Skip to content

Commit f7b6ace

Browse files
committed
Use IOV_MAX and UIO_MAXIOV constants in limit vectored I/O
Also updates the libc dependency to 0.2.77 (from 0.2.74) as the constants were only recently added.
1 parent 8819721 commit f7b6ace

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1616
panic_unwind = { path = "../panic_unwind", optional = true }
1717
panic_abort = { path = "../panic_abort" }
1818
core = { path = "../core" }
19-
libc = { version = "0.2.74", default-features = false, features = ['rustc-dep-of-std'] }
19+
libc = { version = "0.2.77", default-features = false, features = ['rustc-dep-of-std'] }
2020
compiler_builtins = { version = "0.1.35" }
2121
profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }

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

+26-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::cmp;
77
use crate::io::{self, Initializer, IoSlice, IoSliceMut, Read};
88
use crate::mem;
99
#[cfg(not(any(target_os = "redox", target_env = "newlib")))]
10-
use crate::sync::atomic::{AtomicUsize, Ordering};
1110
use crate::sys::cvt;
1211
use crate::sys_common::AsInner;
1312

@@ -31,24 +30,35 @@ const READ_LIMIT: usize = c_int::MAX as usize - 1;
3130
#[cfg(not(target_os = "macos"))]
3231
const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
3332

34-
#[cfg(not(any(target_os = "redox", target_env = "newlib")))]
35-
fn max_iov() -> usize {
36-
static LIM: AtomicUsize = AtomicUsize::new(0);
37-
38-
let mut lim = LIM.load(Ordering::Relaxed);
39-
if lim == 0 {
40-
let ret = unsafe { libc::sysconf(libc::_SC_IOV_MAX) };
41-
42-
// 16 is the minimum value required by POSIX.
43-
lim = if ret > 0 { ret as usize } else { 16 };
44-
LIM.store(lim, Ordering::Relaxed);
45-
}
33+
#[cfg(any(
34+
target_os = "dragonfly",
35+
target_os = "freebsd",
36+
target_os = "ios",
37+
target_os = "macos",
38+
target_os = "netbsd",
39+
target_os = "openbsd",
40+
))]
41+
const fn max_iov() -> usize {
42+
libc::IOV_MAX as usize
43+
}
4644

47-
lim
45+
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
46+
const fn max_iov() -> usize {
47+
libc::UIO_MAXIOV as usize
4848
}
4949

50-
#[cfg(any(target_os = "redox", target_env = "newlib"))]
51-
fn max_iov() -> usize {
50+
#[cfg(not(any(
51+
target_os = "android",
52+
target_os = "dragonfly",
53+
target_os = "emscripten",
54+
target_os = "freebsd",
55+
target_os = "ios",
56+
target_os = "linux",
57+
target_os = "macos",
58+
target_os = "netbsd",
59+
target_os = "openbsd",
60+
)))]
61+
const fn max_iov() -> usize {
5262
16 // The minimum value required by POSIX.
5363
}
5464

0 commit comments

Comments
 (0)