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.EventLoop;
20 import io.netty.channel.socket.ServerSocketChannel;
21
22 import java.net.InetSocketAddress;
23 import java.net.SocketAddress;
24
25 import static io.netty.channel.kqueue.BsdSocket.newSocketStream;
26 import static io.netty.channel.unix.NativeInetAddress.address;
27
28 public final class KQueueServerSocketChannel extends AbstractKQueueServerChannel implements ServerSocketChannel {
29 private final KQueueServerSocketChannelConfig config;
30
31 public KQueueServerSocketChannel() {
32 super(newSocketStream(), false);
33 config = new KQueueServerSocketChannelConfig(this);
34 }
35
36 public KQueueServerSocketChannel(int fd) {
37
38
39 this(new BsdSocket(fd));
40 }
41
42 KQueueServerSocketChannel(BsdSocket fd) {
43 super(fd);
44 config = new KQueueServerSocketChannelConfig(this);
45 }
46
47 KQueueServerSocketChannel(BsdSocket fd, boolean active) {
48 super(fd, active);
49 config = new KQueueServerSocketChannelConfig(this);
50 }
51
52 @Override
53 protected boolean isCompatible(EventLoop loop) {
54 return loop instanceof KQueueEventLoop;
55 }
56
57 @Override
58 protected void doBind(SocketAddress localAddress) throws Exception {
59 super.doBind(localAddress);
60 socket.listen(config.getBacklog());
61 if (config.isTcpFastOpen()) {
62 socket.setTcpFastOpen(true);
63 }
64 active = true;
65 }
66
67 @Override
68 public InetSocketAddress remoteAddress() {
69 return (InetSocketAddress) super.remoteAddress();
70 }
71
72 @Override
73 public InetSocketAddress localAddress() {
74 return (InetSocketAddress) super.localAddress();
75 }
76
77 @Override
78 public KQueueServerSocketChannelConfig config() {
79 return config;
80 }
81
82 @Override
83 protected Channel newChildChannel(int fd, byte[] address, int offset, int len) throws Exception {
84 return new KQueueSocketChannel(this, new BsdSocket(fd), address(address, offset, len));
85 }
86 }