use crate::{
driver,
driver::{life::native::request, retained::flight, route, route::kind},
io::{fd::handles::Descriptor, socket::pending},
};
pub enum Query<'d> {
Ready(Descriptor<'d>, Option<u32>),
Pending(pending::Tuning<'d, u32>),
}
impl<'d> Query<'d> {
pub fn try_new<Tag: route::Tag + route::Select<kind::Tuning>>(
driver: &mut driver::Local<'d>,
_slots: &flight::Slots<'d, Tag>,
_target: route::Target<'d, Tag>,
fd: Descriptor<'d>,
) -> Result<Self, pending::Rejection<'d>> {
#[cfg(target_os = "linux")]
{
match unsafe { request::peer(driver, _slots, _target.operation::<kind::Tuning>(), &fd) }
{
Ok(flight) => Ok(Self::Pending(pending::Tuning::new(fd, flight, ()))),
Err(cause) => Err(pending::Rejection::new(fd, cause)),
}
}
#[cfg(target_os = "macos")]
{
match request::peer(driver, &fd) {
Ok(value) => Ok(Self::Ready(fd, uid(value))),
Err(cause) => Err(pending::Rejection::new(fd, pending::Cause::Option(cause))),
}
}
}
}
pub(super) fn uid(value: u32) -> Option<u32> {
(value != u32::MAX).then_some(value)
}