Trait fuchsia_async::WritableHandle

source ·
pub trait WritableHandle {
    // Required methods
    fn poll_writable(
        &self,
        cx: &mut Context<'_>,
    ) -> Poll<Result<WritableState, Status>>;
    fn need_writable(&self, cx: &mut Context<'_>) -> Poll<Result<(), Status>>;
}
Expand description

A Handle that receives notifications when it is writable.

§Examples

loop {
    ready!(self.poll_writable(cx))?;
    match /* make write syscall */ {
        Err(zx::Status::SHOULD_WAIT) => ready!(self.need_writable(cx)?),
        status => Poll::Ready(status),
    }
}

Required Methods§

source

fn poll_writable( &self, cx: &mut Context<'_>, ) -> Poll<Result<WritableState, Status>>

If the object is ready for writing, returns Ready with the writable state. If the implementor returns Pending, it should first ensure that need_writable is called.

This should be called in a poll function. If the syscall returns SHOULD_WAIT, you must call need_writable to schedule wakeup when the object is writable.

The returned WritableState does not necessarily reflect an observed OBJECT_WRITABLE signal. We optimistically assume the object remains writable until need_writable is called.

source

fn need_writable(&self, cx: &mut Context<'_>) -> Poll<Result<(), Status>>

Arranges for the current task to be woken when the object receives an OBJECT_WRITABLE or OBJECT_PEER_CLOSED signal. This can return Poll::Ready if the object has already been signaled in which case the waker will not be woken and it is the caller’s responsibility to not lose the signal.

Implementors§