forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#96324 - berendjan:set_tcp_quickack, r=dtolnay
Add setter and getter for TCP_QUICKACK on TcpStream for Linux Reference issue rust-lang#96256 Setting TCP_QUICKACK on TcpStream for Linux
- Loading branch information
Showing
11 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
#![stable(feature = "raw_ext", since = "1.1.0")] | ||
|
||
pub mod fs; | ||
pub mod net; | ||
pub mod raw; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//! Linux and Android-specific definitions for socket options. | ||
#![unstable(feature = "tcp_quickack", issue = "96256")] | ||
pub use crate::os::net::tcp::TcpStreamExt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
#![doc(cfg(target_os = "linux"))] | ||
|
||
pub mod fs; | ||
pub mod net; | ||
pub mod process; | ||
pub mod raw; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//! Linux and Android-specific definitions for socket options. | ||
#![unstable(feature = "tcp_quickack", issue = "96256")] | ||
pub use crate::os::net::tcp::TcpStreamExt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! Linux and Android-specific definitions for socket options. | ||
#![unstable(feature = "tcp_quickack", issue = "96256")] | ||
#![doc(cfg(any(target_os = "linux", target_os = "android",)))] | ||
pub mod tcp; | ||
#[cfg(test)] | ||
mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//! Linux and Android-specific tcp extensions to primitives in the [`std::net`] module. | ||
//! | ||
//! [`std::net`]: crate::net | ||
use crate::io; | ||
use crate::net; | ||
use crate::sealed::Sealed; | ||
use crate::sys_common::AsInner; | ||
|
||
/// Os-specific extensions for [`TcpStream`] | ||
/// | ||
/// [`TcpStream`]: net::TcpStream | ||
#[unstable(feature = "tcp_quickack", issue = "96256")] | ||
pub trait TcpStreamExt: Sealed { | ||
/// Enable or disable `TCP_QUICKACK`. | ||
/// | ||
/// This flag causes Linux to eagerly send ACKs rather than delaying them. | ||
/// Linux may reset this flag after further operations on the socket. | ||
/// | ||
/// See [`man 7 tcp`](https://man7.org/linux/man-pages/man7/tcp.7.html) and | ||
/// [TCP delayed acknowledgement](https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment) | ||
/// for more information. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// #![feature(tcp_quickack)] | ||
/// use std::net::TcpStream; | ||
/// use std::os::linux::net::TcpStreamExt; | ||
/// | ||
/// let stream = TcpStream::connect("127.0.0.1:8080") | ||
/// .expect("Couldn't connect to the server..."); | ||
/// stream.set_quickack(true).expect("set_quickack call failed"); | ||
/// ``` | ||
#[unstable(feature = "tcp_quickack", issue = "96256")] | ||
fn set_quickack(&self, quickack: bool) -> io::Result<()>; | ||
|
||
/// Gets the value of the `TCP_QUICKACK` option on this socket. | ||
/// | ||
/// For more information about this option, see [`TcpStreamExt::set_quickack`]. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// #![feature(tcp_quickack)] | ||
/// use std::net::TcpStream; | ||
/// use std::os::linux::net::TcpStreamExt; | ||
/// | ||
/// let stream = TcpStream::connect("127.0.0.1:8080") | ||
/// .expect("Couldn't connect to the server..."); | ||
/// stream.set_quickack(true).expect("set_quickack call failed"); | ||
/// assert_eq!(stream.quickack().unwrap_or(false), true); | ||
/// ``` | ||
#[unstable(feature = "tcp_quickack", issue = "96256")] | ||
fn quickack(&self) -> io::Result<bool>; | ||
} | ||
|
||
#[unstable(feature = "tcp_quickack", issue = "96256")] | ||
impl Sealed for net::TcpStream {} | ||
|
||
#[unstable(feature = "tcp_quickack", issue = "96256")] | ||
impl TcpStreamExt for net::TcpStream { | ||
fn set_quickack(&self, quickack: bool) -> io::Result<()> { | ||
self.as_inner().as_inner().set_quickack(quickack) | ||
} | ||
|
||
fn quickack(&self) -> io::Result<bool> { | ||
self.as_inner().as_inner().quickack() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#[cfg(any(target_os = "android", target_os = "linux",))] | ||
#[test] | ||
fn quickack() { | ||
use crate::{ | ||
net::{test::next_test_ip4, TcpListener, TcpStream}, | ||
os::net::tcp::TcpStreamExt, | ||
}; | ||
|
||
macro_rules! t { | ||
($e:expr) => { | ||
match $e { | ||
Ok(t) => t, | ||
Err(e) => panic!("received error for `{}`: {}", stringify!($e), e), | ||
} | ||
}; | ||
} | ||
|
||
let addr = next_test_ip4(); | ||
let _listener = t!(TcpListener::bind(&addr)); | ||
|
||
let stream = t!(TcpStream::connect(&("localhost", addr.port()))); | ||
|
||
t!(stream.set_quickack(false)); | ||
assert_eq!(false, t!(stream.quickack())); | ||
t!(stream.set_quickack(true)); | ||
assert_eq!(true, t!(stream.quickack())); | ||
t!(stream.set_quickack(false)); | ||
assert_eq!(false, t!(stream.quickack())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters