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.socket.InternetProtocolFamily;
20 import io.netty.channel.socket.ServerSocketChannel;
21 import io.netty.channel.socket.SocketProtocolFamily;
22
23 import java.io.IOException;
24 import java.net.InetAddress;
25 import java.net.InetSocketAddress;
26 import java.net.SocketAddress;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.Map;
30
31 import static io.netty.channel.epoll.LinuxSocket.newSocketStream;
32 import static io.netty.channel.epoll.Native.IS_SUPPORTING_TCP_FASTOPEN_SERVER;
33 import static io.netty.channel.unix.NativeInetAddress.address;
34
35
36
37
38 public final class EpollServerSocketChannel extends AbstractEpollServerChannel implements ServerSocketChannel {
39
40 private final EpollServerSocketChannelConfig config;
41 private volatile Collection<InetAddress> tcpMd5SigAddresses = Collections.emptyList();
42
43 public EpollServerSocketChannel() {
44 this((SocketProtocolFamily) null);
45 }
46
47
48
49
50 @Deprecated
51 public EpollServerSocketChannel(InternetProtocolFamily protocol) {
52 super(newSocketStream(protocol), false);
53 config = new EpollServerSocketChannelConfig(this);
54 }
55
56 public EpollServerSocketChannel(SocketProtocolFamily protocol) {
57 super(newSocketStream(protocol), false);
58 config = new EpollServerSocketChannelConfig(this);
59 }
60
61 public EpollServerSocketChannel(int fd) {
62
63
64 this(new LinuxSocket(fd));
65 }
66
67 EpollServerSocketChannel(LinuxSocket fd) {
68 super(fd);
69 config = new EpollServerSocketChannelConfig(this);
70 }
71
72 EpollServerSocketChannel(LinuxSocket fd, boolean active) {
73 super(fd, active);
74 config = new EpollServerSocketChannelConfig(this);
75 }
76
77 @Override
78 protected void doBind(SocketAddress localAddress) throws Exception {
79 super.doBind(localAddress);
80 final int tcpFastopen;
81 if (IS_SUPPORTING_TCP_FASTOPEN_SERVER && (tcpFastopen = config.getTcpFastopen()) > 0) {
82 socket.setTcpFastOpen(tcpFastopen);
83 }
84 socket.listen(config.getBacklog());
85 active = true;
86
87 submitCurrentOps();
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 LinuxSocket(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
116 synchronized (this) {
117 tcpMd5SigAddresses = TcpMd5Util.newTcpMd5Sigs(this, tcpMd5SigAddresses, keys);
118 }
119 }
120 }