1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.unix;
17
18 import io.netty.buffer.ByteBuf;
19
20 import java.net.InetAddress;
21 import java.net.InetSocketAddress;
22 import java.net.UnknownHostException;
23
24 import static io.netty.channel.unix.Limits.IOV_MAX;
25
26 public final class UnixChannelUtil {
27
28 private UnixChannelUtil() {
29 }
30
31
32
33
34
35 public static boolean isBufferCopyNeededForWrite(ByteBuf byteBuf) {
36 return isBufferCopyNeededForWrite(byteBuf, IOV_MAX);
37 }
38
39 static boolean isBufferCopyNeededForWrite(ByteBuf byteBuf, int iovMax) {
40 return !byteBuf.hasMemoryAddress() && (!byteBuf.isDirect() || byteBuf.nioBufferCount() > iovMax);
41 }
42
43 public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) {
44 if (osRemoteAddr != null) {
45 try {
46
47
48
49 return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(),
50 osRemoteAddr.getAddress().getAddress()),
51 osRemoteAddr.getPort());
52 } catch (UnknownHostException ignore) {
53
54 }
55 return osRemoteAddr;
56 }
57 return remoteAddr;
58 }
59 }