UniStream

Struct UniStream 

Source
pub struct UniStream { /* private fields */ }
Expand description

A simple wrapper of tokio::net::TcpStream.

Implementations§

Source§

impl UniStream

Source

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

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

This function directly corresponds to the getsockname(2) function on Windows.

§Notes

Depending on the OS this may return an error if the socket is not bound.

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 Windows and Unix.

§Notes

This returns an error if the socket is not connected.

Source

pub async fn peek(&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.

Source

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

Sends data on the socket to a connected peer.

Source

pub fn shutdown(&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)

Source

pub fn as_socket_ref(&self) -> SockRef<'_>

Returns a SockRef to the underlying socket for configuration.

Trait Implementations§

Source§

impl AsyncRead for UniStream

Source§

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

Attempts to read from the AsyncRead into buf. Read more
Source§

impl AsyncWrite for UniStream

Source§

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

Attempt to write bytes from buf into the object. Read more
Source§

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

Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

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

Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
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(value: TcpStream) -> Result<Self, Self::Error>

Converts a Tokio TCP stream into a UniStream.

§Errors

This is infallible and always returns Ok, for APIs consistency.

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

§Panics

This function panics if it is not called from within a runtime with IO enabled.

The runtime is usually set implicitly when this function is called from a future driven by a tokio runtime, otherwise runtime can be set explicitly with Runtime::enter function.

Source§

type Error = Error

The type returned in the event of a conversion error.

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>,

Source§

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>,

Source§

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.