pub struct UniStream { /* private fields */ }Expand description
A simple wrapper of tokio::net::TcpStream.
Implementations§
Source§impl UniStream
impl UniStream
Sourcepub fn local_addr(&self) -> Result<UniAddr>
pub fn local_addr(&self) -> Result<UniAddr>
Sourcepub async fn peek(&self, buf: &mut [MaybeUninit<u8>]) -> Result<usize>
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.
Sourcepub fn poll_peek(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<Result<usize>>
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.
Sourcepub async fn read(&mut self, buf: &mut [MaybeUninit<u8>]) -> Result<usize>
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.
Sourcepub async fn write(&mut self, buf: &[u8]) -> Result<usize>
pub async fn write(&mut self, buf: &[u8]) -> Result<usize>
Sends data on the socket to a connected peer.
Sourcepub fn shutdown(&self, shutdown: Shutdown) -> Result<()>
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.
Sourcepub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf)
pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf)
Sourcepub fn as_socket_ref(&self) -> SockRef<'_>
pub fn as_socket_ref(&self) -> SockRef<'_>
Returns a SockRef to the underlying socket for configuration.
Trait Implementations§
Source§impl AsyncWrite for UniStream
impl AsyncWrite for UniStream
Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Source§fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Source§fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write, except that it writes from a slice of buffers. Read moreSource§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moreSource§impl TryFrom<TcpStream> for UniStream
impl TryFrom<TcpStream> for UniStream
Source§fn try_from(stream: TcpStream) -> Result<Self, Self::Error>
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.