1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/// 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
}
}