use dope_sys::{
engine::admit,
io::{
reactor::submit::raw::Vacancy as _,
request::{Context, Source},
socket,
},
memory::buffer::provided,
table::token::{Codec, host},
};
use crate::{
Uring,
reactor::{op::sockets, sq},
};
impl<C: Context> Source<C> for Uring {
type Target = sq::Fixed;
fn target(slot: C::Target) -> sq::Fixed {
sq::Fixed::new(slot.into())
}
}
type Slot<C> = <<C as admit::Context>::Inputs as Context>::Target;
const GROUP: u16 = <Uring as provided::Source>::PROVIDED;
impl<C, T> admit::Guard<C> for sq::raw::Vacancy<'_, T>
where
C: admit::Context<Native = Uring>,
T: Codec,
T::Context: host::Context<Key = C::Key>,
{
fn socket(self, slot: <C::Inputs as Context>::Outbound, domain: socket::Domain, key: C::Key) {
let entry = sq::Entry::socket(sq::Fixed::new(slot.into()), domain);
self.push_owned(entry, T::flight(key));
}
fn accept_multi(self, listener: Slot<C>, key: C::Key) {
let listener = <Uring as Source<C::Inputs>>::target(listener);
self.push_owned(sq::Entry::accept_multi(listener), T::flight(key));
}
fn recv(self, slot: Slot<C>, key: C::Key) {
let slot = <Uring as Source<C::Inputs>>::target(slot);
self.push_owned(sq::Entry::recv::<GROUP>(slot), T::flight(key));
}
fn recv_msg(self, fd: &<C::Inputs as Context>::Datagram<'_>, key: C::Key) {
let slot = <Uring as Source<C::Inputs>>::target(C::Inputs::datagram(fd));
self.push_owned(sq::Entry::recv_msg::<GROUP>(slot), T::flight(key));
}
fn shutdown(self, slot: Slot<C>, key: C::Key) {
let slot = <Uring as Source<C::Inputs>>::target(slot);
self.push_owned(sockets::shutdown(slot, socket::How::WRITE), T::flight(key));
}
}