Struct compio_net::TcpStream
source · pub struct TcpStream { /* private fields */ }
Expand description
A TCP stream between a local and a remote socket.
A TCP stream can either be created by connecting to an endpoint, via the
connect
method, or by accepting a connection from a listener.
Examples
use std::net::SocketAddr;
use compio_net::TcpStream;
compio_runtime::block_on(async {
// Connect to a peer
let mut stream = TcpStream::connect("127.0.0.1:8080").await.unwrap();
// Write some data.
stream.send("hello world!").await.unwrap();
})
Implementations§
source§impl TcpStream
impl TcpStream
sourcepub async fn connect(addr: impl ToSockAddrs) -> Result<Self>
pub async fn connect(addr: impl ToSockAddrs) -> Result<Self>
Opens a TCP connection to a remote host.
sourcepub fn try_clone(&self) -> Result<Self>
pub fn try_clone(&self) -> Result<Self>
Creates a new independently owned handle to the underlying socket.
It does not clear the attach state.
sourcepub fn peer_addr(&self) -> Result<SockAddr>
pub fn peer_addr(&self) -> Result<SockAddr>
Returns the socket address of the remote peer of this TCP connection.
sourcepub fn local_addr(&self) -> Result<SockAddr>
pub fn local_addr(&self) -> Result<SockAddr>
Returns the socket address of the local half of this TCP connection.
sourcepub fn shutdown(&self, how: Shutdown) -> Result<()>
pub fn shutdown(&self, how: Shutdown) -> Result<()>
Shuts down the read, write, or both halves of this connection.
This function will cause all pending and future I/O on the specified
portions to return immediately with an appropriate value (see the
documentation of Shutdown
).
sourcepub async fn recv<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>
pub async fn recv<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>
Receives a packet of data from the socket into the buffer, returning the original buffer and quantity of data received.
sourcepub async fn recv_exact<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>
pub async fn recv_exact<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>
Receives exact number of bytes from the socket.
sourcepub async fn recv_vectored<T: IoVectoredBufMut>(
&self,
buffer: T
) -> BufResult<usize, T>
pub async fn recv_vectored<T: IoVectoredBufMut>( &self, buffer: T ) -> BufResult<usize, T>
Receives a packet of data from the socket into the buffer, returning the original buffer and quantity of data received.
sourcepub async fn send<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>
pub async fn send<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>
Sends some data to the socket from the buffer, returning the original buffer and quantity of data sent.
sourcepub async fn send_all<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>
pub async fn send_all<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>
Sends all data to the socket.
sourcepub async fn send_vectored<T: IoVectoredBuf>(
&self,
buffer: T
) -> BufResult<usize, T>
pub async fn send_vectored<T: IoVectoredBuf>( &self, buffer: T ) -> BufResult<usize, T>
Sends some data to the socket from the buffer, returning the original buffer and quantity of data sent.