From 04a0114e7ecc44049425aaf8f7ba7f66da80e0c4 Mon Sep 17 00:00:00 2001 From: Adam Reichold Date: Sat, 1 Aug 2020 16:06:00 +0200 Subject: [PATCH] Rely only on POSIX semantics for I/O vector count All #[cfg(unix)] platforms follow the POSIX standard and define _SC_IOV_MAX so that we rely purely on POSIX semantics to determine the limits on I/O vector count. --- library/std/src/sys/unix/fd.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 91116a53235..6b8f3ea172d 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -27,35 +27,21 @@ const READ_LIMIT: usize = c_int::MAX as usize - 1; #[cfg(not(target_os = "macos"))] const READ_LIMIT: usize = libc::ssize_t::MAX as usize; -#[cfg(any(target_os = "linux", target_os = "macos"))] 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( - #[cfg(target_os = "linux")] - libc::_SC_IOV_MAX, - #[cfg(target_os = "macos")] - libc::_SC_UIO_MAXIOV, - ) - }; + let ret = unsafe { libc::sysconf(libc::_SC_IOV_MAX) }; - // 1024 is the default value on modern Linux systems - // and hopefully more useful than `c_int::MAX`. - lim = if ret > 0 { ret as usize } else { 1024 }; + // 16 is the minimum value required by POSIX. + lim = if ret > 0 { ret as usize } else { 16 }; LIM.store(lim, Ordering::Relaxed); } lim } -#[cfg(not(any(target_os = "linux", target_os = "macos")))] -fn max_iov() -> usize { - c_int::MAX as usize -} - impl FileDesc { pub fn new(fd: c_int) -> FileDesc { FileDesc { fd }