1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.kqueue;
17
18 import io.netty.channel.Channel;
19 import io.netty.channel.socket.ServerSocketChannel;
20
21 import java.net.InetSocketAddress;
22 import java.net.SocketAddress;
23
24 import static io.netty.channel.kqueue.BsdSocket.newSocketStream;
25 import static io.netty.channel.unix.NativeInetAddress.address;
26
27 public final class KQueueServerSocketChannel extends AbstractKQueueServerChannel implements ServerSocketChannel {
28 private final KQueueServerSocketChannelConfig config;
29
30 public KQueueServerSocketChannel() {
31 super(newSocketStream(), false);
32 config = new KQueueServerSocketChannelConfig(this);
33 }
34
35 public KQueueServerSocketChannel(int fd) {
36
37
38 this(new BsdSocket(fd));
39 }
40
41 KQueueServerSocketChannel(BsdSocket fd) {
42 super(fd);
43 config = new KQueueServerSocketChannelConfig(this);
44 }
45
46 KQueueServerSocketChannel(BsdSocket fd, boolean active) {
47 super(fd, active);
48 config = new KQueueServerSocketChannelConfig(this);
49 }
50
51 @Override
52 protected void doBind(SocketAddress localAddress) throws Exception {
53 super.doBind(localAddress);
54 socket.listen(config.getBacklog());
55 if (config.isTcpFastOpen()) {
56 socket.setTcpFastOpen(true);
57 }
58 active = true;
59 }
60
61 @Override
62 public InetSocketAddress remoteAddress() {
63 return (InetSocketAddress) super.remoteAddress();
64 }
65
66 @Override
67 public InetSocketAddress localAddress() {
68 return (InetSocketAddress) super.localAddress();
69 }
70
71 @Override
72 public KQueueServerSocketChannelConfig config() {
73 return config;
74 }
75
76 @Override
77 protected Channel newChildChannel(int fd, byte[] address, int offset, int len) throws Exception {
78 return new KQueueSocketChannel(this, new BsdSocket(fd), address(address, offset, len));
79 }
80 }