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.unix.DomainSocketAddress;
20 import io.netty.channel.unix.ServerDomainSocketChannel;
21 import io.netty.channel.unix.UnixChannelUtil;
22 import io.netty.util.internal.logging.InternalLogger;
23 import io.netty.util.internal.logging.InternalLoggerFactory;
24
25 import java.net.SocketAddress;
26
27 import static io.netty.channel.kqueue.BsdSocket.newSocketDomain;
28
29 public final class KQueueServerDomainSocketChannel extends AbstractKQueueServerChannel
30 implements ServerDomainSocketChannel {
31 private static final InternalLogger logger = InternalLoggerFactory.getInstance(
32 KQueueServerDomainSocketChannel.class);
33
34 private final KQueueServerChannelConfig config = new KQueueServerChannelConfig(this);
35 private volatile DomainSocketAddress local;
36
37 public KQueueServerDomainSocketChannel() {
38 super(newSocketDomain(), false);
39 }
40
41 public KQueueServerDomainSocketChannel(int fd) {
42 this(new BsdSocket(fd), false);
43 }
44
45 KQueueServerDomainSocketChannel(BsdSocket socket, boolean active) {
46 super(socket, active);
47 }
48
49 @Override
50 protected Channel newChildChannel(int fd, byte[] addr, int offset, int len) throws Exception {
51 return new KQueueDomainSocketChannel(this, new BsdSocket(fd));
52 }
53
54 @Override
55 protected DomainSocketAddress localAddress0() {
56 return local;
57 }
58
59 @Override
60 protected void doBind(SocketAddress localAddress) throws Exception {
61 socket.bind(localAddress);
62 socket.listen(config.getBacklog());
63 local = (DomainSocketAddress) localAddress;
64 active = true;
65 }
66
67 @Override
68 protected void doClose() throws Exception {
69 try {
70 super.doClose();
71 } finally {
72 DomainSocketAddress local = this.local;
73 if (local != null) {
74
75 boolean success = UnixChannelUtil.deleteDomainSocketFile(local.path());
76 if (!success && logger.isDebugEnabled()) {
77 logger.debug("Failed to delete a domain socket file: {}", local.path());
78 }
79 }
80 }
81 }
82
83 @Override
84 public KQueueServerChannelConfig config() {
85 return config;
86 }
87
88 @Override
89 public DomainSocketAddress remoteAddress() {
90 return (DomainSocketAddress) super.remoteAddress();
91 }
92
93 @Override
94 public DomainSocketAddress localAddress() {
95 return (DomainSocketAddress) super.localAddress();
96 }
97 }