File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ harness = false
2020
2121[dependencies ]
2222async-lock = " 2.6"
23+ cfg-if = " 1"
2324concurrent-queue = " 2"
2425futures-lite = " 1.11.0"
2526log = " 0.4.11"
Original file line number Diff line number Diff line change @@ -636,8 +636,23 @@ impl<T: AsRawFd> Async<T> {
636636 // depend on Rust >= 1.63, where `AsFd` is stabilized, and when
637637 // `TimerFd` implements it, we can remove this unsafe and simplify this.
638638 let fd = unsafe { rustix:: fd:: BorrowedFd :: borrow_raw ( raw) } ;
639- let flags = rustix:: fs:: fcntl_getfl ( fd) ?;
640- rustix:: fs:: fcntl_setfl ( fd, flags | rustix:: fs:: OFlags :: NONBLOCK ) ?;
639+ cfg_if:: cfg_if! {
640+ // ioctl(FIONBIO) sets the flag atomically, but we use this only on Linux
641+ // for now, as with the standard library, because it seems to behave
642+ // differently depending on the platform.
643+ // https://github.com/rust-lang/rust/commit/efeb42be2837842d1beb47b51bb693c7474aba3d
644+ // https://github.com/libuv/libuv/blob/e9d91fccfc3e5ff772d5da90e1c4a24061198ca0/src/unix/poll.c#L78-L80
645+ // https://github.com/tokio-rs/mio/commit/0db49f6d5caf54b12176821363d154384357e70a
646+ if #[ cfg( target_os = "linux" ) ] {
647+ rustix:: io:: ioctl_fionbio( fd, true ) ?;
648+ } else {
649+ let previous = rustix:: fs:: fcntl_getfl( fd) ?;
650+ let new = previous | rustix:: fs:: OFlags :: NONBLOCK ;
651+ if new != previous {
652+ rustix:: fs:: fcntl_setfl( fd, new) ?;
653+ }
654+ }
655+ }
641656
642657 Ok ( Async {
643658 source : Reactor :: get ( ) . insert_io ( raw) ?,
You can’t perform that action at this time.
0 commit comments