]> git.lizzy.rs Git - rust.git/commitdiff
Use IOV_MAX and UIO_MAXIOV constants in limit vectored I/O
authorThomas de Zeeuw <thomasdezeeuw@gmail.com>
Thu, 10 Sep 2020 09:35:25 +0000 (11:35 +0200)
committerThomas de Zeeuw <thomasdezeeuw@gmail.com>
Thu, 10 Sep 2020 14:27:28 +0000 (16:27 +0200)
Also updates the libc dependency to 0.2.77 (from 0.2.74) as the
constants were only recently added.

library/std/Cargo.toml
library/std/src/sys/unix/fd.rs

index bfd05db6b1bbee628c1554fdd33db18d7296d81d..01babeffd98f08ce34a8a6c676b41e02da289c02 100644 (file)
@@ -16,7 +16,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
 panic_unwind = { path = "../panic_unwind", optional = true }
 panic_abort = { path = "../panic_abort" }
 core = { path = "../core" }
-libc = { version = "0.2.74", default-features = false, features = ['rustc-dep-of-std'] }
+libc = { version = "0.2.77", default-features = false, features = ['rustc-dep-of-std'] }
 compiler_builtins = { version = "0.1.35" }
 profiler_builtins = { path = "../profiler_builtins", optional = true }
 unwind = { path = "../unwind" }
index b2f15eda9d7b093ccc69c5028ecb51ccd2d893c1..16adbe6d88c4f07bc061430a6d8db362054968e4 100644 (file)
@@ -7,7 +7,6 @@
 use crate::io::{self, Initializer, IoSlice, IoSliceMut, Read};
 use crate::mem;
 #[cfg(not(any(target_os = "redox", target_env = "newlib")))]
-use crate::sync::atomic::{AtomicUsize, Ordering};
 use crate::sys::cvt;
 use crate::sys_common::AsInner;
 
@@ -31,24 +30,35 @@ pub struct FileDesc {
 #[cfg(not(target_os = "macos"))]
 const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
 
-#[cfg(not(any(target_os = "redox", target_env = "newlib")))]
-fn max_iov() -> usize {
-    static LIM: AtomicUsize = AtomicUsize::new(0);
-
-    let mut lim = LIM.load(Ordering::Relaxed);
-    if lim == 0 {
-        let ret = unsafe { libc::sysconf(libc::_SC_IOV_MAX) };
-
-        // 16 is the minimum value required by POSIX.
-        lim = if ret > 0 { ret as usize } else { 16 };
-        LIM.store(lim, Ordering::Relaxed);
-    }
+#[cfg(any(
+    target_os = "dragonfly",
+    target_os = "freebsd",
+    target_os = "ios",
+    target_os = "macos",
+    target_os = "netbsd",
+    target_os = "openbsd",
+))]
+const fn max_iov() -> usize {
+    libc::IOV_MAX as usize
+}
 
-    lim
+#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
+const fn max_iov() -> usize {
+    libc::UIO_MAXIOV as usize
 }
 
-#[cfg(any(target_os = "redox", target_env = "newlib"))]
-fn max_iov() -> usize {
+#[cfg(not(any(
+    target_os = "android",
+    target_os = "dragonfly",
+    target_os = "emscripten",
+    target_os = "freebsd",
+    target_os = "ios",
+    target_os = "linux",
+    target_os = "macos",
+    target_os = "netbsd",
+    target_os = "openbsd",
+)))]
+const fn max_iov() -> usize {
     16 // The minimum value required by POSIX.
 }