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.channel.Channel;
19 import io.netty.channel.EventLoop;
20 import io.netty.channel.socket.ServerSocketChannel;
21 import io.netty.channel.unix.FileDescriptor;
22 import io.netty.channel.unix.Socket;
23
24 import java.io.IOException;
25 import java.net.InetAddress;
26 import java.net.InetSocketAddress;
27 import java.net.SocketAddress;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.Map;
31
32 import static io.netty.channel.unix.NativeInetAddress.address;
33 import static io.netty.channel.unix.Socket.newSocketStream;
34
35
36
37
38
39 public final class EpollServerSocketChannel extends AbstractEpollServerChannel implements ServerSocketChannel {
40
41 private final EpollServerSocketChannelConfig config;
42 private volatile Collection<InetAddress> tcpMd5SigAddresses = Collections.emptyList();
43
44 public EpollServerSocketChannel() {
45 super(newSocketStream(), false);
46 config = new EpollServerSocketChannelConfig(this);
47 }
48
49
50
51
52
53 @Deprecated
54 public EpollServerSocketChannel(FileDescriptor fd) {
55
56
57 this(new Socket(fd.intValue()));
58 }
59
60
61
62
63
64 @Deprecated
65 public EpollServerSocketChannel(Socket fd) {
66 super(fd);
67 config = new EpollServerSocketChannelConfig(this);
68 }
69
70 public EpollServerSocketChannel(Socket fd, boolean active) {
71 super(fd, active);
72 config = new EpollServerSocketChannelConfig(this);
73 }
74
75 @Override
76 protected boolean isCompatible(EventLoop loop) {
77 return loop instanceof EpollEventLoop;
78 }
79
80 @Override
81 protected void doBind(SocketAddress localAddress) throws Exception {
82 super.doBind(localAddress);
83 if (Native.IS_SUPPORTING_TCP_FASTOPEN && config.getTcpFastopen() > 0) {
84 Native.setTcpFastopen(fd().intValue(), config.getTcpFastopen());
85 }
86 fd().listen(config.getBacklog());
87 active = true;
88 }
89
90 @Override
91 public InetSocketAddress remoteAddress() {
92 return (InetSocketAddress) super.remoteAddress();
93 }
94
95 @Override
96 public InetSocketAddress localAddress() {
97 return (InetSocketAddress) super.localAddress();
98 }
99
100 @Override
101 public EpollServerSocketChannelConfig config() {
102 return config;
103 }
104
105 @Override
106 protected Channel newChildChannel(int fd, byte[] address, int offset, int len) throws Exception {
107 return new EpollSocketChannel(this, new Socket(fd), address(address, offset, len));
108 }
109
110 Collection<InetAddress> tcpMd5SigAddresses() {
111 return tcpMd5SigAddresses;
112 }
113
114 void setTcpMd5Sig(Map<InetAddress, byte[]> keys) throws IOException {
115 tcpMd5SigAddresses = TcpMd5Util.newTcpMd5Sigs(this, tcpMd5SigAddresses, keys);
116 }
117 }