From 735583d5e87859b6142fa8f0a17157bfb3d6fa47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Wed, 27 Mar 2024 10:32:57 +0800 Subject: [PATCH] fix(driver,poll): use blocking file io --- compio-driver/src/poll/op.rs | 24 ++++-------------------- compio-driver/tests/file.rs | 11 +++++------ compio-fs/src/open_options/unix.rs | 6 +----- compio/examples/driver.rs | 11 +++++------ 4 files changed, 15 insertions(+), 37 deletions(-) diff --git a/compio-driver/src/poll/op.rs b/compio-driver/src/poll/op.rs index 1268d8aa..b6d5e625 100644 --- a/compio-driver/src/poll/op.rs +++ b/compio-driver/src/poll/op.rs @@ -178,11 +178,7 @@ impl IntoInner for PathStat { impl OpCode for ReadAt { fn pre_submit(self: Pin<&mut Self>) -> io::Result { - if cfg!(any(target_os = "linux", target_os = "android")) { - Ok(Decision::blocking_readable(self.fd)) - } else { - Ok(Decision::wait_readable(self.fd)) - } + Ok(Decision::blocking_readable(self.fd)) } fn on_event(self: Pin<&mut Self>, event: &Event) -> Poll> { @@ -197,11 +193,7 @@ impl OpCode for ReadAt { impl OpCode for ReadVectoredAt { fn pre_submit(self: Pin<&mut Self>) -> io::Result { - if cfg!(any(target_os = "linux", target_os = "android")) { - Ok(Decision::blocking_readable(self.fd)) - } else { - Ok(Decision::wait_readable(self.fd)) - } + Ok(Decision::blocking_readable(self.fd)) } fn on_event(self: Pin<&mut Self>, event: &Event) -> Poll> { @@ -222,11 +214,7 @@ impl OpCode for ReadVectoredAt { impl OpCode for WriteAt { fn pre_submit(self: Pin<&mut Self>) -> io::Result { - if cfg!(any(target_os = "linux", target_os = "android")) { - Ok(Decision::blocking_writable(self.fd)) - } else { - Ok(Decision::wait_writable(self.fd)) - } + Ok(Decision::blocking_writable(self.fd)) } fn on_event(self: Pin<&mut Self>, event: &Event) -> Poll> { @@ -246,11 +234,7 @@ impl OpCode for WriteAt { impl OpCode for WriteVectoredAt { fn pre_submit(self: Pin<&mut Self>) -> io::Result { - if cfg!(any(target_os = "linux", target_os = "android")) { - Ok(Decision::blocking_writable(self.fd)) - } else { - Ok(Decision::wait_writable(self.fd)) - } + Ok(Decision::blocking_writable(self.fd)) } fn on_event(self: Pin<&mut Self>, event: &Event) -> Poll> { diff --git a/compio-driver/tests/file.rs b/compio-driver/tests/file.rs index cec63929..0c8b8657 100644 --- a/compio-driver/tests/file.rs +++ b/compio-driver/tests/file.rs @@ -31,12 +31,11 @@ fn open_file_op() -> impl OpCode { use compio_driver::op::OpenFile; - let mut flags = libc::O_CLOEXEC | libc::O_RDONLY; - if cfg!(not(any(target_os = "linux", target_os = "android"))) { - flags |= libc::O_NONBLOCK; - } - - OpenFile::new(CString::new("Cargo.toml").unwrap(), flags, 0o666) + OpenFile::new( + CString::new("Cargo.toml").unwrap(), + libc::O_CLOEXEC | libc::O_RDONLY, + 0o666, + ) } fn push_and_wait(driver: &mut Proactor, op: O) -> (usize, O) { diff --git a/compio-fs/src/open_options/unix.rs b/compio-fs/src/open_options/unix.rs index a544653c..c1df20c9 100644 --- a/compio-fs/src/open_options/unix.rs +++ b/compio-fs/src/open_options/unix.rs @@ -81,14 +81,10 @@ impl OpenOptions { } pub async fn open(&self, p: impl AsRef) -> io::Result { - let mut flags = libc::O_CLOEXEC + let flags = libc::O_CLOEXEC | self.get_access_mode()? | self.get_creation_mode()? | (self.custom_flags as libc::c_int & !libc::O_ACCMODE); - // Don't set nonblocking with epoll. - if cfg!(not(any(target_os = "linux", target_os = "android"))) { - flags |= libc::O_NONBLOCK; - } let p = path_string(p)?; let op = OpenFile::new(p, flags, self.mode); let fd = Runtime::current().submit(op).await.0? as RawFd; diff --git a/compio/examples/driver.rs b/compio/examples/driver.rs index 404111e0..93335abf 100644 --- a/compio/examples/driver.rs +++ b/compio/examples/driver.rs @@ -34,12 +34,11 @@ fn open_file_op() -> impl OpCode { use compio::driver::op::OpenFile; - let mut flags = libc::O_CLOEXEC | libc::O_RDONLY; - if cfg!(not(any(target_os = "linux", target_os = "android"))) { - flags |= libc::O_NONBLOCK; - } - - OpenFile::new(CString::new("Cargo.toml").unwrap(), flags, 0o666) + OpenFile::new( + CString::new("Cargo.toml").unwrap(), + libc::O_CLOEXEC | libc::O_RDONLY, + 0o666, + ) } fn push_and_wait(driver: &mut Proactor, op: O) -> (usize, O) {