TcpStream

Trait TcpStream 

Source
pub trait TcpStream:
    TryFrom<TcpStream, Error = Error>
    + Fd
    + AsyncReadWrite
    + Unpin
    + Send
    + Sync
    + 'static {
    type Runtime: RuntimeLite;
    type OwnedReadHalf: OwnedReadHalf;
    type OwnedWriteHalf: OwnedWriteHalf;
    type ReuniteError: ReuniteError<Self>;

Show 16 methods // Required methods fn connect<A: ToSocketAddrs<Self::Runtime>>( addr: A, ) -> impl Future<Output = Result<Self>> + Send where Self: Sized; fn connect_timeout( addr: &SocketAddr, timeout: Duration, ) -> impl Future<Output = Result<Self>> + Send where Self: Sized; fn peek(&self, buf: &mut [u8]) -> impl Future<Output = Result<usize>> + Send; fn local_addr(&self) -> Result<SocketAddr>; fn peer_addr(&self) -> Result<SocketAddr>; fn set_ttl(&self, ttl: u32) -> Result<()>; fn ttl(&self) -> Result<u32>; fn set_nodelay(&self, nodelay: bool) -> Result<()>; fn nodelay(&self) -> Result<bool>; fn into_split(self) -> (Self::OwnedReadHalf, Self::OwnedWriteHalf); fn reunite( read: Self::OwnedReadHalf, write: Self::OwnedWriteHalf, ) -> Result<Self, Self::ReuniteError> where Self: Sized; // Provided methods fn shutdown(&self, how: Shutdown) -> Result<()> { ... } fn try_clone(&self) -> Result<Self> { ... } fn only_v6(&self) -> Result<bool> { ... } fn linger(&self) -> Result<Option<Duration>> { ... } fn set_linger(&self, duration: Option<Duration>) -> Result<()> { ... }
}
Expand description

The abstraction of a TCP stream.

Required Associated Types§

Source

type Runtime: RuntimeLite

The async runtime.

Source

type OwnedReadHalf: OwnedReadHalf

The owned read half of the stream.

Source

type OwnedWriteHalf: OwnedWriteHalf

The owned write half of the stream.

Source

type ReuniteError: ReuniteError<Self>

Error indicating that two halves were not from the same socket, and thus could not be reunited.

Required Methods§

Source

fn connect<A: ToSocketAddrs<Self::Runtime>>( addr: A, ) -> impl Future<Output = Result<Self>> + Send
where Self: Sized,

Connects to the specified address.

Source

fn connect_timeout( addr: &SocketAddr, timeout: Duration, ) -> impl Future<Output = Result<Self>> + Send
where Self: Sized,

Opens a TCP connection to a remote host with a timeout.

Unlike connect, connect_timeout takes a single SocketAddr since timeout must be applied to individual addresses.

It is an error to pass a zero Duration to this function.

Unlike other methods on TcpStream, this does not correspond to a single system call. It instead calls connect in nonblocking mode and then uses an OS-specific mechanism to await the completion of the connection request.

Source

fn peek(&self, buf: &mut [u8]) -> impl Future<Output = Result<usize>> + Send

Receives data on the socket from the remote address to which it is connected, without removing that data from the queue.

On success, returns the number of bytes peeked.

Successive calls return the same data. This is accomplished by passing MSG_PEEK as a flag to the underlying recv system call.

Source

fn local_addr(&self) -> Result<SocketAddr>

Returns the local address that this stream is bound to.

Source

fn peer_addr(&self) -> Result<SocketAddr>

Returns the remote address that this stream is connected to.

Source

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

Sets the time-to-live value for this socket.

Source

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

Gets the time-to-live value of this socket.

Source

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

Sets the value of the TCP_NODELAY option on this socket.

Source

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

Gets the value of the TCP_NODELAY option on this socket.

Source

fn into_split(self) -> (Self::OwnedReadHalf, Self::OwnedWriteHalf)

Splits the stream to read and write halves.

Source

fn reunite( read: Self::OwnedReadHalf, write: Self::OwnedWriteHalf, ) -> Result<Self, Self::ReuniteError>
where Self: Sized,

Attempts to put the two halves of a TcpStream back together and recover the original socket. Succeeds only if the two halves originated from the same call to into_split.

Provided Methods§

Source

fn shutdown(&self, how: Shutdown) -> Result<()>

Shuts down the read, write, or both halves of this connection.

Source

fn try_clone(&self) -> Result<Self>

Creates a new independently owned handle to the underlying socket.

The returned UdpSocket is a reference to the same socket that this object references. Both handles will read and write the same port, and options set on one socket will be propagated to the other.

Source

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

Get the value of the IPV6_V6ONLY option for this socket.

Source

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

Gets the value of the SO_LINGER option on this socket.

For more information about this option, see TcpStream::set_linger.

Source

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

Sets the value of the SO_LINGER option on this socket.

This value controls how the socket is closed when data remains to be sent. If SO_LINGER is set, the socket will remain open for the specified duration as the system attempts to send pending data. Otherwise, the system may close the socket immediately, or wait for a default timeout.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§