Skip to content

Commit

Permalink
feat: determine driver type at compile time if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Dec 2, 2024
1 parent 79d4d33 commit 7d8b69e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion compio-fs/src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ async fn is_fifo(file: &File) -> io::Result<bool> {

/// 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;
Expand Down
8 changes: 6 additions & 2 deletions compio-net/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/#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)?;
}
}
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion compio-signal/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl SignalFd {
fn new(sig: i32) -> io::Result<Self> {
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))?;
Expand Down

0 comments on commit 7d8b69e

Please sign in to comment.