Skip to content

Commit 6f86b92

Browse files
jshearerThomasdezeeuw
authored andcommitted
accept()d socket needs to be set to O_NONBLOCK
on x86 Android See #1450
1 parent 8d54148 commit 6f86b92

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
@@ -471,7 +471,15 @@ pub fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, Socket
471471
&mut length
472472
))
473473
.map(|socket| unsafe { net::TcpStream::from_raw_fd(socket) })
474-
.and_then(|s| syscall!(fcntl(s.as_raw_fd(), libc::F_SETFD, libc::FD_CLOEXEC)).map(|_| s))
474+
.and_then(|s| {
475+
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFD, libc::FD_CLOEXEC))?;
476+
477+
// See https://github.com/tokio-rs/mio/issues/1450
478+
#[cfg(all(target_arch = "x86",target_os = "android"))]
479+
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK))?;
480+
481+
Ok(s)
482+
})
475483
}?;
476484

477485
// 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)