Skip to content

Commit 24c231c

Browse files
eddi0815Thomasdezeeuw
authored andcommitted
Add support for the socket option TCP_THIN_LINEAR_TIMEOUTS
1 parent 849eee2 commit 24c231c

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Diff for: src/sys/unix.rs

+54
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,60 @@ impl crate::Socket {
13851385
}
13861386
}
13871387

1388+
/// Get the value of the `TCP_THIN_LINEAR_TIMEOUTS` option on this socket.
1389+
///
1390+
/// For more information about this option, see [`set_thin_linear_timeouts`].
1391+
///
1392+
/// [`set_thin_linear_timeouts`]: Socket::set_thin_linear_timeouts
1393+
#[cfg(all(
1394+
feature = "all",
1395+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1396+
))]
1397+
#[cfg_attr(
1398+
docsrs,
1399+
doc(cfg(all(
1400+
feature = "all",
1401+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1402+
)))
1403+
)]
1404+
pub fn thin_linear_timeouts(&self) -> io::Result<bool> {
1405+
unsafe {
1406+
getsockopt::<Bool>(
1407+
self.as_raw(),
1408+
libc::IPPROTO_TCP,
1409+
libc::TCP_THIN_LINEAR_TIMEOUTS,
1410+
)
1411+
.map(|timeouts| timeouts != 0)
1412+
}
1413+
}
1414+
1415+
/// Set the value of the `TCP_THIN_LINEAR_TIMEOUTS` option on this socket.
1416+
///
1417+
/// If set, the kernel will dynamically detect a thin-stream connection if there are less than four packets in flight.
1418+
/// With less than four packets in flight the normal TCP fast retransmission will not be effective.
1419+
/// The kernel will modify the retransmission to avoid the very high latencies that thin stream suffer because of exponential backoff.
1420+
#[cfg(all(
1421+
feature = "all",
1422+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1423+
))]
1424+
#[cfg_attr(
1425+
docsrs,
1426+
doc(cfg(all(
1427+
feature = "all",
1428+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1429+
)))
1430+
)]
1431+
pub fn set_thin_linear_timeouts(&self, timeouts: bool) -> io::Result<()> {
1432+
unsafe {
1433+
setsockopt(
1434+
self.as_raw(),
1435+
libc::IPPROTO_TCP,
1436+
libc::TCP_THIN_LINEAR_TIMEOUTS,
1437+
timeouts as c_int,
1438+
)
1439+
}
1440+
}
1441+
13881442
/// Gets the value for the `SO_BINDTODEVICE` option on this socket.
13891443
///
13901444
/// This value gets the socket binded device's interface name.

Diff for: tests/socket.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,11 @@ test!(cork, set_cork(true));
11471147
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
11481148
))]
11491149
test!(quickack, set_quickack(false));
1150+
#[cfg(all(
1151+
feature = "all",
1152+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1153+
))]
1154+
test!(thin_linear_timeouts, set_thin_linear_timeouts(true));
11501155
test!(linger, set_linger(Some(Duration::from_secs(10))));
11511156
test!(
11521157
read_timeout,

0 commit comments

Comments
 (0)