pub trait CompletionWait {
// Required method
fn wait(&mut self, ring: &mut RingWait<'_>, timeout_ms: u32) -> Result<()>;
}Expand description
How IoRing::pop_within_with blocks between checks of the completion
queue (M21.2).
Implement this to drive a bounded pop from a wait this crate does not own
– a completion event the caller already holds, a multiplexed
WaitForMultipleObjects, or a pure spin on a thread that must not block
in the kernel.
Required Methods§
Sourcefn wait(&mut self, ring: &mut RingWait<'_>, timeout_ms: u32) -> Result<()>
fn wait(&mut self, ring: &mut RingWait<'_>, timeout_ms: u32) -> Result<()>
Block until a completion may be available, or timeout_ms elapses.
Returning early or spuriously is always permitted, and requires no apology: D-19 makes a wake with nothing to pop a normal event, so the caller re-checks the queue either way. An implementation therefore cannot be subtly wrong about when to return; it can only waste time or burn CPU.
What it must not do is block past timeout_ms, because that is the
only thing standing between a stuck ring and a hung process.
§An expired wait is Ok(()), never an error
This is the one part of the contract an implementation can get wrong
silently, and the crate’s own SubmitWait got it wrong first: Win32
reports an expired wait as a failure code (ERROR_TIMEOUT from
SubmitIoRing, WAIT_TIMEOUT from the WaitFor* family), so
forwarding the underlying result verbatim turns every ordinary timeout
into an Err. IoRing::pop_within then reports a timeout as a
failure rather than as the Ok(None) it promises, and every caller
that matches on Ok(None) to detect a timeout stops working.
So: the bound running out is a successful wait that happened to observe nothing. Report the error only when the wait itself failed.
timeout_ms is never zero and never u32::MAX, so it can be passed
straight to a Win32 wait without being mistaken for “poll and return”
or for INFINITE.
§Errors
Whatever the underlying wait reports as a genuine failure. An error ends the pop.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".