Skip to main content

dope_core/io/socket/install/
error.rs

1use std::num;
2
3use dope_sys::{
4    Errno,
5    io::socket::{Create, Origin, Setup, addr, option},
6};
7
8use crate::{
9    driver::result,
10    io::{
11        socket,
12        socket::install::{Operation, adopt, receive, slot},
13    },
14};
15
16/// Exact bootstrap failure with typed validation and numeric OS causes.
17#[derive(PartialEq, Eq, Debug)]
18pub enum Error {
19    Slot(slot::Error),
20    Receive(receive::Error),
21    Adopt(adopt::Error),
22    Listening(<crate::Backend as option::Source>::Listening),
23    FastOpen(num::NonZero<i32>),
24    Address(socket::Error),
25    LocalAddress(addr::Local<Errno>),
26    Setup(Setup),
27    System {
28        operation: Operation,
29        fault: crate::Errno,
30    },
31    Kernel {
32        operation: Operation,
33        cause: result::Kernel,
34    },
35}
36
37impl Error {
38    pub(crate) fn create(error: Create) -> Self {
39        match error.origin() {
40            Origin::Socket(errno) => Self::syscall(Operation::Socket, errno),
41            Origin::Setup(error) => Self::Setup(error),
42        }
43    }
44
45    pub(crate) const fn validate(fault: dope_sys::Errno) -> Self {
46        Self::syscall(Operation::Validate, fault)
47    }
48
49    pub(crate) fn reuse((reuse, errno): (socket::Reuse, dope_sys::Errno)) -> Self {
50        let op = match reuse {
51            socket::Reuse::Address => Operation::ReuseAddress,
52            socket::Reuse::Port => Operation::ReusePort,
53        };
54        Self::syscall(op, errno)
55    }
56
57    pub(crate) const fn syscall(op: Operation, fault: dope_sys::Errno) -> Self {
58        Self::System {
59            operation: op,
60            fault,
61        }
62    }
63
64    pub(crate) const fn kernel(op: Operation, cause: result::Kernel) -> Self {
65        Self::Kernel {
66            operation: op,
67            cause,
68        }
69    }
70}