use super::Op;
use crate::future::Future;
pub struct Poll {
fd: lx::RawFd,
event_mask: i16,
}
unsafe impl Op for Poll {
type Output = lx::Result<i16>;
fn fill_sqe(&mut self, sqe: &mut lx::io_uring_sqe) {
sqe.opcode = lx::IORING_OP_POLL_ADD;
sqe.fd = self.fd;
sqe.op_flags = self.event_mask as u32;
}
fn complete(self, ret: i32) -> Self::Output {
if let Ok(err) = lx::Error::try_from(ret) {
Err(err)
} else if let Ok(event_mask) = i16::try_from(ret) {
Ok(event_mask)
} else {
Err(lx::Error::from_code(lx::EINVAL))
}
}
}
pub fn poll(fd: &impl lx::AsRawFd, event_mask: i16) -> Future<Poll> {
Future::new(Poll {
fd: fd.as_raw_fd(),
event_mask,
})
}