Skip to main content

dope_sys/ring/
mod.rs

1use crate::memory;
2pub mod create;
3pub mod enter;
4pub mod inspect;
5pub mod layout;
6pub mod map;
7pub mod prepare;
8pub mod ready;
9pub mod register;
10use self::{create::Create, enter::Enter, inspect::Inspect, map::Unmap, prepare::Prepare};
11use crate::{
12    io::{
13        Close,
14        reactor::{
15            complete,
16            complete::{Drain, Entry, message, packet::record},
17            submit,
18        },
19    },
20    kernel,
21    memory::buffer::provided,
22    probe::session::Closed,
23};
24
25/// Native ring ownership specialized to the caller's completion token.
26pub trait Source: kernel::Source + Sized {
27    type Decoded<T: Copy, E>: record::Map<
28            Parts = complete::Parts<
29                T,
30                <Self::Entry<T> as Entry>::Outcome,
31                <Self::Entry<T> as Entry>::Flags,
32            >,
33            Fault = E,
34        >;
35    type Ready<T: complete::raw::Token, L: memory::raw::Receive>: ready::Ready<
36            Ring = Self::Ring<T>,
37            Token = T,
38            Layout = L,
39            Context = <Self as provided::Source>::Context<L>,
40            Producer = <Self as provided::Source>::Producer<L>,
41            Pending = <Self as provided::Source>::Pending<L::Extent>,
42            Index = <Self as provided::Source>::Index,
43            Entry = <Self as Source>::Entry<T>,
44        > + ready::raw::Create
45    where
46        Self: provided::Source;
47    type Poll: Copy + Eq;
48    type Entry<T>: complete::Entry<Token = T, Outcome: complete::Outcome<Returned = Self::Returned>>;
49    type Packet<T: Copy, B>: complete::Packet<
50            Parts = complete::Parts<
51                T,
52                <Self::Entry<T> as complete::Entry>::Outcome,
53                <Self::Entry<T> as complete::Entry>::Flags,
54            >,
55            Buffer = B,
56        >;
57    type Message<'a, const NAME: usize, const CONTROL: usize>: message::Output<'a>;
58    type Enter<'a, T: 'a>: Enter;
59    type Ring<T: complete::raw::Token>: Create
60        + Owner<Token = T>
61        + Prepare
62        + Inspect<Code = Self::Code>
63        + Complete<Entry = Self::Entry<T>>;
64}
65
66/// Exclusive queue and registration views borrow the same native owner.
67pub trait Access {
68    type Token;
69    type Target;
70    type File: register::Occupied<Target = Self::Target>;
71    type Queue<'a>: submit::Queue<'a, Self::Token>
72    where
73        Self: 'a,
74        Self::Token: complete::raw::Token;
75    type Enter<'a>: Enter
76    where
77        Self: 'a;
78    type Registry<'a>: register::Registry<Token = Self::Token, Target = Self::Target, File = Self::File>
79    where
80        Self: 'a;
81
82    fn sq(&mut self) -> Self::Queue<'_>
83    where
84        Self::Token: complete::raw::Token;
85    fn enter(&mut self) -> Self::Enter<'_>;
86    fn registry(&mut self) -> Self::Registry<'_>;
87}
88
89/// Ring registration and failed fixed-file cleanup retain the complete owner.
90pub trait Owner: Access + Close<State: Unmap> + Sized {
91    type Registered: register::Registered<
92            Token = Self::Token,
93            State: map::Unmap<Error = <Self::State as map::Unmap>::Error>,
94        >;
95    type Registration: register::Registration;
96    type Closing: Closed<Target = Self::Target>;
97
98    fn try_register(self) -> Result<Self::Registered, Self::Registration>;
99    fn close_file(self, file: Self::File) -> Result<(), Self::Closing>;
100}
101
102pub trait Complete {
103    type Entry: Entry;
104    type Queue<'a>: Drain<Entry = Self::Entry>
105    where
106        Self: 'a;
107
108    fn completion(&mut self) -> Self::Queue<'_>;
109}