Skip to content

Commit 68a6827

Browse files
authored
Merge pull request compio-rs#232 from Berrysoft/fix/poll-file-blocking
2 parents 5e185ba + 735583d commit 68a6827

File tree

4 files changed

+15
-37
lines changed

4 files changed

+15
-37
lines changed

compio-driver/src/poll/op.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,7 @@ impl IntoInner for PathStat {
178178

179179
impl<T: IoBufMut> OpCode for ReadAt<T> {
180180
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
181-
if cfg!(any(target_os = "linux", target_os = "android")) {
182-
Ok(Decision::blocking_readable(self.fd))
183-
} else {
184-
Ok(Decision::wait_readable(self.fd))
185-
}
181+
Ok(Decision::blocking_readable(self.fd))
186182
}
187183

188184
fn on_event(self: Pin<&mut Self>, event: &Event) -> Poll<io::Result<usize>> {
@@ -197,11 +193,7 @@ impl<T: IoBufMut> OpCode for ReadAt<T> {
197193

198194
impl<T: IoVectoredBufMut> OpCode for ReadVectoredAt<T> {
199195
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
200-
if cfg!(any(target_os = "linux", target_os = "android")) {
201-
Ok(Decision::blocking_readable(self.fd))
202-
} else {
203-
Ok(Decision::wait_readable(self.fd))
204-
}
196+
Ok(Decision::blocking_readable(self.fd))
205197
}
206198

207199
fn on_event(self: Pin<&mut Self>, event: &Event) -> Poll<io::Result<usize>> {
@@ -222,11 +214,7 @@ impl<T: IoVectoredBufMut> OpCode for ReadVectoredAt<T> {
222214

223215
impl<T: IoBuf> OpCode for WriteAt<T> {
224216
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
225-
if cfg!(any(target_os = "linux", target_os = "android")) {
226-
Ok(Decision::blocking_writable(self.fd))
227-
} else {
228-
Ok(Decision::wait_writable(self.fd))
229-
}
217+
Ok(Decision::blocking_writable(self.fd))
230218
}
231219

232220
fn on_event(self: Pin<&mut Self>, event: &Event) -> Poll<io::Result<usize>> {
@@ -246,11 +234,7 @@ impl<T: IoBuf> OpCode for WriteAt<T> {
246234

247235
impl<T: IoVectoredBuf> OpCode for WriteVectoredAt<T> {
248236
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
249-
if cfg!(any(target_os = "linux", target_os = "android")) {
250-
Ok(Decision::blocking_writable(self.fd))
251-
} else {
252-
Ok(Decision::wait_writable(self.fd))
253-
}
237+
Ok(Decision::blocking_writable(self.fd))
254238
}
255239

256240
fn on_event(self: Pin<&mut Self>, event: &Event) -> Poll<io::Result<usize>> {

compio-driver/tests/file.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ fn open_file_op() -> impl OpCode {
3131

3232
use compio_driver::op::OpenFile;
3333

34-
let mut flags = libc::O_CLOEXEC | libc::O_RDONLY;
35-
if cfg!(not(any(target_os = "linux", target_os = "android"))) {
36-
flags |= libc::O_NONBLOCK;
37-
}
38-
39-
OpenFile::new(CString::new("Cargo.toml").unwrap(), flags, 0o666)
34+
OpenFile::new(
35+
CString::new("Cargo.toml").unwrap(),
36+
libc::O_CLOEXEC | libc::O_RDONLY,
37+
0o666,
38+
)
4039
}
4140

4241
fn push_and_wait<O: OpCode + 'static>(driver: &mut Proactor, op: O) -> (usize, O) {

compio-fs/src/open_options/unix.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,10 @@ impl OpenOptions {
8181
}
8282

8383
pub async fn open(&self, p: impl AsRef<Path>) -> io::Result<File> {
84-
let mut flags = libc::O_CLOEXEC
84+
let flags = libc::O_CLOEXEC
8585
| self.get_access_mode()?
8686
| self.get_creation_mode()?
8787
| (self.custom_flags as libc::c_int & !libc::O_ACCMODE);
88-
// Don't set nonblocking with epoll.
89-
if cfg!(not(any(target_os = "linux", target_os = "android"))) {
90-
flags |= libc::O_NONBLOCK;
91-
}
9288
let p = path_string(p)?;
9389
let op = OpenFile::new(p, flags, self.mode);
9490
let fd = Runtime::current().submit(op).await.0? as RawFd;

compio/examples/driver.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ fn open_file_op() -> impl OpCode {
3434

3535
use compio::driver::op::OpenFile;
3636

37-
let mut flags = libc::O_CLOEXEC | libc::O_RDONLY;
38-
if cfg!(not(any(target_os = "linux", target_os = "android"))) {
39-
flags |= libc::O_NONBLOCK;
40-
}
41-
42-
OpenFile::new(CString::new("Cargo.toml").unwrap(), flags, 0o666)
37+
OpenFile::new(
38+
CString::new("Cargo.toml").unwrap(),
39+
libc::O_CLOEXEC | libc::O_RDONLY,
40+
0o666,
41+
)
4342
}
4443

4544
fn push_and_wait<O: OpCode + 'static>(driver: &mut Proactor, op: O) -> (usize, O) {

0 commit comments

Comments
 (0)