diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 88850a19..2e084980 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -1334,6 +1334,57 @@ impl crate::Socket { } } + /// Get the value of the `TCP_QUICKACK` option on this socket. + /// + /// For more information about this option, see [`set_quickack`]. + /// + /// [`set_quickack`]: Socket::set_quickack + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))] + #[cfg_attr( + docsrs, + doc(cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))) + )] + pub fn quickack(&self) -> io::Result { + unsafe { + getsockopt::(self.as_raw(), libc::IPPROTO_TCP, libc::TCP_QUICKACK) + .map(|quickack| quickack != 0) + } + } + + /// Set the value of the `TCP_QUICKACK` option on this socket. + /// + /// If set, acks are sent immediately, rather than delayed if needed in accordance to normal + /// TCP operation. This flag is not permanent, it only enables a switch to or from quickack mode. + /// Subsequent operation of the TCP protocol will once again enter/leave quickack mode depending on + /// internal protocol processing and factors such as delayed ack timeouts occurring and data transfer. + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))] + #[cfg_attr( + docsrs, + doc(cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))) + )] + pub fn set_quickack(&self, quickack: bool) -> io::Result<()> { + unsafe { + setsockopt( + self.as_raw(), + libc::IPPROTO_TCP, + libc::TCP_QUICKACK, + quickack as c_int, + ) + } + } + /// Gets the value for the `SO_BINDTODEVICE` option on this socket. /// /// This value gets the socket binded device's interface name. diff --git a/tests/socket.rs b/tests/socket.rs index b06db883..4d8838c0 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -1142,6 +1142,11 @@ test!( any(target_os = "android", target_os = "fuchsia", target_os = "linux") ))] test!(cork, set_cork(true)); +#[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") +))] +test!(quickack, set_quickack(false)); test!(linger, set_linger(Some(Duration::from_secs(10)))); test!( read_timeout,