dope-core 0.77.0

Owned native I/O and completion driver for dope
Documentation
use std::mem;

use dope_sys::{
    engine::admit,
    io::{reactor::Full, request::Source},
};

use crate::{
    Backend, driver,
    driver::{
        life::native::{self, host::Host},
        retained::flight,
    },
    io::{fd::handles, socket::msg},
};

/// Native capacity retained while its owner initializes the final message slot.
#[repr(transparent)]
pub struct Admission<'a, 'd> {
    native: driver::Admission<'a>,
    driver: driver::Invariant<'d>,
}

impl<'a, 'd> Admission<'a, 'd> {
    pub fn try_new(context: &'a mut driver::Local<'d>) -> Result<Self, Full> {
        const {
            assert!(mem::size_of::<Self>() == mem::size_of::<driver::Admission<'a>>());
            assert!(mem::align_of::<Self>() == mem::align_of::<driver::Admission<'a>>());
        }
        let driver = context.driver.brand;
        let native = context.try_admit()?;
        Ok(Self { native, driver })
    }

    /// # Safety
    /// The descriptor, echoed slot and message graph belong to this driver and
    /// remain retained through terminal completion or quiescence.
    pub unsafe fn send_msg<'r>(
        self,
        fd: &'r handles::Descriptor<'d>,
        message: msg::Message<'r>,
        key: flight::Echo,
    ) where
        'd: 'r,
    {
        // SAFETY: the caller retains the admitted slot and immutable graph.
        unsafe {
            admit::raw::Retain::<Host<Backend>>::send_msg(
                self.native,
                <Backend as Source<native::Context>>::target(fd.slot()),
                message,
                key,
            );
        }
    }
}