dope-sys 0.78.0

Typed operating-system call contracts
Documentation
use o3::{buffer::bytes, depot::capacity::Limit};

use crate::{
    Errno,
    engine::admit::{Context, Native},
    io::{
        self, file,
        reactor::Full,
        request,
        socket::{addr, option},
    },
};

type Slot<C> = <<C as Context>::Native as request::Source<<C as Context>::Inputs>>::Target;
type Target<C> = <<C as Context>::Inputs as request::Context>::Target;
type File<'a, C> = <<C as Context>::Native as file::File>::Request<'a>;

/// The host's existing vacancy, reservation and committed flight.
pub trait Flight<I> {
    type Front: Into<Self::Reserved>;
    type Reserved: Into<Self::Output>;
    type Output;
    type Error: From<Full> + From<Errno>;

    /// # Safety
    /// Keep this group's free list exclusive until the returned front is consumed.
    unsafe fn front(input: I) -> Result<Self::Front, Self::Error>;
}

/// Consumes the exact native requests whose pointees remain owned by the host.
pub trait Retain<C: Context>: Sized {
    /// # Safety
    /// Retain the descriptor and bytes through terminal completion or quiescence.
    unsafe fn send(
        self,
        slot: Slot<C>,
        input: bytes::Prefix<'_, { i32::MAX as usize }>,
        key: C::Key,
    );

    /// # Safety
    /// Retain the descriptor and the complete message graph through completion or quiescence.
    unsafe fn send_msg<'a>(self, slot: Slot<C>, message: impl io::raw::Message<'a>, key: C::Key);

    /// # Safety
    /// Retain the listener and exclusive peer output through completion or quiescence.
    unsafe fn accept(self, listener: Slot<C>, peer: &mut addr::Storage, key: C::Key);

    /// # Safety
    /// Retain the descriptor and address through completion or quiescence.
    unsafe fn connect(self, slot: Slot<C>, address: addr::Addr<'_>, key: C::Key);

    /// # Safety
    /// Every file request borrow remains live through terminal completion or quiescence.
    unsafe fn file(self, request: File<'_, C>, key: C::Key);
}

/// Native socket effects consume the host's admitted flight directly.
pub trait Socket<C: Context, const N: usize> {
    /// # Safety
    /// Retain the descriptor, address and flight through completion or quiescence.
    /// Native admission must not access the host's free list.
    unsafe fn connect<I, O>(
        &mut self,
        input: I,
        slot: Target<C>,
        options: Option<(Limit<N>, O)>,
        address: addr::Addr<'_>,
        retry: &mut bool,
    ) -> Result<C::Output, C::Error>
    where
        C: Flight<I>,
        <C as Context>::Key: for<'a> From<&'a C::Reserved>,
        O: option::Cursor;

    /// # Safety
    /// The descriptor and flight belong to this backend and retain its pinned values.
    /// Native admission must not access the host's free list.
    unsafe fn tune<I, O, D, R, E>(
        &mut self,
        input: I,
        fd: D,
        slot: Target<C>,
        options: Option<(Limit<N>, O)>,
        retry: &mut bool,
    ) -> Result<R, E>
    where
        C: Flight<I>,
        <C as Context>::Key: for<'a> From<&'a C::Reserved>,
        O: option::Cursor,
        R: From<D> + From<(D, C::Output, <C::Native as Native>::Permit)>,
        E: From<(D, C::Error)>;

    /// # Safety
    /// The descriptor and flight belong to this backend and retain its pinned output.
    /// Native admission must not access the host's free list.
    unsafe fn peer<I, D, R, E>(
        &mut self,
        input: I,
        fd: D,
        slot: Target<C>,
        retry: &mut bool,
    ) -> Result<R, E>
    where
        C: Flight<I>,
        <C as Context>::Key: for<'a> From<&'a C::Reserved>,
        R: From<(D, u32)> + From<(D, C::Output, <C::Native as Native>::Permit)>,
        E: From<(D, C::Error)>;
}