compio_driver/
driver_type.rs

1/// Representing underlying driver type the fusion driver is using
2#[repr(u8)]
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub enum DriverType {
5    /// Using `polling` driver
6    Poll,
7    /// Using `io-uring` driver
8    IoUring,
9    /// Using `iocp` driver
10    IOCP,
11}
12
13impl DriverType {
14    /// Get the underlying driver type
15    #[cfg(fusion)]
16    pub(crate) fn suggest() -> DriverType {
17        use io_uring::opcode::*;
18
19        // Add more opcodes here if used
20        const USED_OP: &[u8] = &[
21            Read::CODE,
22            Readv::CODE,
23            Write::CODE,
24            Writev::CODE,
25            Fsync::CODE,
26            Accept::CODE,
27            Connect::CODE,
28            RecvMsg::CODE,
29            SendMsg::CODE,
30            AsyncCancel::CODE,
31            OpenAt::CODE,
32            Close::CODE,
33            Shutdown::CODE,
34        ];
35
36        if USED_OP.iter().all(|op| crate::sys::is_op_supported(*op)) {
37            DriverType::IoUring
38        } else {
39            DriverType::Poll
40        }
41    }
42
43    /// Check if the current driver is `polling`
44    pub fn is_polling(&self) -> bool {
45        *self == DriverType::Poll
46    }
47
48    /// Check if the current driver is `io-uring`
49    pub fn is_iouring(&self) -> bool {
50        *self == DriverType::IoUring
51    }
52
53    /// Check if the current driver is `iocp`
54    pub fn is_iocp(&self) -> bool {
55        *self == DriverType::IOCP
56    }
57}