1pub mod change;
2pub mod closed;
3pub mod permit;
4pub mod registry;
5pub mod token;
6use std::{os::fd, task};
7
8use o3::alloc;
9use reclaim::{Kind, View};
10
11use crate::{io::socket, table::change::Index};
12
13pub mod raw;
14pub mod reclaim;
15
16type Interest<T, S> =
17 Result<T, Error<<S as change::raw::Slots>::Index, <S as raw::Slots>::Missing>>;
18
19#[derive(Clone, Copy, Debug, Eq, PartialEq)]
21pub enum Error<I, M> {
22 Missing(M),
23 Index(Index<I>),
24}
25
26pub trait Files<S: raw::Slots>: Sized {
27 type Handle: socket::raw::Open + socket::raw::Receive;
28 type Changes: change::Changes<Slots = S>;
29
30 fn try_new(layout: S::Layout) -> Result<Self, alloc::Error>;
31 fn has_accept_capacity(&self) -> bool;
32 fn establish(&mut self, handle: Self::Handle) -> Result<S::Accepted, Self::Handle>;
33 fn close(&mut self, slot: S::Physical) -> closed::File<S::Missing>;
34 fn install(&mut self, slot: S::Owned, handle: Self::Handle) -> Result<(), Install<S::Index>>;
35 fn raw(&self, slot: S::Physical) -> Option<fd::RawFd>;
36 fn borrow(&self, slot: S::Physical) -> Option<fd::BorrowedFd<'_>>;
37 fn try_socket(
38 &self,
39 id: <Self::Changes as change::Changes>::Id,
40 ) -> Result<&Self::Handle, S::Missing>;
41 fn try_read(
42 &mut self,
43 slot: S::Physical,
44 ) -> Interest<<Self::Changes as change::Changes>::Read<'_>, S>;
45 fn try_write(
46 &mut self,
47 slot: S::Physical,
48 ) -> Interest<<Self::Changes as change::Changes>::Write<'_>, S>;
49 fn read(
50 &mut self,
51 id: <Self::Changes as change::Changes>::Id,
52 ) -> Result<Option<<Self::Changes as change::Changes>::Read<'_>>, change::Index<S::Index>>;
53 fn write(
54 &mut self,
55 id: <Self::Changes as change::Changes>::Id,
56 ) -> Result<Option<<Self::Changes as change::Changes>::Write<'_>>, change::Index<S::Index>>;
57 fn try_delete(
58 &mut self,
59 entries: impl Iterator<Item = (<Self::Changes as change::Changes>::Id, change::Filter)>,
60 ) -> Result<<Self::Changes as change::Changes>::Deletion<'_>, change::Index<S::Index>>;
61 fn changes(&self) -> &Self::Changes;
62 fn edit(&mut self) -> &mut Self::Changes;
63}
64
65#[derive(Clone, Copy, Debug, Eq, PartialEq)]
67#[repr(u8)]
68pub enum Install<S> {
69 Index(S),
70 Occupied(S),
71}
72
73impl<S> From<Install<S>> for crate::kernel::Diagnostic<S> {
74 fn from(error: Install<S>) -> Self {
75 match error {
76 Install::Index(index) => Self::FileIndex(index),
77 Install::Occupied(index) => Self::FileOccupied(index),
78 }
79 }
80}
81
82const _: () = assert!(std::mem::size_of::<Install<u32>>() == 2 * std::mem::size_of::<u32>());
83
84pub trait Retire<'d, V: View> {
86 type Output;
87
88 fn retire<'a>(
89 &'a mut self,
90 pending: Kind<V::Close, V::Retire>,
91 view: V,
92 ) -> task::Poll<Self::Output>
93 where
94 'd: 'a;
95}
96
97pub trait Source {
98 type Files<S: raw::Slots>: Files<S>;
99}