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
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 this((SocketProtocolFamily) null);
46 }
47
48
49
50
51 @Deprecated
52 public EpollServerSocketChannel(InternetProtocolFamily protocol) {
53 super(newSocketStream(protocol), false);
54 config = new EpollServerSocketChannelConfig(this);
55 }
56
57 public EpollServerSocketChannel(SocketProtocolFamily protocol) {
58 super(newSocketStream(protocol), false);
59 config = new EpollServerSocketChannelConfig(this);
60 }
61
62 public EpollServerSocketChannel(int fd) {
63
64
65 this(new LinuxSocket(fd));
66 }
67
68 EpollServerSocketChannel(LinuxSocket fd) {
69 super(fd);
70 config = new EpollServerSocketChannelConfig(this);
71 }
72
73 EpollServerSocketChannel(LinuxSocket fd, boolean active) {
74 super(fd, active);
75 config = new EpollServerSocketChannelConfig(this);
76 }
77
78 @Override
79 protected void doBind(SocketAddress localAddress) throws Exception {
80 super.doBind(localAddress);
81 final int tcpFastopen;
82 if (IS_SUPPORTING_TCP_FASTOPEN_SERVER && (tcpFastopen = config.getTcpFastopen()) > 0) {
83 socket.setTcpFastOpen(tcpFastopen);
84 }
85 socket.listen(config.getBacklog());
86 active = true;
87 }
88
89 @Override
90 public InetSocketAddress remoteAddress() {
91 return (InetSocketAddress) super.remoteAddress();
92 }
93
94 @Override
95 public InetSocketAddress localAddress() {
96 return (InetSocketAddress) super.localAddress();
97 }
98
99 @Override
100 public EpollServerSocketChannelConfig config() {
101 return config;
102 }
103
104 @Override
105 protected Channel newChildChannel(int fd, byte[] address, int offset, int len) throws Exception {
106 return new EpollSocketChannel(this, new LinuxSocket(fd), address(address, offset, len));
107 }
108
109 Collection<InetAddress> tcpMd5SigAddresses() {
110 return tcpMd5SigAddresses;
111 }
112
113 void setTcpMd5Sig(Map<InetAddress, byte[]> keys) throws IOException {
114
115 synchronized (this) {
116 tcpMd5SigAddresses = TcpMd5Util.newTcpMd5Sigs(this, tcpMd5SigAddresses, keys);
117 }
118 }
119 }