Skip to main content

dope_core/driver/result/poll/
mod.rs

1use std::{mem, os::fd, task};
2
3use dope_sys::table::change;
4
5use crate::driver::route::{indices, table::bounds};
6
7mod cause;
8mod dispatch;
9mod error;
10pub mod fault;
11
12pub use cause::Cause;
13pub use dispatch::Dispatch;
14pub use error::Error;
15
16/// Exact reactor operation that failed on a readiness-queue backend.
17#[derive(Clone, Copy, Eq, PartialEq, Debug)]
18pub enum Operation {
19    Wait,
20    Changes,
21    Accept,
22    Connect,
23    SocketError,
24    Recv,
25    RecvMsg,
26    Send,
27    Shutdown,
28    FileOpen,
29    FileWrite,
30    FileSync,
31    FileRename,
32    FileUnlink,
33}
34
35/// Exact descriptor-table absence observed by a readiness backend.
36#[derive(Clone, Copy, Eq, PartialEq, Debug)]
37#[repr(u8)]
38pub enum Missing {
39    Bounds(bounds::Excluded),
40    Backing {
41        index: indices::SlotIndex,
42    },
43    Vacant {
44        index: indices::SlotIndex,
45    },
46    Replaced {
47        index: indices::SlotIndex,
48        expected: fd::RawFd,
49        actual: fd::RawFd,
50    },
51}
52
53#[derive(Clone, Copy, Eq, PartialEq, Debug)]
54#[must_use = "pending backend events must be drained before blocking"]
55pub enum Drain {
56    /// The backend's visible event queue was empty after synchronization.
57    Drained,
58    /// Visible events remain and require another reactor turn.
59    Pending,
60}
61
62impl From<task::Poll<()>> for Drain {
63    fn from(state: task::Poll<()>) -> Self {
64        match state {
65            task::Poll::Ready(()) => Self::Drained,
66            task::Poll::Pending => Self::Pending,
67        }
68    }
69}
70
71/// Backend publication progress, not completion of submitted I/O.
72#[derive(Clone, Copy, Eq, PartialEq)]
73#[must_use = "pending backend changes must be committed in a later reactor turn"]
74pub enum Commit {
75    /// Every change queued before this call has reached the backend.
76    Drained,
77    /// Queued changes remain and require another reactor turn.
78    Pending,
79}
80
81const _: () = {
82    assert!(mem::size_of::<Missing>() == 4 * mem::size_of::<u32>());
83    assert!(mem::align_of::<Missing>() == mem::align_of::<u32>());
84    assert!(mem::size_of::<Operation>() == 1);
85    assert!(core::mem::size_of::<Result<(), Error>>() == core::mem::size_of::<Error>());
86    assert!(core::mem::size_of::<Result<Commit, Error>>() == core::mem::size_of::<Error>());
87};
88
89/// Descriptor retirement distinguishes missing ownership from the exact close result.
90#[derive(Clone, Copy, Debug, Eq, PartialEq)]
91pub enum Close {
92    Missing(Missing),
93    Closed(Result<(), crate::Errno>),
94}
95
96/// Descriptor readiness direction whose native change could not be committed.
97#[derive(Clone, Copy, Debug, Eq, PartialEq)]
98#[repr(u8)]
99pub enum Filter {
100    Read,
101    Write,
102}
103
104impl Filter {
105    pub(crate) const fn from_native(filter: change::Filter) -> Self {
106        use dope_sys::table::change::Filter;
107        match filter {
108            Filter::Read => Self::Read,
109            Filter::Write => Self::Write,
110        }
111    }
112}