dope_sys/ring/ready/
mod.rs1use crate::{memory, ring::map};
2mod error;
3pub mod raw;
4use std::{os::fd, time};
5
6pub use error::Error;
7use o3::base::num::bounded;
8
9use crate::{
10 io::{
11 Close,
12 reactor::{complete, submit},
13 },
14 memory::{buffer, buffer::provided},
15 ring::{
16 enter,
17 enter::{Enter, Poll},
18 },
19};
20
21type Completion<R> = (
22 <R as Complete>::Entry,
23 Option<Result<<R as Complete>::Pending, <R as Complete>::Index>>,
24);
25type Failure<R> = Poll<<R as Ready>::Error, <R as Ready>::CancelError>;
26
27pub trait Complete: Sized {
29 type Token: complete::raw::Token;
30 type Layout: memory::raw::Receive;
31 type Pending: buffer::raw::Token<Index = Self::Index>
32 + buffer::raw::Pending<
33 Extent = <Self::Layout as memory::raw::Receive>::Extent,
34 Complete: buffer::raw::Token<
35 Index = Self::Index,
36 Length = <<Self::Layout as memory::raw::Receive>::Extent as memory::raw::Extent>::Length,
37 >,
38 >;
39 type Index: Copy;
40 type Entry: complete::Entry<Token = Self::Token>;
41
42 fn acquire(&mut self);
43 fn publish(&mut self);
45 fn pop(&mut self) -> Option<Completion<Self>>;
46 fn refresh(&mut self) -> bounded::U32<0, { u32::MAX }>;
47 fn layout(&self) -> Self::Layout;
48 fn flush(&mut self);
49}
50
51pub trait Ready: Complete + Close<State: map::Unmap> + Sized {
53 type Ring;
54 type Context: provided::Context;
55 type Producer: provided::Producer<Layout = Self::Layout, Context = Self::Context>;
56 type Registration;
57 type Registered;
58 type BufferError;
59 type Error;
60 type InstallError;
61 type CancelError;
62 type Target;
63 type Queue<'q>: submit::Queue<'q, Self::Token>
64 where
65 Self: 'q;
66 type Enter<'q>: Enter<Error = Self::Error>
67 where
68 Self: 'q;
69
70 fn submission(&mut self) -> Self::Queue<'_>;
71 fn enter(&mut self) -> Self::Enter<'_>;
72
73 fn submit(&mut self) -> Result<(), Failure<Self>>;
74 fn commit(&mut self) -> Result<(), Failure<Self>>;
75 fn advance(&mut self) -> Result<enter::Progress, Failure<Self>>;
76 fn try_wait(&mut self, timeout: Option<time::Duration>) -> Result<(), Failure<Self>>;
77
78 fn install(
79 &mut self,
80 target: Self::Target,
81 file: fd::BorrowedFd<'_>,
82 ) -> Result<(), Self::InstallError>;
83 fn cancel_all(&mut self) -> Result<(), Failure<Self>>;
84}