dope-core 0.75.0

Owned native I/O and completion driver for dope
Documentation
use crate::{
    driver,
    driver::{life::native::request, retained::flight, route, route::kind},
    io::{fd::handles::Descriptor, socket::pending},
};

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

impl<'d> Query<'d> {
    pub fn try_new<Tag: route::Tag + route::Select<kind::Tuning>>(
        driver: &mut driver::Local<'d>,
        _slots: &flight::Slots<'d, Tag>,
        _target: route::Target<'d, Tag>,
        fd: Descriptor<'d>,
    ) -> Result<Self, pending::Rejection<'d>> {
        #[cfg(target_os = "linux")]
        {
            // SAFETY: this exact descriptor and route retain the same driver's
            // native slot through the peer-query completion.
            match unsafe { request::peer(driver, _slots, _target.operation::<kind::Tuning>(), &fd) }
            {
                Ok(flight) => Ok(Self::Pending(pending::Tuning::new(fd, flight, ()))),
                Err(cause) => Err(pending::Rejection::new(fd, cause)),
            }
        }
        #[cfg(target_os = "macos")]
        {
            match request::peer(driver, &fd) {
                Ok(value) => Ok(Self::Ready(fd, uid(value))),
                Err(cause) => Err(pending::Rejection::new(fd, pending::Cause::Option(cause))),
            }
        }
    }
}

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