Skip to content

Commit

Permalink
Use accept() instead of accept4() on x86 Android
Browse files Browse the repository at this point in the history
Description in, closes #1445
  • Loading branch information
jshearer authored and Thomasdezeeuw committed Feb 22, 2021
1 parent 139f7c4 commit 8d54148
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,12 @@ pub fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, Socket
// On platforms that support it we can use `accept4(2)` to set `NONBLOCK`
// and `CLOEXEC` in the call to accept the connection.
#[cfg(any(
target_os = "android",
// Android x86's seccomp profile forbids calls to `accept4(2)`
// See https://github.com/tokio-rs/mio/issues/1445 for details
all(
not(target_arch="x86"),
target_os = "android"
),
target_os = "dragonfly",
target_os = "freebsd",
target_os = "illumos",
Expand All @@ -450,7 +455,15 @@ pub fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, Socket
// But not all platforms have the `accept4(2)` call. Luckily BSD (derived)
// OSes inherit the non-blocking flag from the listener, so we just have to
// set `CLOEXEC`.
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "solaris"))]
#[cfg(any(
all(
target_arch = "x86",
target_os = "android"
),
target_os = "ios",
target_os = "macos",
target_os = "solaris"
))]
let stream = {
syscall!(accept(
listener.as_raw_fd(),
Expand Down
14 changes: 12 additions & 2 deletions src/sys/unix/uds/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "solaris"
target_os = "solaris",
// Android x86's seccomp profile forbids calls to `accept4(2)`
// See https://github.com/tokio-rs/mio/issues/1445 for details
all(
target_arch = "x86",
target_os = "android"
)
)))]
let socket = {
let flags = libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;
Expand All @@ -59,7 +65,11 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "solaris"
target_os = "solaris",
all(
target_arch = "x86",
target_os = "android"
)
))]
let socket = syscall!(accept(
listener.as_raw_fd(),
Expand Down

0 comments on commit 8d54148

Please sign in to comment.