pub struct WriteHalf<'a>(&'a TcpStream);
Expand description
Borrowed write half of a TcpStream
, created by split
.
Note that in the AsyncWrite
implementation of this type, poll_shutdown
will
shut down the TCP stream in the write direction.
Writing to an WriteHalf
is usually done using the convenience methods found
on the AsyncWriteExt
trait.
Tuple Fields§
§0: &'a TcpStream
Implementations§
source§impl WriteHalf<'_>
impl WriteHalf<'_>
sourcepub async fn ready(&self, interest: Interest) -> Result<Ready>
pub async fn ready(&self, interest: Interest) -> Result<Ready>
Waits for any of the requested ready states.
This function is usually paired with try_write()
. It can be used instead
of writable()
to check the returned ready set for Ready::WRITABLE
and Ready::WRITE_CLOSED
events.
The function may complete without the socket being ready. This is a
false-positive and attempting an operation will return with
io::ErrorKind::WouldBlock
. The function can also return with an empty
Ready
set, so you should always check the returned value and possibly
wait again if the requested states are not set.
This function is equivalent to TcpStream::ready
.
§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 writable(&self) -> Result<()>
pub async fn writable(&self) -> Result<()>
Waits for the socket to become writable.
This function is equivalent to ready(Interest::WRITABLE)
and is usually
paired with try_write()
.
§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 write that fails with WouldBlock
or
Poll::Pending
.
sourcepub fn try_write(&self, buf: &[u8]) -> Result<usize>
pub fn try_write(&self, buf: &[u8]) -> Result<usize>
Tries to write a buffer to the stream, returning how many bytes were written.
The function will attempt to write the entire contents of buf
, but
only part of the buffer may be written.
This function is usually paired with writable()
.
§Return
If data is successfully written, Ok(n)
is returned, where n
is the
number of bytes written. If the stream is not ready to write data,
Err(io::ErrorKind::WouldBlock)
is returned.
sourcepub fn try_write_vectored(&self, bufs: &[IoSlice<'_>]) -> Result<usize>
pub fn try_write_vectored(&self, bufs: &[IoSlice<'_>]) -> Result<usize>
Tries to write several buffers to the stream, returning how many bytes were written.
Data is written from each buffer in order, with the final buffer read
from possible being only partially consumed. This method behaves
equivalently to a single call to try_write()
with concatenated
buffers.
This function is usually paired with writable()
.
§Return
If data is successfully written, Ok(n)
is returned, where n
is the
number of bytes written. If the stream is not ready to write data,
Err(io::ErrorKind::WouldBlock)
is returned.
sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Returns the remote address that this stream is connected to.
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local address that this stream is bound to.
Trait Implementations§
source§impl AsyncWrite for WriteHalf<'_>
impl AsyncWrite for WriteHalf<'_>
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_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize>>
fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>
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 more