GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — IoUring: Expose tcp_info · netty/netty@ba76352

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • transport-classes-io_uring/src/main/java/io/netty/channel/uring
    • IoUringSocketChannel.java
  • transport-native-io_uring/src/test/java/io/netty/channel/uring
    • IoUringSocketChannelTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringSocketChannel.java‎

Copy file name to clipboardExpand all lines: transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringSocketChannel.java
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
import io.netty.buffer.ByteBuf;
1919
import io.netty.channel.Channel;
20+
import io.netty.channel.ChannelException;
2021
import io.netty.channel.ChannelOutboundBuffer;
2122
import io.netty.channel.socket.ServerSocketChannel;
2223
import io.netty.channel.socket.SocketChannel;
2324
import io.netty.channel.socket.SocketChannelConfig;
2425
import io.netty.channel.unix.IovArray;
2526

27+
import java.io.IOException;
2628
import java.net.InetSocketAddress;
2729
import java.net.SocketAddress;
2830
import static io.netty.channel.unix.Errors.ioResult;
@@ -45,6 +47,27 @@ public IoUringSocketChannel() {
4547
this.config = new IoUringSocketChannelConfig(this);
4648
}
4749

50+
/**
51+
* Returns the {@code TCP_INFO} for the current socket.
52+
* See <a href="https://linux.die.net//man/7/tcp">man 7 tcp</a>.
53+
*/
54+
public IoUringTcpInfo tcpInfo() {
55+
return tcpInfo(new IoUringTcpInfo());
56+
}
57+
58+
/**
59+
* Updates and returns the {@code TCP_INFO} for the current socket.
60+
* See <a href="https://linux.die.net//man/7/tcp">man 7 tcp</a>.
61+
*/
62+
public IoUringTcpInfo tcpInfo(IoUringTcpInfo info) {
63+
try {
64+
socket.getTcpInfo(info);
65+
return info;
66+
} catch (IOException e) {
67+
throw new ChannelException(e);
68+
}
69+
}
70+
4871
@Override
4972
public ServerSocketChannel parent() {
5073
return (ServerSocketChannel) super.parent();
Collapse file

‎transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringSocketChannelTest.java‎

Copy file name to clipboard
+111Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright 2025 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.channel.uring;
17+
18+
import io.netty.bootstrap.Bootstrap;
19+
import io.netty.channel.ChannelInboundHandlerAdapter;
20+
import io.netty.channel.EventLoopGroup;
21+
import io.netty.channel.MultiThreadIoEventLoopGroup;
22+
import org.junit.jupiter.api.BeforeAll;
23+
import org.junit.jupiter.api.Test;
24+
25+
import java.net.InetSocketAddress;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.junit.jupiter.api.Assertions.assertNotNull;
29+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
30+
31+
public class IoUringSocketChannelTest {
32+
33+
@BeforeAll
34+
public static void loadJNI() {
35+
assumeTrue(IoUring.isAvailable());
36+
}
37+
38+
@Test
39+
public void testTcpInfo() throws Exception {
40+
EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, IoUringIoHandler.newFactory());
41+
42+
try {
43+
Bootstrap bootstrap = new Bootstrap();
44+
IoUringSocketChannel ch = (IoUringSocketChannel) bootstrap.group(group)
45+
.channel(IoUringSocketChannel.class)
46+
.handler(new ChannelInboundHandlerAdapter())
47+
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
48+
IoUringTcpInfo info = ch.tcpInfo();
49+
assertTcpInfo0(info);
50+
ch.close().syncUninterruptibly();
51+
} finally {
52+
group.shutdownGracefully();
53+
}
54+
}
55+
56+
@Test
57+
public void testTcpInfoReuse() throws Exception {
58+
EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, IoUringIoHandler.newFactory());
59+
60+
try {
61+
Bootstrap bootstrap = new Bootstrap();
62+
IoUringSocketChannel ch = (IoUringSocketChannel) bootstrap.group(group)
63+
.channel(IoUringSocketChannel.class)
64+
.handler(new ChannelInboundHandlerAdapter())
65+
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
66+
IoUringTcpInfo info = new IoUringTcpInfo();
67+
ch.tcpInfo(info);
68+
assertTcpInfo0(info);
69+
ch.close().syncUninterruptibly();
70+
} finally {
71+
group.shutdownGracefully();
72+
}
73+
}
74+
75+
private static void assertTcpInfo0(IoUringTcpInfo info) throws Exception {
76+
assertNotNull(info);
77+
78+
assertThat(info.state()).isGreaterThanOrEqualTo(0);
79+
assertThat(info.caState()).isGreaterThanOrEqualTo(0);
80+
assertThat(info.retransmits()).isGreaterThanOrEqualTo(0);
81+
assertThat(info.probes()).isGreaterThanOrEqualTo(0);
82+
assertThat(info.backoff()).isGreaterThanOrEqualTo(0);
83+
assertThat(info.options()).isGreaterThanOrEqualTo(0);
84+
assertThat(info.sndWscale()).isGreaterThanOrEqualTo(0);
85+
assertThat(info.rcvWscale()).isGreaterThanOrEqualTo(0);
86+
assertThat(info.rto()).isGreaterThanOrEqualTo(0);
87+
assertThat(info.ato()).isGreaterThanOrEqualTo(0);
88+
assertThat(info.sndMss()).isGreaterThanOrEqualTo(0);
89+
assertThat(info.rcvMss()).isGreaterThanOrEqualTo(0);
90+
assertThat(info.unacked()).isGreaterThanOrEqualTo(0);
91+
assertThat(info.sacked()).isGreaterThanOrEqualTo(0);
92+
assertThat(info.lost()).isGreaterThanOrEqualTo(0);
93+
assertThat(info.retrans()).isGreaterThanOrEqualTo(0);
94+
assertThat(info.fackets()).isGreaterThanOrEqualTo(0);
95+
assertThat(info.lastDataSent()).isGreaterThanOrEqualTo(0);
96+
assertThat(info.lastAckSent()).isGreaterThanOrEqualTo(0);
97+
assertThat(info.lastDataRecv()).isGreaterThanOrEqualTo(0);
98+
assertThat(info.lastAckRecv()).isGreaterThanOrEqualTo(0);
99+
assertThat(info.pmtu()).isGreaterThanOrEqualTo(0);
100+
assertThat(info.rcvSsthresh()).isGreaterThanOrEqualTo(0);
101+
assertThat(info.rtt()).isGreaterThanOrEqualTo(0);
102+
assertThat(info.rttvar()).isGreaterThanOrEqualTo(0);
103+
assertThat(info.sndSsthresh()).isGreaterThanOrEqualTo(0);
104+
assertThat(info.sndCwnd()).isGreaterThanOrEqualTo(0);
105+
assertThat(info.advmss()).isGreaterThanOrEqualTo(0);
106+
assertThat(info.reordering()).isGreaterThanOrEqualTo(0);
107+
assertThat(info.rcvRtt()).isGreaterThanOrEqualTo(0);
108+
assertThat(info.rcvSpace()).isGreaterThanOrEqualTo(0);
109+
assertThat(info.totalRetrans()).isGreaterThanOrEqualTo(0);
110+
}
111+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.