mirror of
https://github.com/rust-lang/rust
synced 2024-10-06 16:51:35 +00:00
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.
This commit is contained in:
parent
88197214b8
commit
f7b6ace029
|
@ -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" }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
lim
|
||||
#[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
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "redox", target_env = "newlib"))]
|
||||
fn max_iov() -> usize {
|
||||
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
|
||||
const fn max_iov() -> usize {
|
||||
libc::UIO_MAXIOV as 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.
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue