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 IoUringIoHandler handler = registration().attachment();
50 LinuxSocket socket = new LinuxSocket(fd);
51 if (acceptedAddressMemoryAddress != 0 && acceptedAddressLengthMemoryAddress != 0) {
52
53 final InetSocketAddress address;
54 if (socket.isIpv6()) {
55 byte[] ipv6Array = handler.inet6AddressArray();
56 byte[] ipv4Array = handler.inet4AddressArray();
57 address = SockaddrIn.readIPv6(acceptedAddressMemoryAddress, ipv6Array, ipv4Array);
58 } else {
59 byte[] addressArray = handler.inet4AddressArray();
60 address = SockaddrIn.readIPv4(acceptedAddressMemoryAddress, addressArray);
61 }
62 return new IoUringSocketChannel(this, new LinuxSocket(fd), address);
63 }
64 return new IoUringSocketChannel(this, new LinuxSocket(fd));
65 }
66
67 @Override
68 public InetSocketAddress remoteAddress() {
69 return (InetSocketAddress) super.remoteAddress();
70 }
71
72 @Override
73 public InetSocketAddress localAddress() {
74 return (InetSocketAddress) super.localAddress();
75 }
76
77 @Override
78 public void doBind(SocketAddress localAddress) throws Exception {
79 super.doBind(localAddress);
80 if (IoUring.isTcpFastOpenServerSideAvailable()) {
81 Integer fastOpen = config().getOption(ChannelOption.TCP_FASTOPEN);
82 if (fastOpen != null && fastOpen > 0) {
83 socket.setTcpFastOpen(fastOpen);
84 }
85 }
86 socket.listen(config.getBacklog());
87 active = true;
88 }
89 }