Skip to content

Commit

Permalink
Merge pull request #232 from Berrysoft/fix/poll-file-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
George-Miao committed Mar 27, 2024
2 parents 5e185ba + 735583d commit 68a6827
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 37 deletions.
24 changes: 4 additions & 20 deletions compio-driver/src/poll/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ impl IntoInner for PathStat {

impl<T: IoBufMut> OpCode for ReadAt<T> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
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<io::Result<usize>> {
Expand All @@ -197,11 +193,7 @@ impl<T: IoBufMut> OpCode for ReadAt<T> {

impl<T: IoVectoredBufMut> OpCode for ReadVectoredAt<T> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
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<io::Result<usize>> {
Expand All @@ -222,11 +214,7 @@ impl<T: IoVectoredBufMut> OpCode for ReadVectoredAt<T> {

impl<T: IoBuf> OpCode for WriteAt<T> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
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<io::Result<usize>> {
Expand All @@ -246,11 +234,7 @@ impl<T: IoBuf> OpCode for WriteAt<T> {

impl<T: IoVectoredBuf> OpCode for WriteVectoredAt<T> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
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<io::Result<usize>> {
Expand Down
11 changes: 5 additions & 6 deletions compio-driver/tests/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<O: OpCode + 'static>(driver: &mut Proactor, op: O) -> (usize, O) {
Expand Down
6 changes: 1 addition & 5 deletions compio-fs/src/open_options/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,10 @@ impl OpenOptions {
}

pub async fn open(&self, p: impl AsRef<Path>) -> io::Result<File> {
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;
Expand Down
11 changes: 5 additions & 6 deletions compio/examples/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<O: OpCode + 'static>(driver: &mut Proactor, op: O) -> (usize, O) {
Expand Down

0 comments on commit 68a6827

Please sign in to comment.