W3cubDocs

/Rust

Trait TcpStreamExt

pub trait TcpStreamExt: Sealed {
    // Required methods
    fn set_quickack(&self, quickack: bool) -> Result<()>;
    fn quickack(&self) -> Result<bool>;
    fn set_deferaccept(&self, accept: Duration) -> Result<()>;
    fn deferaccept(&self) -> Result<Duration>;
}
Available on Linux only.

Os-specific extensions for TcpStream

Required Methods

1.89.0Source
fn set_quickack(&self, quickack: bool) -> Result<()>

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 and TCP delayed acknowledgement for more information.

Examples
use std::net::TcpStream;
#[cfg(target_os = "linux")]
use std::os::linux::net::TcpStreamExt;
#[cfg(target_os = "android")]
use std::os::android::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");
1.89.0Source
fn quickack(&self) -> Result<bool>

Gets the value of the TCP_QUICKACK option on this socket.

For more information about this option, see TcpStreamExt::set_quickack.

Examples
use std::net::TcpStream;
#[cfg(target_os = "linux")]
use std::os::linux::net::TcpStreamExt;
#[cfg(target_os = "android")]
use std::os::android::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);
Source
fn set_deferaccept(&self, accept: Duration) -> Result<()>
🔬This is a nightly-only experimental API. (tcp_deferaccept #119639)

A socket listener will be awakened solely when data arrives.

The accept argument set the maximum delay until the data is available to read, reducing the number of short lived connections without data to process. Contrary to other platforms SO_ACCEPTFILTER feature equivalent, there is no necessity to set it after the listen call. Note that the delay is expressed as Duration from user’s perspective the call rounds it down to the nearest second expressible as a c_int.

See man 7 tcp

Examples
#![feature(tcp_deferaccept)]
use std::net::TcpStream;
use std::os::linux::net::TcpStreamExt;
use std::time::Duration;

let stream = TcpStream::connect("127.0.0.1:8080")
        .expect("Couldn't connect to the server...");
stream.set_deferaccept(Duration::from_secs(1u64)).expect("set_deferaccept call failed");
Source
fn deferaccept(&self) -> Result<Duration>
🔬This is a nightly-only experimental API. (tcp_deferaccept #119639)

Gets the accept delay value of the TCP_DEFER_ACCEPT option.

For more information about this option, see TcpStreamExt::set_deferaccept.

Examples
#![feature(tcp_deferaccept)]
use std::net::TcpStream;
use std::os::linux::net::TcpStreamExt;
use std::time::Duration;

let stream = TcpStream::connect("127.0.0.1:8080")
        .expect("Couldn't connect to the server...");
stream.set_deferaccept(Duration::from_secs(1u64)).expect("set_deferaccept call failed");
assert_eq!(stream.deferaccept().unwrap(), Duration::from_secs(1u64));

Implementors

1.89.0Source
impl TcpStreamExt for TcpStreamAvailable on Linux or Android or Cygwin only.

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/os/linux/net/trait.TcpStreamExt.html