Skip to main content

AsyncTcpStream

Trait AsyncTcpStream 

Source
pub trait AsyncTcpStream:
    Send
    + Sync
    + Debug {
    // Required methods
    fn poll_read(
        &self,
        cx: &mut Context<'_>,
        buf: &mut [u8],
    ) -> Poll<Result<usize>>;
    fn poll_write(
        &self,
        cx: &mut Context<'_>,
        buf: &[u8],
    ) -> Poll<Result<usize>>;
    fn shutdown_write(&self) -> Result<()>;
    fn reset_on_close(&self) -> Result<()>;
    fn set_traffic_class(&self, value: u8) -> Result<u32>;
    fn local_addr(&self) -> Result<SocketAddr>;
    fn peer_addr(&self) -> Result<SocketAddr>;
}
Expand description

A TCP connection of a runtime. &self methods: the driver’s reader and writer tasks share one Arc.

Required Methods§

Source

fn poll_read(&self, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<Result<usize>>

Reads into buf; 0 at the peer’s end of stream.

Source

fn poll_write(&self, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>

Writes some of buf; how much.

Source

fn shutdown_write(&self) -> Result<()>

Ends the sending direction (FIN).

§Errors

The socket refused.

Source

fn reset_on_close(&self) -> Result<()>

Makes the close abortive (SO_LINGER 0): when the last reference is dropped the connection is reset (RST) instead of closed with FIN.

§Errors

The socket refused.

Source

fn set_traffic_class(&self, value: u8) -> Result<u32>

Sets the socket’s TOS / Traffic Class byte and returns what the operating system reports for it afterwards.

§Errors

The platform refused the option or does not offer it.

Source

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

Its local address.

Source

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

The peer’s address.

Implementations§

Source§

impl<'a> dyn AsyncTcpStream + 'a

Source

pub async fn read(&self, buf: &mut [u8]) -> Result<usize>

Reads into buf; 0 at the peer’s end of stream.

Source

pub async fn write_all(&self, buf: &[u8]) -> Result<()>

Writes all of buf.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§