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 import io.netty.util.internal.PlatformDependent;
20
21 import java.net.InetAddress;
22 import java.net.InetSocketAddress;
23 import java.net.UnknownHostException;
24
25 import static io.netty.channel.unix.Limits.IOV_MAX;
26
27 public final class UnixChannelUtil {
28
29 private UnixChannelUtil() {
30 }
31
32
33
34
35
36 public static boolean isBufferCopyNeededForWrite(ByteBuf byteBuf) {
37 return isBufferCopyNeededForWrite(byteBuf, IOV_MAX);
38 }
39
40 static boolean isBufferCopyNeededForWrite(ByteBuf byteBuf, int iovMax) {
41 return !byteBuf.hasMemoryAddress() && (!byteBuf.isDirect() || byteBuf.nioBufferCount() > iovMax);
42 }
43
44 public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) {
45 if (osRemoteAddr != null) {
46 if (PlatformDependent.javaVersion() >= 7) {
47 try {
48
49
50
51 return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(),
52 osRemoteAddr.getAddress().getAddress()),
53 osRemoteAddr.getPort());
54 } catch (UnknownHostException ignore) {
55
56 }
57 }
58 return osRemoteAddr;
59 }
60 return remoteAddr;
61 }
62 }