compio-driver 0.11.4

Low-level driver for compio
Documentation
/// Representing underlying driver type the fusion driver is using
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DriverType {
    /// Using `polling` driver
    Poll,
    /// Using `io-uring` driver
    IoUring,
    /// Using `iocp` driver
    IOCP,
}

impl DriverType {
    /// Get the underlying driver type
    #[cfg(fusion)]
    pub(crate) fn suggest() -> DriverType {
        use io_uring::opcode::*;

        // Add more opcodes here if used
        const USED_OP: &[u8] = &[
            Read::CODE,
            Readv::CODE,
            Write::CODE,
            Writev::CODE,
            Fsync::CODE,
            Accept::CODE,
            Connect::CODE,
            Recv::CODE,
            Send::CODE,
            RecvMsg::CODE,
            SendMsg::CODE,
            PollAdd::CODE,
        ];

        if USED_OP.iter().all(|op| crate::sys::is_op_supported(*op)) {
            DriverType::IoUring
        } else {
            DriverType::Poll
        }
    }

    /// Check if the current driver is `polling`
    pub fn is_polling(&self) -> bool {
        *self == DriverType::Poll
    }

    /// Check if the current driver is `io-uring`
    pub fn is_iouring(&self) -> bool {
        *self == DriverType::IoUring
    }

    /// Check if the current driver is `iocp`
    pub fn is_iocp(&self) -> bool {
        *self == DriverType::IOCP
    }
}