expression

Configure TCP_NODELAY

Disable Nagle’s algorithm when a protocol requires that policy. It is not a guarantee of low latency or immediate remote receipt. Measure throughput and latency before selecting a production setting. Tokio is an external crate. Authorized isolated IPv4 loopback fixture; no public network or DNS. Expected stdout (not executed): true Common mistake: Treating the option as an acknowledgement from the peer.

Formal Syntax & Structure

rust syntaxrust
stream.set_nodelay(true); stream.nodelay()

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    tokio::time::timeout(std::time::Duration::from_secs(3), async {        use tokio::net::{TcpListener, TcpStream};        let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();        let addr = listener.local_addr().unwrap();        let (client, accepted) = tokio::join!(TcpStream::connect(addr), listener.accept());        let mut client = client.unwrap();        let (mut server, _) = accepted.unwrap();        client.set_nodelay(true).unwrap();        println!("{}", client.nodelay().unwrap());    }).await.expect("fixture deadline");}
Rust Reference