Skip to content

Commit daaa9af

Browse files
committed
feat: Get tcp_info structure
Implement TCP_INFO option for getsockopt.
1 parent e4895d3 commit daaa9af

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/sys/socket/sockopt.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,17 @@ sockopt_impl!(
12681268
libc::SO_EXCLBIND,
12691269
bool
12701270
);
1271+
#[cfg(target_os = "linux")]
1272+
#[cfg(feature = "net")]
1273+
sockopt_impl!(
1274+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
1275+
/// Get tcp_info structure.
1276+
TcpInfo,
1277+
GetOnly,
1278+
libc::SOL_TCP,
1279+
libc::TCP_INFO,
1280+
libc::tcp_info
1281+
);
12711282

12721283
#[allow(missing_docs)]
12731284
// Not documented by Linux!

test/sys/test_sockopt.rs

+17
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,23 @@ fn test_ipv6_tclass() {
568568
assert_eq!(getsockopt(&fd, sockopt::Ipv6TClass).unwrap(), class);
569569
}
570570

571+
#[test]
572+
#[cfg(target_os = "linux")]
573+
fn test_tcp_info() {
574+
let fd = socket(
575+
AddressFamily::Inet6,
576+
SockType::Stream,
577+
SockFlag::empty(),
578+
SockProtocol::Tcp,
579+
)
580+
.unwrap();
581+
let tcp_info = getsockopt(&fd, sockopt::TcpInfo).unwrap();
582+
// Silly assert for the sake of having one in the test.
583+
// There should be no retransmits because nothing is sent through the
584+
// socket in the first place.
585+
assert_eq!(tcp_info.tcpi_retransmits, 0);
586+
}
587+
571588
#[test]
572589
#[cfg(target_os = "freebsd")]
573590
fn test_receive_timestamp() {

0 commit comments

Comments
 (0)