Skip to main content

from_tcp_stream

Function from_tcp_stream 

Source
pub fn from_tcp_stream(stream: TcpStream, cfg: SharedCfg) -> Result<Io>
Expand description

Converts a standard-library TCP stream into an [Io] value.

§TCP_NODELAY

This function does not change TCP_NODELAY; the stream keeps the value it already has. With the option disabled, Nagle’s algorithm may delay small writes, so callers that need low latency must enable it first:

stream.set_nodelay(true)?;
let io = ntex_net::from_tcp_stream(stream, Default::default())?;

Streams accepted from a listener with TCP_NODELAY enabled inherit the option on Linux and macOS, so they do not need the extra call.

§Panics

Panics if called outside an ntex runtime, for example from a plain thread or a runtime from another crate. Call it from code running under #[ntex::main], #[ntex::test], or an ntex System.