Skip to main content

dope_uring/reactor/sq/
source.rs

1use dope_sys::{
2    engine::admit,
3    io::{
4        reactor::submit::raw::Vacancy as _,
5        request::{Context, Source},
6        socket,
7    },
8    memory::buffer::provided,
9    table::token::{Codec, host},
10};
11
12use crate::{
13    Uring,
14    reactor::{op::sockets, sq},
15};
16
17impl<C: Context> Source<C> for Uring {
18    type Target = sq::Fixed;
19
20    fn target(slot: C::Target) -> sq::Fixed {
21        sq::Fixed::new(slot.into())
22    }
23}
24
25type Slot<C> = <<C as admit::Context>::Inputs as Context>::Target;
26const GROUP: u16 = <Uring as provided::Source>::PROVIDED;
27
28impl<C, T> admit::Guard<C> for sq::raw::Vacancy<'_, T>
29where
30    C: admit::Context<Native = Uring>,
31    T: Codec,
32    T::Context: host::Context<Key = C::Key>,
33{
34    fn socket(self, slot: <C::Inputs as Context>::Outbound, domain: socket::Domain, key: C::Key) {
35        let entry = sq::Entry::socket(sq::Fixed::new(slot.into()), domain);
36        self.push_owned(entry, T::flight(key));
37    }
38
39    fn accept_multi(self, listener: Slot<C>, key: C::Key) {
40        let listener = <Uring as Source<C::Inputs>>::target(listener);
41        self.push_owned(sq::Entry::accept_multi(listener), T::flight(key));
42    }
43
44    fn recv(self, slot: Slot<C>, key: C::Key) {
45        let slot = <Uring as Source<C::Inputs>>::target(slot);
46        self.push_owned(sq::Entry::recv::<GROUP>(slot), T::flight(key));
47    }
48
49    fn recv_msg(self, fd: &<C::Inputs as Context>::Datagram<'_>, key: C::Key) {
50        let slot = <Uring as Source<C::Inputs>>::target(C::Inputs::datagram(fd));
51        self.push_owned(sq::Entry::recv_msg::<GROUP>(slot), T::flight(key));
52    }
53
54    fn shutdown(self, slot: Slot<C>, key: C::Key) {
55        let slot = <Uring as Source<C::Inputs>>::target(slot);
56        self.push_owned(sockets::shutdown(slot, socket::How::WRITE), T::flight(key));
57    }
58}