Skip to content

Commit 849eee2

Browse files
eddi0815Thomasdezeeuw
authored andcommitted
Add support for the socket option TCP_QUICKACK
1 parent 50f31f1 commit 849eee2

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/sys/unix.rs

+51
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,57 @@ impl crate::Socket {
13341334
}
13351335
}
13361336

1337+
/// Get the value of the `TCP_QUICKACK` option on this socket.
1338+
///
1339+
/// For more information about this option, see [`set_quickack`].
1340+
///
1341+
/// [`set_quickack`]: Socket::set_quickack
1342+
#[cfg(all(
1343+
feature = "all",
1344+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1345+
))]
1346+
#[cfg_attr(
1347+
docsrs,
1348+
doc(cfg(all(
1349+
feature = "all",
1350+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1351+
)))
1352+
)]
1353+
pub fn quickack(&self) -> io::Result<bool> {
1354+
unsafe {
1355+
getsockopt::<Bool>(self.as_raw(), libc::IPPROTO_TCP, libc::TCP_QUICKACK)
1356+
.map(|quickack| quickack != 0)
1357+
}
1358+
}
1359+
1360+
/// Set the value of the `TCP_QUICKACK` option on this socket.
1361+
///
1362+
/// If set, acks are sent immediately, rather than delayed if needed in accordance to normal
1363+
/// TCP operation. This flag is not permanent, it only enables a switch to or from quickack mode.
1364+
/// Subsequent operation of the TCP protocol will once again enter/leave quickack mode depending on
1365+
/// internal protocol processing and factors such as delayed ack timeouts occurring and data transfer.
1366+
#[cfg(all(
1367+
feature = "all",
1368+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1369+
))]
1370+
#[cfg_attr(
1371+
docsrs,
1372+
doc(cfg(all(
1373+
feature = "all",
1374+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1375+
)))
1376+
)]
1377+
pub fn set_quickack(&self, quickack: bool) -> io::Result<()> {
1378+
unsafe {
1379+
setsockopt(
1380+
self.as_raw(),
1381+
libc::IPPROTO_TCP,
1382+
libc::TCP_QUICKACK,
1383+
quickack as c_int,
1384+
)
1385+
}
1386+
}
1387+
13371388
/// Gets the value for the `SO_BINDTODEVICE` option on this socket.
13381389
///
13391390
/// This value gets the socket binded device's interface name.

tests/socket.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,11 @@ test!(
11421142
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
11431143
))]
11441144
test!(cork, set_cork(true));
1145+
#[cfg(all(
1146+
feature = "all",
1147+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1148+
))]
1149+
test!(quickack, set_quickack(false));
11451150
test!(linger, set_linger(Some(Duration::from_secs(10))));
11461151
test!(
11471152
read_timeout,

0 commit comments

Comments
 (0)