Trait net2::TcpStreamExt

source ·
pub trait TcpStreamExt {
Show 27 methods // Required methods fn set_nodelay(&self, nodelay: bool) -> Result<()>; fn nodelay(&self) -> Result<bool>; fn set_recv_buffer_size(&self, size: usize) -> Result<()>; fn recv_buffer_size(&self) -> Result<usize>; fn set_send_buffer_size(&self, size: usize) -> Result<()>; fn send_buffer_size(&self) -> Result<usize>; fn set_keepalive_ms(&self, keepalive: Option<u32>) -> Result<()>; fn keepalive_ms(&self) -> Result<Option<u32>>; fn set_keepalive(&self, keepalive: Option<Duration>) -> Result<()>; fn keepalive(&self) -> Result<Option<Duration>>; fn set_read_timeout_ms(&self, val: Option<u32>) -> Result<()>; fn set_read_timeout(&self, val: Option<Duration>) -> Result<()>; fn read_timeout_ms(&self) -> Result<Option<u32>>; fn read_timeout(&self) -> Result<Option<Duration>>; fn set_write_timeout_ms(&self, val: Option<u32>) -> Result<()>; fn set_write_timeout(&self, val: Option<Duration>) -> Result<()>; fn write_timeout_ms(&self) -> Result<Option<u32>>; fn write_timeout(&self) -> Result<Option<Duration>>; fn set_ttl(&self, ttl: u32) -> Result<()>; fn ttl(&self) -> Result<u32>; fn set_only_v6(&self, only_v6: bool) -> Result<()>; fn only_v6(&self) -> Result<bool>; fn connect<T: ToSocketAddrs>(&self, addr: T) -> Result<()>; fn take_error(&self) -> Result<Option<Error>>; fn set_nonblocking(&self, nonblocking: bool) -> Result<()>; fn set_linger(&self, dur: Option<Duration>) -> Result<()>; fn linger(&self) -> Result<Option<Duration>>;
}
Expand description

Extension methods for the standard TcpStream type in std::net.

Required Methods§

source

fn set_nodelay(&self, nodelay: bool) -> Result<()>

Sets the value of the TCP_NODELAY option on this socket.

If set, this option disables the Nagle algorithm. This means that segments are always sent as soon as possible, even if there is only a small amount of data. When not set, data is buffered until there is a sufficient amount to send out, thereby avoiding the frequent sending of small packets.

source

fn nodelay(&self) -> Result<bool>

Gets the value of the TCP_NODELAY option on this socket.

For more information about this option, see set_nodelay.

source

fn set_recv_buffer_size(&self, size: usize) -> Result<()>

Sets the value of the SO_RCVBUF option on this socket.

Changes the size of the operating system’s receive buffer associated with the socket.

source

fn recv_buffer_size(&self) -> Result<usize>

Gets the value of the SO_RCVBUF option on this socket.

For more information about this option, see set_recv_buffer_size.

source

fn set_send_buffer_size(&self, size: usize) -> Result<()>

Sets the value of the SO_SNDBUF option on this socket.

Changes the size of the operating system’s send buffer associated with the socket.

source

fn send_buffer_size(&self) -> Result<usize>

Gets the value of the SO_SNDBUF option on this socket.

For more information about this option, see set_send_buffer.

source

fn set_keepalive_ms(&self, keepalive: Option<u32>) -> Result<()>

Sets whether keepalive messages are enabled to be sent on this socket.

On Unix, this option will set the SO_KEEPALIVE as well as the TCP_KEEPALIVE or TCP_KEEPIDLE option (depending on your platform). On Windows, this will set the SIO_KEEPALIVE_VALS option.

If None is specified then keepalive messages are disabled, otherwise the number of milliseconds specified will be the time to remain idle before sending a TCP keepalive probe.

Some platforms specify this value in seconds, so sub-second millisecond specifications may be omitted.

source

fn keepalive_ms(&self) -> Result<Option<u32>>

Returns whether keepalive messages are enabled on this socket, and if so the amount of milliseconds between them.

For more information about this option, see set_keepalive_ms.

source

fn set_keepalive(&self, keepalive: Option<Duration>) -> Result<()>

Sets whether keepalive messages are enabled to be sent on this socket.

On Unix, this option will set the SO_KEEPALIVE as well as the TCP_KEEPALIVE or TCP_KEEPIDLE option (depending on your platform). On Windows, this will set the SIO_KEEPALIVE_VALS option.

If None is specified then keepalive messages are disabled, otherwise the duration specified will be the time to remain idle before sending a TCP keepalive probe.

Some platforms specify this value in seconds, so sub-second specifications may be omitted.

source

fn keepalive(&self) -> Result<Option<Duration>>

Returns whether keepalive messages are enabled on this socket, and if so the duration of time between them.

For more information about this option, see set_keepalive.

source

fn set_read_timeout_ms(&self, val: Option<u32>) -> Result<()>

Sets the SO_RCVTIMEO option for this socket.

This option specifies the timeout, in milliseconds, of how long calls to this socket’s read function will wait before returning a timeout. A value of None means that no read timeout should be specified and otherwise Some indicates the number of milliseconds for the timeout.

source

fn set_read_timeout(&self, val: Option<Duration>) -> Result<()>

Sets the SO_RCVTIMEO option for this socket.

This option specifies the timeout of how long calls to this socket’s read function will wait before returning a timeout. A value of None means that no read timeout should be specified and otherwise Some indicates the number of duration of the timeout.

source

fn read_timeout_ms(&self) -> Result<Option<u32>>

Gets the value of the SO_RCVTIMEO option for this socket.

For more information about this option, see set_read_timeout_ms.

source

fn read_timeout(&self) -> Result<Option<Duration>>

Gets the value of the SO_RCVTIMEO option for this socket.

For more information about this option, see set_read_timeout.

source

fn set_write_timeout_ms(&self, val: Option<u32>) -> Result<()>

Sets the SO_SNDTIMEO option for this socket.

This option specifies the timeout, in milliseconds, of how long calls to this socket’s write function will wait before returning a timeout. A value of None means that no read timeout should be specified and otherwise Some indicates the number of milliseconds for the timeout.

source

fn set_write_timeout(&self, val: Option<Duration>) -> Result<()>

Sets the SO_SNDTIMEO option for this socket.

This option specifies the timeout of how long calls to this socket’s write function will wait before returning a timeout. A value of None means that no read timeout should be specified and otherwise Some indicates the duration of the timeout.

source

fn write_timeout_ms(&self) -> Result<Option<u32>>

Gets the value of the SO_SNDTIMEO option for this socket.

For more information about this option, see set_write_timeout_ms.

source

fn write_timeout(&self) -> Result<Option<Duration>>

Gets the value of the SO_SNDTIMEO option for this socket.

For more information about this option, see set_write_timeout.

source

fn set_ttl(&self, ttl: u32) -> Result<()>

Sets the value for the IP_TTL option on this socket.

This value sets the time-to-live field that is used in every packet sent from this socket.

source

fn ttl(&self) -> Result<u32>

Gets the value of the IP_TTL option for this socket.

For more information about this option, see set_ttl.

source

fn set_only_v6(&self, only_v6: bool) -> Result<()>

Sets the value for the IPV6_V6ONLY option on this socket.

If this is set to true then the socket is restricted to sending and receiving IPv6 packets only. In this case two IPv4 and IPv6 applications can bind the same port at the same time.

If this is set to false then the socket can be used to send and receive packets from an IPv4-mapped IPv6 address.

source

fn only_v6(&self) -> Result<bool>

Gets the value of the IPV6_V6ONLY option for this socket.

For more information about this option, see set_only_v6.

source

fn connect<T: ToSocketAddrs>(&self, addr: T) -> Result<()>

Executes a connect operation on this socket, establishing a connection to the host specified by addr.

Note that this normally does not need to be called on a TcpStream, it’s typically automatically done as part of a normal TcpStream::connect function call or TcpBuilder::connect method call.

This should only be necessary if an unconnected socket was extracted from a TcpBuilder and then needs to be connected.

source

fn take_error(&self) -> Result<Option<Error>>

Get the value of the SO_ERROR option on this socket.

This will retrieve the stored error in the underlying socket, clearing the field in the process. This can be useful for checking errors between calls.

source

fn set_nonblocking(&self, nonblocking: bool) -> Result<()>

Moves this TCP stream into or out of nonblocking mode.

On Unix this corresponds to calling fcntl, and on Windows this corresponds to calling ioctlsocket.

source

fn set_linger(&self, dur: Option<Duration>) -> Result<()>

Sets the linger duration of this socket by setting the SO_LINGER option

source

fn linger(&self) -> Result<Option<Duration>>

reads the linger duration for this socket by getting the SO_LINGER option

Implementations on Foreign Types§

source§

impl TcpStreamExt for TcpStream

source§

fn set_recv_buffer_size(&self, size: usize) -> Result<()>

source§

fn recv_buffer_size(&self) -> Result<usize>

source§

fn set_send_buffer_size(&self, size: usize) -> Result<()>

source§

fn send_buffer_size(&self) -> Result<usize>

source§

fn set_nodelay(&self, nodelay: bool) -> Result<()>

source§

fn nodelay(&self) -> Result<bool>

source§

fn set_keepalive(&self, keepalive: Option<Duration>) -> Result<()>

source§

fn keepalive(&self) -> Result<Option<Duration>>

source§

fn set_keepalive_ms(&self, keepalive: Option<u32>) -> Result<()>

source§

fn keepalive_ms(&self) -> Result<Option<u32>>

source§

fn set_read_timeout_ms(&self, dur: Option<u32>) -> Result<()>

source§

fn read_timeout_ms(&self) -> Result<Option<u32>>

source§

fn set_write_timeout_ms(&self, dur: Option<u32>) -> Result<()>

source§

fn write_timeout_ms(&self) -> Result<Option<u32>>

source§

fn set_read_timeout(&self, dur: Option<Duration>) -> Result<()>

source§

fn read_timeout(&self) -> Result<Option<Duration>>

source§

fn set_write_timeout(&self, dur: Option<Duration>) -> Result<()>

source§

fn write_timeout(&self) -> Result<Option<Duration>>

source§

fn set_ttl(&self, ttl: u32) -> Result<()>

source§

fn ttl(&self) -> Result<u32>

source§

fn set_only_v6(&self, only_v6: bool) -> Result<()>

source§

fn only_v6(&self) -> Result<bool>

source§

fn connect<T: ToSocketAddrs>(&self, addr: T) -> Result<()>

source§

fn take_error(&self) -> Result<Option<Error>>

source§

fn set_nonblocking(&self, nonblocking: bool) -> Result<()>

source§

fn set_linger(&self, dur: Option<Duration>) -> Result<()>

source§

fn linger(&self) -> Result<Option<Duration>>

Implementors§