Skip to main content

dope_sys/table/
mod.rs

1pub mod change;
2mod slots;
3pub use slots::Slots;
4pub mod closed;
5pub mod permit;
6pub mod registry;
7pub mod token;
8use std::{os::fd, task};
9
10use o3::alloc;
11use reclaim::{Kind, View};
12
13use crate::{
14    io::{reactor::event, socket},
15    table::change::Index,
16};
17
18pub mod raw;
19pub mod reclaim;
20
21type Interest<T, S> =
22    Result<T, Error<<S as change::raw::Slots>::Index, <S as raw::Slots>::Missing>>;
23
24/// Exact table or changelist absence while acquiring a descriptor interest.
25#[derive(Clone, Copy, Debug, Eq, PartialEq)]
26pub enum Error<I, M> {
27    Missing(M),
28    Index(Index<I>),
29}
30
31pub trait Files<S: raw::Slots>: Sized {
32    type Handle: socket::raw::Open + socket::raw::Receive;
33    type Changes: change::Changes<Slots = S>;
34
35    fn try_new(layout: S::Layout) -> Result<Self, alloc::Error>;
36    fn can_accept(&self) -> bool;
37    fn establish(&mut self, handle: Self::Handle) -> Result<S::Accepted, Self::Handle>;
38    fn close(&mut self, slot: S::Physical) -> closed::File<S::Missing>;
39    fn install(&mut self, slot: S::Owned, handle: Self::Handle) -> Result<(), Install<S::Index>>;
40    fn raw(&self, slot: S::Physical) -> Option<fd::RawFd>;
41    fn borrow(&self, slot: S::Physical) -> Option<fd::BorrowedFd<'_>>;
42    fn try_socket(
43        &self,
44        id: <Self::Changes as change::Changes>::Id,
45    ) -> Result<&Self::Handle, S::Missing>;
46    fn try_read(
47        &mut self,
48        slot: S::Physical,
49    ) -> Interest<<Self::Changes as change::Changes>::Read<'_>, S>;
50    fn try_write(
51        &mut self,
52        slot: S::Physical,
53    ) -> Interest<<Self::Changes as change::Changes>::Write<'_>, S>;
54    fn read(
55        &mut self,
56        id: <Self::Changes as change::Changes>::Id,
57    ) -> Result<Option<<Self::Changes as change::Changes>::Read<'_>>, change::Index<S::Index>>;
58    fn write(
59        &mut self,
60        id: <Self::Changes as change::Changes>::Id,
61    ) -> Result<Option<<Self::Changes as change::Changes>::Write<'_>>, change::Index<S::Index>>;
62    fn try_delete(
63        &mut self,
64        entries: impl Iterator<Item = (<Self::Changes as change::Changes>::Id, change::Filter)>,
65    ) -> Result<<Self::Changes as change::Changes>::Deletion<'_>, change::Index<S::Index>>;
66    fn changes(&self) -> &Self::Changes;
67    fn edit(&mut self) -> &mut Self::Changes;
68}
69
70/// Exact in-memory descriptor installation failure.
71#[derive(Clone, Copy, Debug, Eq, PartialEq)]
72#[repr(u8)]
73pub enum Install<S> {
74    Index(S),
75    Occupied(S),
76}
77
78impl<S> From<Install<S>> for crate::kernel::Diagnostic<S> {
79    fn from(error: Install<S>) -> Self {
80        match error {
81            Install::Index(index) => Self::FileIndex(index),
82            Install::Occupied(index) => Self::FileOccupied(index),
83        }
84    }
85}
86
87const _: () = assert!(std::mem::size_of::<Install<u32>>() == 2 * std::mem::size_of::<u32>());
88
89/// Retires one affine descriptor transaction before advancing its host domain.
90pub trait Retire<'d, V: View> {
91    type Output: IntoIterator;
92
93    fn retire<'a>(
94        &'a mut self,
95        pending: Kind<V::Close, V::Retire>,
96        view: V,
97    ) -> task::Poll<Self::Output>
98    where
99        'd: 'a;
100
101    fn submit<'a, P, R>(&'a mut self, pending: P, view: V, report: &mut R) -> task::Poll<()>
102    where
103        'd: 'a,
104        P: Into<Kind<V::Close, V::Retire>>,
105        R: event::Report,
106        R::Event: From<<Self::Output as IntoIterator>::Item>,
107    {
108        match self.retire(pending.into(), view) {
109            task::Poll::Ready(done) => {
110                for event in done.into_iter().map(R::Event::from) {
111                    report.report(event);
112                }
113                task::Poll::Ready(())
114            }
115            task::Poll::Pending => task::Poll::Pending,
116        }
117    }
118
119    fn drain<'a, R>(
120        &'a mut self,
121        view: V,
122        mut pending: Option<<V as reclaim::Queue>::Pending>,
123        report: &mut R,
124    ) where
125        'd: 'a,
126        V: reclaim::Queue,
127        R: event::Report,
128        R::Event: From<<Self::Output as IntoIterator>::Item>,
129    {
130        while let Some(entry) = pending {
131            if self.submit(entry, view, report).is_pending() {
132                break;
133            }
134            pending = view.pending();
135        }
136    }
137}
138
139pub trait Source {
140    type Files<S: raw::Slots>: Files<S>;
141}