pub trait ReadableHandle {
    // Required methods
    fn poll_readable(
        &self,
        cx: &mut Context<'_>
    ) -> Poll<Result<ReadableState, Status>>;
    fn need_readable(&self, cx: &mut Context<'_>) -> Poll<Result<(), Status>>;
}
Expand description

A Handle that receives notifications when it is readable.

§Examples

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

Required Methods§

source

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

If the object is ready for reading, returns Ready with the readable state. If the implementor returns Pending, it should first ensure that need_readable is called.

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

The returned ReadableState does not necessarily reflect an observed OBJECT_READABLE signal. We optimistically assume the object remains readable until need_readable is called.

source

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

Arranges for the current task to be woken when the object receives an OBJECT_READABLE 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§

source§

impl ReadableHandle for Socket

source§

impl<T> ReadableHandle for RWHandle<T>
where T: AsHandleRef,