Skip to content

Commit 04a0114

Browse files
committed
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.
1 parent 87edccf commit 04a0114

File tree

1 file changed

+3
-17
lines changed
  • library/std/src/sys/unix

1 file changed

+3
-17
lines changed

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

+3-17
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,21 @@ const READ_LIMIT: usize = c_int::MAX as usize - 1;
2727
#[cfg(not(target_os = "macos"))]
2828
const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
2929

30-
#[cfg(any(target_os = "linux", target_os = "macos"))]
3130
fn max_iov() -> usize {
3231
static LIM: AtomicUsize = AtomicUsize::new(0);
3332

3433
let mut lim = LIM.load(Ordering::Relaxed);
3534
if lim == 0 {
36-
let ret = unsafe {
37-
libc::sysconf(
38-
#[cfg(target_os = "linux")]
39-
libc::_SC_IOV_MAX,
40-
#[cfg(target_os = "macos")]
41-
libc::_SC_UIO_MAXIOV,
42-
)
43-
};
35+
let ret = unsafe { libc::sysconf(libc::_SC_IOV_MAX) };
4436

45-
// 1024 is the default value on modern Linux systems
46-
// and hopefully more useful than `c_int::MAX`.
47-
lim = if ret > 0 { ret as usize } else { 1024 };
37+
// 16 is the minimum value required by POSIX.
38+
lim = if ret > 0 { ret as usize } else { 16 };
4839
LIM.store(lim, Ordering::Relaxed);
4940
}
5041

5142
lim
5243
}
5344

54-
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
55-
fn max_iov() -> usize {
56-
c_int::MAX as usize
57-
}
58-
5945
impl FileDesc {
6046
pub fn new(fd: c_int) -> FileDesc {
6147
FileDesc { fd }

0 commit comments

Comments
 (0)