Skip to content

Commit

Permalink
Use set_nonblocking in Async::new on Windows (#157)
Browse files Browse the repository at this point in the history
On Unix, we are already using it.
  • Loading branch information
taiki-e authored Oct 8, 2023
1 parent d5bc619 commit 59ee2ea
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,9 @@ impl<T: AsFd> Async<T> {
/// # std::io::Result::Ok(()) });
/// ```
pub fn new(io: T) -> io::Result<Async<T>> {
// Put the file descriptor in non-blocking mode.
let fd = io.as_fd();

// Put the file descriptor in non-blocking mode.
set_nonblocking(fd)?;

// SAFETY: It is impossible to drop the I/O source while it is registered through
Expand Down Expand Up @@ -733,11 +734,7 @@ impl<T: AsSocket> Async<T> {
let borrowed = io.as_socket();

// Put the socket in non-blocking mode.
//
// Safety: We assume `as_raw_socket()` returns a valid fd. When we can
// depend on Rust >= 1.63, where `AsFd` is stabilized, and when
// `TimerFd` implements it, we can remove this unsafe and simplify this.
rustix::io::ioctl_fionbio(borrowed, true)?;
set_nonblocking(borrowed)?;

// Create the registration.
//
Expand Down

0 comments on commit 59ee2ea

Please sign in to comment.