dope-core 0.77.0

Owned native I/O and completion driver for dope
Documentation
use dope_sys::{
    io::reactor::event::Report,
    io::socket::{Setup, accept},
    table::registry,
};

use crate::{
    driver::{life, retained::accept::Readiness},
    io::fd::handles,
};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Failure {
    Syscall(crate::Errno),
    Registration(registry::Failure),
    Setup(Setup),
    Capacity { close: Result<(), crate::Errno> },
    Retired(handles::PhysicalSlot),
    Quarantined(handles::PhysicalSlot),
}

impl Failure {
    /// Settles pending returns before checking the native local accepted-slot capacity.
    /// Native syscall exhaustion retains its backend-specific retirement policy.
    pub fn can_defer(
        &self,
        driver: &mut life::Lifecycle<'_, impl Report<Event = crate::Reported>>,
    ) -> bool {
        if matches!(self, Self::Capacity { close: Ok(()) }) {
            driver.retire();
            return driver.context().backend.can_accept();
        }
        self.is_resource() && !matches!(Readiness::from(driver.driver_ref()), Readiness::Ready)
    }

    /// Whether capacity recovery permits a later attempt, without proving readiness now.
    pub fn is_resource(&self) -> bool {
        matches!(self, Self::Capacity { close: Ok(()) })
            || matches!(self, Self::Syscall(error) if <crate::Backend as accept::Source>::can_defer(*error))
    }

    pub fn is_retryable(&self) -> bool {
        matches!(self, Self::Syscall(error) if <crate::Backend as accept::Source>::is_retryable(*error))
    }
}

impl From<handles::Reclaimed> for Failure {
    fn from(retired: handles::Reclaimed) -> Self {
        match retired {
            handles::Reclaimed::Queued(slot) => Self::Retired(slot),
            handles::Reclaimed::Quarantined(slot) => Self::Quarantined(slot),
        }
    }
}

impl From<dope_sys::Errno> for Failure {
    fn from(error: dope_sys::Errno) -> Self {
        Self::Syscall(error)
    }
}

impl From<accept::Error> for Failure {
    fn from(error: accept::Error) -> Self {
        match error {
            accept::Error::Syscall(error) => Self::Syscall(error),
            accept::Error::Registration(error) => Self::Registration(error),
            accept::Error::Setup(error) => Self::Setup(error),
            accept::Error::Capacity { close } => Self::Capacity { close },
        }
    }
}