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

source

pub async fn connect(addr: impl ToSockAddrs) -> Result<Self>

Opens a TCP connection to a remote host.

source

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

Creates a new independently owned handle to the underlying socket.

It does not clear the attach state.

source

pub fn peer_addr(&self) -> Result<SockAddr>

Returns the socket address of the remote peer of this TCP connection.

source

pub fn local_addr(&self) -> Result<SockAddr>

Returns the socket address of the local half of this TCP connection.

source

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).

source

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.

source

pub async fn recv_exact<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>

Receives exact number of bytes from the socket.

source

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.

source

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.

source

pub async fn send_all<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>

Sends all data to the socket.

source

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.

Trait Implementations§

source§

impl AsRawFd for TcpStream

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl FromRawFd for TcpStream

source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more
source§

impl IntoRawFd for TcpStream

source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.