dope-uring 0.77.0

Owned io_uring backend for dope
Documentation
use crate::reactor::register::owned;
use dope_sys::{
    kernel,
    probe::{Cause, Outcome as _, Stopped, accept},
    ring::Owner,
    table::token::{self, host},
};

use crate::{
    Observed, Ring, error,
    reactor::{
        ring::{Outcome, wait},
        sq,
    },
};

type Identity<T> = <<T as token::Codec>::Context as host::Context>::Probe;
type Fault<T> = Cause<Identity<T>, Observed<T>, kernel::Errno<error::Enter>>;
type Checked<T> = Outcome<T, Identity<T>>;

#[must_use = "a live accept canary must reach its terminal completion"]
pub struct Accepted<T: token::Codec> {
    ring: Ring<T>,
    probe: Identity<T>,
}

impl<T: token::Codec> accept::Accept for Accepted<T> {
    type Ring = Ring<T>;
    type Owned = sq::Owned<T>;
    type Probe = Identity<T>;
    type Outcome = Checked<T>;
    type Error = kernel::Errno<error::Enter>;
    type File = owned::Occupied;
    type Closing = <Ring<T> as Owner>::Closing;

    fn new(ring: Ring<T>, probe: Identity<T>) -> Self {
        Self { ring, probe }
    }

    fn submit(
        mut self,
        entry: sq::Owned<T>,
    ) -> Result<(Self, Checked<T>), Stopped<Self, Fault<T>>> {
        let result = wait::run(&mut self.ring, &entry, self.probe);
        Stopped::attach(self, result)
    }

    fn cancel(mut self) -> Result<Ring<T>, Stopped<Self, Fault<T>>> {
        let probe = self.probe;
        let target = T::probe(probe);
        let complete = T::cancel_probe(probe);
        let vacancy = match wait::reserve(&mut self.ring, probe) {
            Ok(vacancy) => vacancy,
            Err(cause) => return Err(Stopped { state: self, cause }),
        };
        vacancy.cancel::<false>(target, complete);
        let result = wait::next(&mut self.ring, probe);
        let (state, done) = Stopped::attach(self, result)?;
        let (state, ()) = Stopped::attach(state, done.canceled().map_err(Cause::Check))?;
        Ok(state.ring)
    }

    fn try_close(self, file: Self::File) -> Result<(), <Ring<T> as Owner>::Closing> {
        self.ring.close_file(file)
    }
}