Skip to content

Commit

Permalink
accept()d socket needs to be set to O_NONBLOCK
Browse files Browse the repository at this point in the history
on x86 Android

See #1450
  • Loading branch information
jshearer authored and Thomasdezeeuw committed Feb 22, 2021
1 parent 8d54148 commit 6f86b92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,15 @@ pub fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, Socket
&mut length
))
.map(|socket| unsafe { net::TcpStream::from_raw_fd(socket) })
.and_then(|s| syscall!(fcntl(s.as_raw_fd(), libc::F_SETFD, libc::FD_CLOEXEC)).map(|_| s))
.and_then(|s| {
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFD, libc::FD_CLOEXEC))?;

// See https://github.com/tokio-rs/mio/issues/1450
#[cfg(all(target_arch = "x86",target_os = "android"))]
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK))?;

Ok(s)
})
}?;

// This is safe because `accept` calls above ensures the address
Expand Down
8 changes: 7 additions & 1 deletion src/sys/unix/uds/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
// Ensure the socket is closed if either of the `fcntl` calls
// error below.
let s = unsafe { net::UnixStream::from_raw_fd(socket) };
syscall!(fcntl(socket, libc::F_SETFD, libc::FD_CLOEXEC)).map(|_| s)
syscall!(fcntl(socket, libc::F_SETFD, libc::FD_CLOEXEC))?;

// See https://github.com/tokio-rs/mio/issues/1450
#[cfg(all(target_arch = "x86",target_os = "android"))]
syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK))?;

Ok(s)
});

socket
Expand Down

0 comments on commit 6f86b92

Please sign in to comment.