UniStream

Type Alias UniStream 

Source
pub type UniStream = UniSocket<StreamTy>;
Expand description

A UniSocket used as a stream.

Aliased Type§

pub struct UniStream { /* private fields */ }

Implementations§

Source§

impl UniStream

Source

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

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

This function directly corresponds to the getpeername(2) function on Unix.

§Notes

This returns an error if the socket is not connected.

Source

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

Receives data on the socket from the remote adress 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

pub fn poll_peek( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll<Result<usize>>

Receives data on the socket from the remote adress 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.

Notes that on multiple calls to poll_peek, only the waker from the Context passed to the most recent call is scheduled to receive a wakeup. Unless you are implementing your own future accepting connections, you probably want to use the asynchronous accept method instead.

Source

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

Receives data on the socket from the remote address to which it is connected.

§Cancel safety

This method is cancel safe. Once a readiness event occurs, the method will continue to return immediately until the readiness event is consumed by an attempt to read or write that fails with WouldBlock or Poll::Pending.

Source

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

Sends data on the socket to a connected peer.

§Cancel safety

This method is cancel safe. Once a readiness event occurs, the method will continue to return immediately until the readiness event is consumed by an attempt to read or write that fails with WouldBlock or Poll::Pending.

Source

pub fn shutdown(&mut self, shutdown: 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.

Source

pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf)

Splits a UniStream into a read half and a write half, which can be used to read and write the stream concurrently.

Note: dropping the write half will shutdown the write half of the stream.

Trait Implementations§

Source§

impl AsyncRead for UniStream

Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll<Result<()>>

Receives data on the socket from the remote address to which it is connected.

Notes that on multiple calls to poll_read, only the waker from the Context passed to the most recent call is scheduled to receive a wakeup. Unless you are implementing your own future accepting connections, you probably want to use the asynchronous read method instead.

Source§

impl AsyncWrite for UniStream

Source§

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

Sends data on the socket to a connected peer.

Notes that on multiple calls to poll_write, only the waker from the Context passed to the most recent call is scheduled to receive a wakeup. Unless you are implementing your own future accepting connections, you probably want to use the asynchronous write method instead.

Source§

fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>

For TCP and Unix domain sockets, flush is a no-op.

Source§

fn poll_shutdown( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<()>>

See shutdown.

Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>

Like poll_write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

Determines if this writer has an efficient poll_write_vectored implementation. Read more
Source§

impl Debug for UniStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TryFrom<TcpStream> for UniStream

Source§

fn try_from(stream: TcpStream) -> Result<Self, Self::Error>

Converts a Tokio TCP stream into a unified UniStream.

§Panics

This function panics if there is no current Tokio reactor set, or if the rt feature flag is not enabled.

Source§

type Error = Error

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

impl TryFrom<TcpStream> for UniStream

Source§

fn try_from(stream: TcpStream) -> Result<Self, Self::Error>

Converts a standard library TCP stream into a unified UniStream.

§Panics

This function panics if there is no current Tokio reactor set, or if the rt feature flag is not enabled.

Source§

type Error = Error

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

impl TryFrom<UnixStream> for UniStream

Source§

fn try_from(stream: UnixStream) -> Result<Self, Self::Error>

Converts a Tokio Unix stream into a unified UniStream.

§Panics

This function panics if there is no current Tokio reactor set, or if the rt feature flag is not enabled.

Source§

type Error = Error

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

impl TryFrom<UnixStream> for UniStream

Source§

fn try_from(stream: UnixStream) -> Result<Self, Self::Error>

Converts a standard library Unix stream into a unified UniStream.

§Panics

This function panics if there is no current Tokio reactor set, or if the rt feature flag is not enabled.

Source§

type Error = Error

The type returned in the event of a conversion error.