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.util.internal.logging.InternalLogger;
25 import io.netty.util.internal.logging.InternalLoggerFactory;
26
27 import java.io.File;
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 File socketFile = new File(local.path());
50 boolean success = socketFile.delete();
51 if (!success && logger.isDebugEnabled()) {
52 logger.debug("Failed to delete a domain socket file: {}", local.path());
53 }
54 }
55 }
56 });
57 }
58
59 @Override
60 Channel newChildChannel(int fd, ByteBuffer acceptedAddressMemory) throws Exception {
61 return new IoUringDomainSocketChannel(this, new LinuxSocket(fd));
62 }
63
64 @Override
65 public ChannelConfig config() {
66 return config;
67 }
68
69 @Override
70 public DomainSocketAddress localAddress() {
71 return local;
72 }
73
74 @Override
75 public DomainSocketAddress remoteAddress() {
76 return (DomainSocketAddress) super.remoteAddress();
77 }
78
79 @Override
80 protected void doBind(SocketAddress localAddress) throws Exception {
81 socket.bind(localAddress);
82 socket.listen(config.getBacklog());
83 local = (DomainSocketAddress) localAddress;
84 active = true;
85 }
86
87 }