Skip to content

Commit 4c4e919

Browse files
jshearerThomasdezeeuw
authored andcommitted
accept()d socket needs to be set to O_NONBLOCK
on x86 Android See #1450
1 parent 527e843 commit 4c4e919

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/sys/unix/tcp.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,15 @@ pub fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, Socket
465465
&mut length
466466
))
467467
.map(|socket| unsafe { net::TcpStream::from_raw_fd(socket) })
468-
.and_then(|s| syscall!(fcntl(s.as_raw_fd(), libc::F_SETFD, libc::FD_CLOEXEC)).map(|_| s))
468+
.and_then(|s| {
469+
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFD, libc::FD_CLOEXEC))?;
470+
471+
// See https://github.com/tokio-rs/mio/issues/1450
472+
#[cfg(all(target_arch = "x86",target_os = "android"))]
473+
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK))?;
474+
475+
Ok(s)
476+
})
469477
}?;
470478

471479
// This is safe because `accept` calls above ensures the address

src/sys/unix/uds/listener.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
8080
// Ensure the socket is closed if either of the `fcntl` calls
8181
// error below.
8282
let s = unsafe { net::UnixStream::from_raw_fd(socket) };
83-
syscall!(fcntl(socket, libc::F_SETFD, libc::FD_CLOEXEC)).map(|_| s)
83+
syscall!(fcntl(socket, libc::F_SETFD, libc::FD_CLOEXEC))?;
84+
85+
// See https://github.com/tokio-rs/mio/issues/1450
86+
#[cfg(all(target_arch = "x86",target_os = "android"))]
87+
syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK))?;
88+
89+
Ok(s)
8490
});
8591

8692
socket

0 commit comments

Comments
 (0)