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§
Sourcetype Runtime: RuntimeLite
type Runtime: RuntimeLite
The async runtime.
Sourcetype OwnedReadHalf: OwnedReadHalf
type OwnedReadHalf: OwnedReadHalf
The owned read half of the stream.
Sourcetype OwnedWriteHalf: OwnedWriteHalf
type OwnedWriteHalf: OwnedWriteHalf
The owned write half of the stream.
Sourcetype ReuniteError: ReuniteError<Self>
type ReuniteError: ReuniteError<Self>
Error indicating that two halves were not from the same socket, and thus could not be reunited.
Required Methods§
Sourcefn connect<A: ToSocketAddrs<Self::Runtime>>(
addr: A,
) -> impl Future<Output = Result<Self>> + Sendwhere
Self: Sized,
fn connect<A: ToSocketAddrs<Self::Runtime>>(
addr: A,
) -> impl Future<Output = Result<Self>> + Sendwhere
Self: Sized,
Connects to the specified address.
Sourcefn connect_timeout(
addr: &SocketAddr,
timeout: Duration,
) -> impl Future<Output = Result<Self>> + Sendwhere
Self: Sized,
fn connect_timeout(
addr: &SocketAddr,
timeout: Duration,
) -> impl Future<Output = Result<Self>> + Sendwhere
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.
Sourcefn peek(&self, buf: &mut [u8]) -> impl Future<Output = Result<usize>> + Send
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.
Sourcefn local_addr(&self) -> Result<SocketAddr>
fn local_addr(&self) -> Result<SocketAddr>
Returns the local address that this stream is bound to.
Sourcefn peer_addr(&self) -> Result<SocketAddr>
fn peer_addr(&self) -> Result<SocketAddr>
Returns the remote address that this stream is connected to.
Sourcefn set_nodelay(&self, nodelay: bool) -> Result<()>
fn set_nodelay(&self, nodelay: bool) -> Result<()>
Sets the value of the TCP_NODELAY option on this socket.
Sourcefn into_split(self) -> (Self::OwnedReadHalf, Self::OwnedWriteHalf)
fn into_split(self) -> (Self::OwnedReadHalf, Self::OwnedWriteHalf)
Splits the stream to read and write halves.
Sourcefn reunite(
read: Self::OwnedReadHalf,
write: Self::OwnedWriteHalf,
) -> Result<Self, Self::ReuniteError>where
Self: Sized,
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§
Sourcefn shutdown(&self, how: Shutdown) -> Result<()>
fn shutdown(&self, how: Shutdown) -> Result<()>
Shuts down the read, write, or both halves of this connection.
Sourcefn try_clone(&self) -> Result<Self>
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.
Sourcefn linger(&self) -> Result<Option<Duration>>
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.
Sourcefn set_linger(&self, duration: Option<Duration>) -> Result<()>
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.