pub struct ReadHalf<'a>(_);
Expand description
Borrowed read half of a UnixStream
, created by split
.
Reading from a ReadHalf
is usually done using the convenience methods found on the
AsyncReadExt
trait.
Implementations
sourceimpl ReadHalf<'_>
impl ReadHalf<'_>
sourcepub async fn ready(&self, interest: Interest) -> Result<Ready>
pub async fn ready(&self, interest: Interest) -> Result<Ready>
Wait for any of the requested ready states.
This function is usually paired with try_read()
or try_write()
. It
can be used to concurrently read / write to the same socket on a single
task without splitting the socket.
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
.
sourcepub async fn readable(&self) -> Result<()>
pub async fn readable(&self) -> Result<()>
Waits for the socket to become readable.
This function is equivalent to ready(Interest::READABLE)
and is usually
paired with try_read()
.
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 that fails with WouldBlock
or
Poll::Pending
.
sourcepub fn try_read(&self, buf: &mut [u8]) -> Result<usize>
pub fn try_read(&self, buf: &mut [u8]) -> Result<usize>
Tries to read data from the stream into the provided buffer, returning how many bytes were read.
Receives any pending data from the socket but does not wait for new data
to arrive. On success, returns the number of bytes read. Because
try_read()
is non-blocking, the buffer does not have to be stored by
the async task and can exist entirely on the stack.
Usually, readable()
or ready()
is used with this function.
Return
If data is successfully read, Ok(n)
is returned, where n
is the
number of bytes read. Ok(0)
indicates the stream’s read half is closed
and will no longer yield data. If the stream is not ready to read data
Err(io::ErrorKind::WouldBlock)
is returned.
sourcepub fn try_read_buf<B: BufMut>(&self, buf: &mut B) -> Result<usize>
pub fn try_read_buf<B: BufMut>(&self, buf: &mut B) -> Result<usize>
Tries to read data from the stream into the provided buffer, advancing the buffer’s internal cursor, returning how many bytes were read.
Receives any pending data from the socket but does not wait for new data
to arrive. On success, returns the number of bytes read. Because
try_read_buf()
is non-blocking, the buffer does not have to be stored by
the async task and can exist entirely on the stack.
Usually, readable()
or ready()
is used with this function.
Return
If data is successfully read, Ok(n)
is returned, where n
is the
number of bytes read. Ok(0)
indicates the stream’s read half is closed
and will no longer yield data. If the stream is not ready to read data
sourcepub fn try_read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
pub fn try_read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
Tries to read data from the stream into the provided buffers, returning how many bytes were read.
Data is copied to fill each buffer in order, with the final buffer
written to possibly being only partially filled. This method behaves
equivalently to a single call to try_read()
with concatenated
buffers.
Receives any pending data from the socket but does not wait for new data
to arrive. On success, returns the number of bytes read. Because
try_read_vectored()
is non-blocking, the buffer does not have to be
stored by the async task and can exist entirely on the stack.
Usually, readable()
or ready()
is used with this function.
Return
If data is successfully read, Ok(n)
is returned, where n
is the
number of bytes read. Ok(0)
indicates the stream’s read half is closed
and will no longer yield data. If the stream is not ready to read data
Err(io::ErrorKind::WouldBlock)
is returned.
sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Returns the socket address of the remote half of this connection.
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the socket address of the local half of this connection.
Trait Implementations
sourceimpl AsRef<UnixStream> for ReadHalf<'_>
impl AsRef<UnixStream> for ReadHalf<'_>
sourcefn as_ref(&self) -> &UnixStream
fn as_ref(&self) -> &UnixStream
Converts this type into a shared reference of the (usually inferred) input type.
Auto Trait Implementations
impl<'a> RefUnwindSafe for ReadHalf<'a>
impl<'a> Send for ReadHalf<'a>
impl<'a> Sync for ReadHalf<'a>
impl<'a> Unpin for ReadHalf<'a>
impl<'a> UnwindSafe for ReadHalf<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more