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