]> git.lizzy.rs Git - rust.git/commitdiff
Disable accept4 on Android.
authorMaarten de Vries <maarten@de-vri.es>
Sat, 31 Oct 2020 13:20:18 +0000 (14:20 +0100)
committerMaarten de Vries <maarten@de-vri.es>
Fri, 6 Nov 2020 13:17:48 +0000 (14:17 +0100)
library/std/src/sys/unix/net.rs

index 71c6aa5a0e7ea43e0a000b1a6182c382a9d766f8..378d690f8bfd7d5cfa42a5550a6f182ae85cfed6 100644 (file)
@@ -195,7 +195,6 @@ pub fn accept(&self, storage: *mut sockaddr, len: *mut socklen_t) -> io::Result<
         // glibc 2.10 and musl 0.9.5.
         cfg_if::cfg_if! {
             if #[cfg(any(
-                target_os = "android",
                 target_os = "dragonfly",
                 target_os = "freebsd",
                 target_os = "illumos",
@@ -207,6 +206,13 @@ pub fn accept(&self, storage: *mut sockaddr, len: *mut socklen_t) -> io::Result<
                     libc::accept4(self.0.raw(), storage, len, libc::SOCK_CLOEXEC)
                 })?;
                 Ok(Socket(FileDesc::new(fd)))
+            // While the Android kernel supports the syscall,
+            // it is not included in all versions of Android's libc.
+            } else if #[cfg(target_os = "android")] {
+                let fd = cvt_r(|| unsafe {
+                    libc::syscall(libc::SYS_accept4, self.0.raw(), storage, len, libc::SOCK_CLOEXEC)
+                })?;
+                Ok(Socket(FileDesc::new(fd as c_int)))
             } else {
                 let fd = cvt_r(|| unsafe { libc::accept(self.0.raw(), storage, len) })?;
                 let fd = FileDesc::new(fd);