dope-core 0.77.0

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

use dope_sys::{
    Errno,
    io::socket::{Create, Origin, Setup, addr, option},
};

use crate::{
    driver::result,
    io::{
        socket,
        socket::install::{Operation, adopt, receive, slot},
    },
};

/// Exact bootstrap failure with typed validation and numeric OS causes.
#[derive(PartialEq, Eq, Debug)]
pub enum Error {
    Slot(slot::Error),
    Receive(receive::Error),
    Adopt(adopt::Error),
    Listening(<crate::Backend as option::Source>::Listening),
    FastOpen(num::NonZero<i32>),
    Address(addr::Error),
    LocalAddress(addr::Local<Errno>),
    Setup(Setup),
    System {
        operation: Operation,
        fault: crate::Errno,
    },
    Kernel {
        operation: Operation,
        cause: result::Kernel,
    },
}

impl From<addr::Error> for Error {
    fn from(error: addr::Error) -> Self {
        Self::Address(error)
    }
}

impl Error {
    pub(crate) fn create(error: Create) -> Self {
        match error.origin() {
            Origin::Socket(errno) => Self::syscall(Operation::Socket, errno),
            Origin::Setup(error) => Self::Setup(error),
        }
    }

    pub(crate) const fn validate(fault: dope_sys::Errno) -> Self {
        Self::syscall(Operation::Validate, fault)
    }

    pub(crate) fn reuse((reuse, errno): (socket::Reuse, dope_sys::Errno)) -> Self {
        let op = match reuse {
            socket::Reuse::Address => Operation::ReuseAddress,
            socket::Reuse::Port => Operation::ReusePort,
        };
        Self::syscall(op, errno)
    }

    pub(crate) const fn syscall(op: Operation, fault: dope_sys::Errno) -> Self {
        Self::System {
            operation: op,
            fault,
        }
    }

    pub(crate) const fn kernel(op: Operation, cause: result::Kernel) -> Self {
        Self::Kernel {
            operation: op,
            cause,
        }
    }
}