1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.uring;
17
18 import io.netty.channel.Channel;
19 import io.netty.channel.ChannelConfig;
20 import io.netty.channel.ChannelFuture;
21 import io.netty.channel.ChannelFutureListener;
22 import io.netty.channel.unix.DomainSocketAddress;
23 import io.netty.channel.unix.ServerDomainSocketChannel;
24 import io.netty.channel.unix.UnixChannelUtil;
25 import io.netty.util.internal.logging.InternalLogger;
26 import io.netty.util.internal.logging.InternalLoggerFactory;
27
28 import java.net.SocketAddress;
29 import java.nio.ByteBuffer;
30
31 public final class IoUringServerDomainSocketChannel extends AbstractIoUringServerChannel
32 implements ServerDomainSocketChannel {
33
34 private static final InternalLogger logger = InternalLoggerFactory.getInstance(
35 IoUringServerDomainSocketChannel.class);
36
37 private final IoUringServerSocketChannelConfig config;
38
39 private volatile DomainSocketAddress local;
40
41 public IoUringServerDomainSocketChannel() {
42 super(LinuxSocket.newSocketDomain(), false);
43 this.config = new IoUringServerSocketChannelConfig(this);
44 this.closeFuture().addListener(new ChannelFutureListener() {
45 @Override
46 public void operationComplete(ChannelFuture future) throws Exception {
47 if (local != null) {
48
49 boolean success = UnixChannelUtil.deleteDomainSocketFile(local.path());
50 if (!success && logger.isDebugEnabled()) {
51 logger.debug("Failed to delete a domain socket file: {}", local.path());
52 }
53 }
54 }
55 });
56 }
57
58 @Override
59 Channel newChildChannel(int fd, ByteBuffer acceptedAddressMemory) throws Exception {
60 return new IoUringDomainSocketChannel(this, new LinuxSocket(fd));
61 }
62
63 @Override
64 public ChannelConfig config() {
65 return config;
66 }
67
68 @Override
69 public DomainSocketAddress localAddress() {
70 return local;
71 }
72
73 @Override
74 public DomainSocketAddress remoteAddress() {
75 return (DomainSocketAddress) super.remoteAddress();
76 }
77
78 @Override
79 protected void doBind(SocketAddress localAddress) throws Exception {
80 socket.bind(localAddress);
81 socket.listen(config.getBacklog());
82 local = (DomainSocketAddress) localAddress;
83 active = true;
84 }
85
86 }