Skip to content

Commit

Permalink
Allow getting TCP info till tcpi_segs_in #14022
Browse files Browse the repository at this point in the history
Minimum Linux requirement: v4.2 released on 30 August 2015

torvalds/linux@2efd055
  • Loading branch information
dries-c committed May 3, 2024
1 parent 7ed972d commit c2e2589
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@
* __u32 tcpi_rcv_space;
*
* __u32 tcpi_total_retrans;
*
* __u64 tcpi_pacing_rate;
* __u64 tcpi_max_pacing_rate;
* __u64 tcpi_bytes_acked;
* __u64 tcpi_bytes_received;
* __u32 tcpi_segs_out;
* __u32 tcpi_segs_in;
* };
* </p>
*/
public final class EpollTcpInfo {

final long[] info = new long[32];
final long[] info = new long[38];

public int state() {
return (int) info[0];
Expand Down Expand Up @@ -190,4 +197,28 @@ public long rcvSpace() {
public long totalRetrans() {
return info[31];
}

/**
* Returns an unsigned long
*/
public long pacingRate() { return info[31]; }

/**
* Returns an unsigned long
*/
public long maxPacingRate() { return info[32]; }

/**
* Returns an unsigned long
*/
public long bytesAcked() { return info[33]; }

/**
* Returns an unsigned long
*/
public long bytesReceived() { return info[34]; }

public long segsOut() { return info[35]; }

public long segsIn() { return info[36]; }
}
12 changes: 9 additions & 3 deletions transport-native-epoll/src/main/c/netty_epoll_linuxsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ static void netty_epoll_linuxsocket_getTcpInfo(JNIEnv* env, jclass clazz, jint f
if (netty_unix_socket_getOption(env, fd, IPPROTO_TCP, TCP_INFO, &tcp_info, sizeof(tcp_info)) == -1) {
return;
}
jlong cArray[32];
jlong cArray[38];
// Expand to 64 bits, then cast away unsigned-ness.
cArray[0] = (jlong) (uint64_t) tcp_info.tcpi_state;
cArray[1] = (jlong) (uint64_t) tcp_info.tcpi_ca_state;
Expand Down Expand Up @@ -647,8 +647,14 @@ static void netty_epoll_linuxsocket_getTcpInfo(JNIEnv* env, jclass clazz, jint f
cArray[29] = (jlong) (uint64_t) tcp_info.tcpi_rcv_rtt;
cArray[30] = (jlong) (uint64_t) tcp_info.tcpi_rcv_space;
cArray[31] = (jlong) (uint64_t) tcp_info.tcpi_total_retrans;

(*env)->SetLongArrayRegion(env, array, 0, 32, cArray);
cArray[32] = (jlong) (uint64_t) tcp_info.tcpi_pacing_rate;
cArray[33] = (jlong) (uint64_t) tcp_info.tcpi_max_pacing_rate;
cArray[34] = (jlong) (uint64_t) tcp_info.tcpi_bytes_acked;
cArray[35] = (jlong) (uint64_t) tcp_info.tcpi_bytes_received;
cArray[36] = (jlong) (uint64_t) tcp_info.tcpi_segs_out;
cArray[37] = (jlong) (uint64_t) tcp_info.tcpi_segs_in;

(*env)->SetLongArrayRegion(env, array, 0, 38, cArray);
}

static jint netty_epoll_linuxsocket_isTcpCork(JNIEnv* env, jclass clazz, jint fd) {
Expand Down

0 comments on commit c2e2589

Please sign in to comment.