dope-uring 0.77.0

Owned io_uring backend for dope
Documentation
use dope_sys::{
    io::reactor::complete::flags::{Flow, Meta as _},
    memory,
    probe::{Cause, Outcome as _, receive, receive::Context as _, session::Checked},
    table::token,
};

use crate::reactor::{
    buffers::Payload,
    register::owned::Occupied,
    ring::{
        session::{Fault, Inspect, Inspected, Pending},
        wait,
    },
};

type Inspection<T, L> = Result<(), Inspected<T, L, Inspect<T>>>;

pub(super) fn receive<
    T: token::Codec<Context: receive::Context<Payload>>,
    L: memory::raw::Canary,
>(
    active: &mut Pending<T, L, Occupied>,
    mode: receive::Mode,
    expected: &[u8],
) -> Result<(Flow, Inspection<T, L>), Fault<T>> {
    use dope_sys::memory::buffer::canary::raw::Storage as _;

    let probe = active.0.probe;
    let session = &mut active.0.state;
    let done = wait::next(session.ring(), probe)?;
    let meta = done.meta();
    let result = match (done.success(), meta.buffer()) {
        (Err(cause), _) => Err(Checked::Wait(Cause::Check(cause))),
        (Ok(_), None) => Err(Checked::MissingBuffer(probe)),
        (Ok(len), Some(buffer)) => {
            // SAFETY: this session consumed its probe's completion and still owns the buffer.
            unsafe {
                session
                    .owner
                    .storage_mut()
                    .inspect(buffer, len.into(), |bytes| {
                        T::Context::inspect(mode, bytes, expected)
                    })
            }
            .map_err(|failure| Checked::Buffer { probe, failure })
        }
    };
    Ok((meta.flow(), result))
}