Skip to content

Commit c0700f7

Browse files
committed
Set nonblocking for file when no epoll.
1 parent efb2fca commit c0700f7

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/fs/file.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ fn file_with_options(
4242
#[cfg(not(target_os = "windows"))]
4343
fn file_with_options(
4444
path: impl AsRef<Path>,
45-
options: std::fs::OpenOptions,
45+
mut options: std::fs::OpenOptions,
4646
) -> io::Result<std::fs::File> {
47+
use std::os::unix::prelude::OpenOptionsExt;
48+
49+
// Don't set nonblocking with epoll.
50+
if cfg!(not(any(
51+
target_os = "linux",
52+
target_os = "android",
53+
target_os = "illumos"
54+
))) {
55+
options.custom_flags(libc::O_NONBLOCK);
56+
}
4757
options.open(path)
4858
}
4959

@@ -252,11 +262,10 @@ impl File {
252262
let mut total_written = 0;
253263
let mut written;
254264
while total_written < buf_len {
255-
(written, buffer) = buf_try!(
256-
self.write_at(buffer.slice(total_written..), pos + total_written)
257-
.await
258-
.into_inner()
259-
);
265+
(written, buffer) = buf_try!(self
266+
.write_at(buffer.slice(total_written..), pos + total_written)
267+
.await
268+
.into_inner());
260269
total_written += written;
261270
}
262271
(Ok(total_written), buffer)

src/net/socket.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ impl Socket {
5959
// non blocking socket when there is no connections in listen queue
6060
//
6161
// https://patchwork.kernel.org/project/linux-block/patch/[email protected]/#22949861
62-
#[cfg(all(unix, not(all(target_os = "linux", feature = "io-uring"))))]
63-
socket.set_nonblocking(true)?;
62+
if cfg!(all(
63+
unix,
64+
not(all(target_os = "linux", feature = "io-uring"))
65+
)) {
66+
socket.set_nonblocking(true)?;
67+
}
6468
Ok(Self::from_socket2(socket))
6569
}
6670

0 commit comments

Comments
 (0)