File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ harness = false
20
20
21
21
[dependencies ]
22
22
async-lock = " 2.6"
23
+ cfg-if = " 1"
23
24
concurrent-queue = " 2"
24
25
futures-lite = " 1.11.0"
25
26
log = " 0.4.11"
Original file line number Diff line number Diff line change @@ -636,8 +636,23 @@ impl<T: AsRawFd> Async<T> {
636
636
// depend on Rust >= 1.63, where `AsFd` is stabilized, and when
637
637
// `TimerFd` implements it, we can remove this unsafe and simplify this.
638
638
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
+ }
641
656
642
657
Ok ( Async {
643
658
source : Reactor :: get ( ) . insert_io ( raw) ?,
You can’t perform that action at this time.
0 commit comments