From 7d8b69e39ec3c096c50697b01488eb83e2238a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Mon, 2 Dec 2024 20:54:46 +0900 Subject: [PATCH] feat: determine driver type at compile time if possible --- compio-fs/src/pipe.rs | 4 +++- compio-net/src/socket.rs | 8 ++++++-- compio-signal/src/linux.rs | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/compio-fs/src/pipe.rs b/compio-fs/src/pipe.rs index d609a81e..af256b0c 100644 --- a/compio-fs/src/pipe.rs +++ b/compio-fs/src/pipe.rs @@ -513,7 +513,9 @@ async fn is_fifo(file: &File) -> io::Result { /// Sets file's flags with O_NONBLOCK by fcntl. fn set_nonblocking(file: &impl AsRawFd) -> io::Result<()> { - if compio_driver::DriverType::is_polling() { + if cfg!(not(all(target_os = "linux", feature = "io-uring"))) + || compio_driver::DriverType::is_polling() + { let fd = file.as_raw_fd(); let current_flags = syscall!(libc::fcntl(fd, libc::F_GETFL))?; let flags = current_flags | libc::O_NONBLOCK; diff --git a/compio-net/src/socket.rs b/compio-net/src/socket.rs index 5d4a3262..3975de9c 100644 --- a/compio-net/src/socket.rs +++ b/compio-net/src/socket.rs @@ -56,7 +56,9 @@ impl Socket { // non blocking socket when there is no connections in listen queue // // https://patchwork.kernel.org/project/linux-block/patch/f999615b-205c-49b7-b272-c4e42e45e09d@kernel.dk/#22949861 - if compio_driver::DriverType::is_polling() { + if cfg!(not(all(target_os = "linux", feature = "io-uring"))) + || compio_driver::DriverType::is_polling() + { socket.set_nonblocking(true)?; } } @@ -161,7 +163,9 @@ impl Socket { let BufResult(res, op) = compio_runtime::submit(op).await; let addr = op.into_addr(); let accept_sock = unsafe { Socket2::from_raw_fd(res? as _) }; - if compio_driver::DriverType::is_polling() { + if cfg!(not(all(target_os = "linux", feature = "io-uring"))) + || compio_driver::DriverType::is_polling() + { accept_sock.set_nonblocking(true)?; } let accept_sock = Self::from_socket2(accept_sock)?; diff --git a/compio-signal/src/linux.rs b/compio-signal/src/linux.rs index de277f25..1b7eb369 100644 --- a/compio-signal/src/linux.rs +++ b/compio-signal/src/linux.rs @@ -57,7 +57,7 @@ impl SignalFd { fn new(sig: i32) -> io::Result { let set = register_signal(sig)?; let mut flag = libc::SFD_CLOEXEC; - if compio_driver::DriverType::is_polling() { + if cfg!(not(feature = "io-uring")) || compio_driver::DriverType::is_polling() { flag |= libc::SFD_NONBLOCK; } let fd = syscall!(libc::signalfd(-1, &set, flag))?;