1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.channel.unix;
17
18 import io.netty5.buffer.api.Buffer;
19
20 import java.net.InetAddress;
21 import java.net.InetSocketAddress;
22 import java.net.UnknownHostException;
23
24 import static io.netty5.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(Buffer buffer) {
36 return isBufferCopyNeededForWrite(buffer, IOV_MAX);
37 }
38
39 static boolean isBufferCopyNeededForWrite(Buffer buffer, int iovMax) {
40 return !buffer.isDirect() || buffer.countReadableComponents() > 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 }