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