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.ChannelOption;
20 import io.netty.channel.socket.ServerSocketChannel;
21 import io.netty.channel.socket.ServerSocketChannelConfig;
22
23 import java.net.InetSocketAddress;
24 import java.net.SocketAddress;
25
26 public final class IoUringServerSocketChannel extends AbstractIoUringServerChannel implements ServerSocketChannel {
27 private final IoUringServerSocketChannelConfig config;
28
29 public IoUringServerSocketChannel() {
30
31
32
33
34
35
36
37
38 super(LinuxSocket.newSocketStream(), false);
39 this.config = new IoUringServerSocketChannelConfig(this);
40 }
41
42 @Override
43 public ServerSocketChannelConfig config() {
44 return config;
45 }
46
47 @Override
48 Channel newChildChannel(int fd, long acceptedAddressMemoryAddress, long acceptedAddressLengthMemoryAddress) {
49 final InetSocketAddress address;
50 IoUringIoHandler handler = (IoUringIoHandler) registration().ioHandler();
51 if (socket.isIpv6()) {
52 byte[] ipv6Array = handler.inet6AddressArray();
53 byte[] ipv4Array = handler.inet4AddressArray();
54 address = SockaddrIn.readIPv6(acceptedAddressMemoryAddress, ipv6Array, ipv4Array);
55 } else {
56 byte[] addressArray = handler.inet4AddressArray();
57 address = SockaddrIn.readIPv4(acceptedAddressMemoryAddress, addressArray);
58 }
59 return new IoUringSocketChannel(this, new LinuxSocket(fd), address);
60 }
61
62 @Override
63 public InetSocketAddress remoteAddress() {
64 return (InetSocketAddress) super.remoteAddress();
65 }
66
67 @Override
68 public InetSocketAddress localAddress() {
69 return (InetSocketAddress) super.localAddress();
70 }
71
72 @Override
73 public void doBind(SocketAddress localAddress) throws Exception {
74 super.doBind(localAddress);
75 if (IoUring.isTcpFastOpenServerSideAvailable()) {
76 Integer fastOpen = config().getOption(ChannelOption.TCP_FASTOPEN);
77 if (fastOpen != null && fastOpen > 0) {
78 socket.setTcpFastOpen(fastOpen);
79 }
80 }
81 socket.listen(config.getBacklog());
82 active = true;
83 }
84 }