dope-core 0.77.0

Owned native I/O and completion driver for dope
Documentation
use dope_sys::io::reactor::event::{Entry, kind};
use o3::mem::slot;

use crate::{
    Errno,
    driver::{self, retained::flight},
    io::{
        fd::handles::Descriptor,
        socket::{Completion, pending},
    },
};

/// The same descriptor and its observed peer UID, or its pending native owner.
pub enum Query<'d, P = pending::raw::Owner<'d, kind::Tuning>> {
    Ready(Descriptor<'d>, Option<u32>),
    Pending(P),
}

impl<'d> Query<'d> {
    pub fn complete<'slot>(
        owner: slot::Occupied<'slot, pending::raw::Owner<'d, kind::Tuning>>,
        done: &Entry<flight::Complete<'d>, kind::Tuning, Result<u32, Errno>>,
    ) -> Completion<'slot, 'd, pending::raw::Owner<'d, kind::Tuning>, Result<Option<u32>, Errno>>
    {
        let (fd, result) = pending::raw::Owner::complete(owner, done)?;
        Ok((fd, result.map(Self::uid)))
    }

    fn uid(value: u32) -> Option<u32> {
        (value != u32::MAX).then_some(value)
    }
}

impl<'d> From<((Descriptor<'d>, driver::Invariant<'d>), u32)> for Query<'d> {
    fn from(((fd, _), value): ((Descriptor<'d>, driver::Invariant<'d>), u32)) -> Self {
        Self::Ready(fd, Self::uid(value))
    }
}

impl<'d, P>
    From<(
        (Descriptor<'d>, driver::Invariant<'d>),
        flight::Flight<'d, kind::Tuning>,
        P,
    )> for Query<'d, pending::raw::Owner<'d, kind::Tuning, P>>
{
    fn from(
        ((fd, _), flight, permit): (
            (Descriptor<'d>, driver::Invariant<'d>),
            flight::Flight<'d, kind::Tuning>,
            P,
        ),
    ) -> Self {
        Self::Pending(pending::raw::Owner::new(fd, flight, permit))
    }
}