1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.epoll;
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 public final class UnixChannelUtil {
26
27 private UnixChannelUtil() {
28 }
29
30
31
32
33
34 public static boolean isBufferCopyNeededForWrite(ByteBuf byteBuf) {
35 return isBufferCopyNeededForWrite(byteBuf, Native.IOV_MAX);
36 }
37
38 static boolean isBufferCopyNeededForWrite(ByteBuf byteBuf, int iovMax) {
39 return !byteBuf.hasMemoryAddress() && (!byteBuf.isDirect() || byteBuf.nioBufferCount() > iovMax);
40 }
41
42 public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) {
43 if (osRemoteAddr != null) {
44 if (PlatformDependent.javaVersion() >= 7) {
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 }
56 return osRemoteAddr;
57 }
58 return remoteAddr;
59 }
60 }