From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/mio/src/sys/unix/uio.rs | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 third_party/rust/mio/src/sys/unix/uio.rs (limited to 'third_party/rust/mio/src/sys/unix/uio.rs') diff --git a/third_party/rust/mio/src/sys/unix/uio.rs b/third_party/rust/mio/src/sys/unix/uio.rs new file mode 100644 index 0000000000..e38cd4983b --- /dev/null +++ b/third_party/rust/mio/src/sys/unix/uio.rs @@ -0,0 +1,44 @@ +use std::cmp; +use std::io; +use std::os::unix::io::AsRawFd; +use libc; +use iovec::IoVec; +use iovec::unix as iovec; + +pub trait VecIo { + fn readv(&self, bufs: &mut [&mut IoVec]) -> io::Result; + + fn writev(&self, bufs: &[&IoVec]) -> io::Result; +} + +impl VecIo for T { + fn readv(&self, bufs: &mut [&mut IoVec]) -> io::Result { + unsafe { + let slice = iovec::as_os_slice_mut(bufs); + let len = cmp::min(::max_value() as usize, slice.len()); + let rc = libc::readv(self.as_raw_fd(), + slice.as_ptr(), + len as libc::c_int); + if rc < 0 { + Err(io::Error::last_os_error()) + } else { + Ok(rc as usize) + } + } + } + + fn writev(&self, bufs: &[&IoVec]) -> io::Result { + unsafe { + let slice = iovec::as_os_slice(bufs); + let len = cmp::min(::max_value() as usize, slice.len()); + let rc = libc::writev(self.as_raw_fd(), + slice.as_ptr(), + len as libc::c_int); + if rc < 0 { + Err(io::Error::last_os_error()) + } else { + Ok(rc as usize) + } + } + } +} \ No newline at end of file -- cgit v1.2.3