pub(crate) mod sealed {
use super::{Fd, Fixed};
use std::os::unix::io::RawFd;
#[derive(Debug)]
pub enum Target {
Fd(RawFd),
Fixed(u32),
}
pub trait UseFd: Sized {
fn into(self) -> RawFd;
}
pub trait UseFixed: Sized {
fn into(self) -> Target;
}
impl UseFd for Fd {
#[inline]
fn into(self) -> RawFd {
self.0
}
}
impl UseFixed for Fd {
#[inline]
fn into(self) -> Target {
Target::Fd(self.0)
}
}
impl UseFixed for Fixed {
#[inline]
fn into(self) -> Target {
Target::Fixed(self.0)
}
}
}
use crate::sys;
use bitflags::bitflags;
use std::os::unix::io::RawFd;
use std::marker::PhantomData;
use crate::util::cast_ptr;
pub use sys::__kernel_rwf_t as RwFlags;
#[repr(C)]
pub struct statx {
_priv: (),
}
#[repr(C)]
pub struct epoll_event {
_priv: (),
}
#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
pub struct Fd(pub RawFd);
#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
pub struct Fixed(pub u32);
bitflags! {
pub struct TimeoutFlags: u32 {
const ABS = sys::IORING_TIMEOUT_ABS;
const UPDATE = sys::IORING_TIMEOUT_UPDATE;
}
}
bitflags! {
pub struct FsyncFlags: u32 {
const DATASYNC = sys::IORING_FSYNC_DATASYNC;
}
}
#[derive(Default, Debug, Clone, Copy)]
#[repr(transparent)]
pub struct OpenHow(sys::open_how);
impl OpenHow {
pub const fn new() -> Self {
OpenHow(sys::open_how {
flags: 0,
mode: 0,
resolve: 0,
})
}
pub const fn flags(mut self, flags: u64) -> Self {
self.0.flags = flags;
self
}
pub const fn mode(mut self, mode: u64) -> Self {
self.0.mode = mode;
self
}
pub const fn resolve(mut self, resolve: u64) -> Self {
self.0.resolve = resolve;
self
}
}
#[derive(Default, Debug, Clone, Copy)]
#[repr(transparent)]
pub struct Timespec(sys::__kernel_timespec);
impl Timespec {
#[inline]
pub const fn new() -> Self {
Timespec(sys::__kernel_timespec {
tv_sec: 0,
tv_nsec: 0,
})
}
#[inline]
pub const fn sec(mut self, sec: u64) -> Self {
self.0.tv_sec = sec as _;
self
}
#[inline]
pub const fn nsec(mut self, nsec: u32) -> Self {
self.0.tv_nsec = nsec as _;
self
}
}
#[derive(Default, Debug, Clone, Copy)]
pub struct SubmitArgs<'prev: 'now, 'now> {
pub(crate) args: sys::io_uring_getevents_arg,
prev: PhantomData<&'prev ()>,
now: PhantomData<&'now ()>,
}
impl<'prev, 'now> SubmitArgs<'prev, 'now> {
#[inline]
pub const fn new() -> SubmitArgs<'static, 'static> {
let args = sys::io_uring_getevents_arg {
sigmask: 0,
sigmask_sz: 0,
pad: 0,
ts: 0,
};
SubmitArgs {
args,
prev: PhantomData,
now: PhantomData,
}
}
#[inline]
pub fn sigmask<'new>(mut self, sigmask: &'new libc::sigset_t) -> SubmitArgs<'now, 'new> {
self.args.sigmask = cast_ptr(sigmask) as _;
self.args.sigmask_sz = std::mem::size_of::<libc::sigset_t>() as _;
SubmitArgs {
args: self.args,
prev: self.now,
now: PhantomData,
}
}
#[inline]
pub fn timespec<'new>(mut self, timespec: &'new Timespec) -> SubmitArgs<'now, 'new> {
self.args.ts = cast_ptr(timespec) as _;
SubmitArgs {
args: self.args,
prev: self.now,
now: PhantomData,
}
}
}
#[repr(transparent)]
pub struct BufRingEntry(sys::io_uring_buf);
impl BufRingEntry {
pub fn set_addr(&mut self, addr: u64) {
self.0.addr = addr;
}
pub fn addr(&self) -> u64 {
self.0.addr
}
pub fn set_len(&mut self, len: u32) {
self.0.len = len;
}
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> u32 {
self.0.len
}
pub fn set_bid(&mut self, bid: u16) {
self.0.bid = bid;
}
pub fn bid(&self) -> u16 {
self.0.bid
}
pub unsafe fn tail(ring_base: *const BufRingEntry) -> *const u16 {
&(*ring_base).0.resv
}
}