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.
This commit is contained in:
Adam Reichold 2020-08-01 16:06:00 +02:00
parent 87edccf0f0
commit 04a0114e7e

View file

@ -27,35 +27,21 @@ const READ_LIMIT: usize = c_int::MAX as usize - 1;
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
const READ_LIMIT: usize = libc::ssize_t::MAX as usize; const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
#[cfg(any(target_os = "linux", target_os = "macos"))]
fn max_iov() -> usize { fn max_iov() -> usize {
static LIM: AtomicUsize = AtomicUsize::new(0); static LIM: AtomicUsize = AtomicUsize::new(0);
let mut lim = LIM.load(Ordering::Relaxed); let mut lim = LIM.load(Ordering::Relaxed);
if lim == 0 { if lim == 0 {
let ret = unsafe { let ret = unsafe { libc::sysconf(libc::_SC_IOV_MAX) };
libc::sysconf(
#[cfg(target_os = "linux")]
libc::_SC_IOV_MAX,
#[cfg(target_os = "macos")]
libc::_SC_UIO_MAXIOV,
)
};
// 1024 is the default value on modern Linux systems // 16 is the minimum value required by POSIX.
// and hopefully more useful than `c_int::MAX`. lim = if ret > 0 { ret as usize } else { 16 };
lim = if ret > 0 { ret as usize } else { 1024 };
LIM.store(lim, Ordering::Relaxed); LIM.store(lim, Ordering::Relaxed);
} }
lim lim
} }
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
fn max_iov() -> usize {
c_int::MAX as usize
}
impl FileDesc { impl FileDesc {
pub fn new(fd: c_int) -> FileDesc { pub fn new(fd: c_int) -> FileDesc {
FileDesc { fd } FileDesc { fd }