Struct tokio::net::unix::WriteHalf

source ·
pub struct WriteHalf<'a>(_);
Expand description

Borrowed write half of a UnixStream, created by split.

Note that in the AsyncWrite implementation of this type, poll_shutdown will shut down the UnixStream stream in the write direction.

Writing to an WriteHalf is usually done using the convenience methods found on the AsyncWriteExt trait.

Implementations§

source§

impl WriteHalf<'_>

source

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 UnixStream::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.

source

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.

source

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.

source

pub fn try_write_vectored(&self, buf: &[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.

source

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

Returns the socket address of the remote half of this connection.

source

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

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

Trait Implementations§

source§

impl AsRef<UnixStream> for WriteHalf<'_>

source§

fn as_ref(&self) -> &UnixStream

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsyncWrite for WriteHalf<'_>

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_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>] ) -> Poll<Result<usize>>

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§

fn poll_flush(self: Pin<&mut Self>, _: &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>, _: &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§

impl<'a> Debug for WriteHalf<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for WriteHalf<'a>

§

impl<'a> Send for WriteHalf<'a>

§

impl<'a> Sync for WriteHalf<'a>

§

impl<'a> Unpin for WriteHalf<'a>

§

impl<'a> UnwindSafe for WriteHalf<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.