Trait fuchsia_async::ReadableHandle
source · pub trait ReadableHandle {
// Required methods
fn poll_readable(
&self,
cx: &mut Context<'_>
) -> Poll<Result<ReadableState, Status>>;
fn need_readable(&self, cx: &mut Context<'_>) -> Result<(), Status>;
}
Expand description
A Handle
that receives notifications when it is readable.
Examples
ready!(self.poll_readable(cx))?;
match /* make read syscall */ {
Err(zx::Status::SHOULD_WAIT) => {
self.need_readable(cx)?;
Poll::Pending
}
status => Poll::Ready(status),
}
Required Methods§
sourcefn poll_readable(
&self,
cx: &mut Context<'_>
) -> Poll<Result<ReadableState, Status>>
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 before making a read syscall.
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. If you only want to read once
the object is confirmed to be readable, call need_readable
with a
no-op waker before the first poll.
sourcefn need_readable(&self, cx: &mut Context<'_>) -> Result<(), Status>
fn need_readable(&self, cx: &mut Context<'_>) -> Result<(), Status>
Arranges for the current task to be woken when the object receives an
OBJECT_READABLE
or OBJECT_PEER_CLOSED
signal.