From 31bcec648aa57391115f877a2ca022d7ff6415aa Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 8 Feb 2019 20:42:34 +0100 Subject: Add vectored read and write support This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies. --- src/libstd/sys/windows/c.rs | 25 +++++++++++++++++ src/libstd/sys/windows/io.rs | 63 +++++++++++++++++++++++++++++++++++++++++++ src/libstd/sys/windows/mod.rs | 27 ++++++++++--------- src/libstd/sys/windows/net.rs | 43 ++++++++++++++++++++++++++++- 4 files changed, 144 insertions(+), 14 deletions(-) create mode 100644 src/libstd/sys/windows/io.rs (limited to 'src/libstd/sys/windows') diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 28fd4df386e..a78b599204b 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -57,6 +57,9 @@ pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO; pub type LPSTR = *mut CHAR; pub type LPWSTR = *mut WCHAR; pub type LPFILETIME = *mut FILETIME; +pub type LPWSABUF = *mut WSABUF; +pub type LPWSAOVERLAPPED = *mut c_void; +pub type LPWSAOVERLAPPED_COMPLETION_ROUTINE = *mut c_void; pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE; pub type PLARGE_INTEGER = *mut c_longlong; @@ -324,6 +327,12 @@ pub struct WSADATA { pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1], } +#[repr(C)] +pub struct WSABUF { + pub len: ULONG, + pub buf: *mut CHAR, +} + #[repr(C)] pub struct WSAPROTOCOL_INFO { pub dwServiceFlags1: DWORD, @@ -988,6 +997,22 @@ extern "system" { dwProcessId: DWORD, lpProtocolInfo: LPWSAPROTOCOL_INFO) -> c_int; + pub fn WSASend(s: SOCKET, + lpBuffers: LPWSABUF, + dwBufferCount: DWORD, + lpNumberOfBytesSent: LPDWORD, + dwFlags: DWORD, + lpOverlapped: LPWSAOVERLAPPED, + lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE) + -> c_int; + pub fn WSARecv(s: SOCKET, + lpBuffers: LPWSABUF, + dwBufferCount: DWORD, + lpNumberOfBytesRecvd: LPDWORD, + lpFlags: LPDWORD, + lpOverlapped: LPWSAOVERLAPPED, + lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE) + -> c_int; pub fn GetCurrentProcessId() -> DWORD; pub fn WSASocketW(af: c_int, kind: c_int, diff --git a/src/libstd/sys/windows/io.rs b/src/libstd/sys/windows/io.rs new file mode 100644 index 00000000000..a14bfea9a21 --- /dev/null +++ b/src/libstd/sys/windows/io.rs @@ -0,0 +1,63 @@ +use marker::PhantomData; +use slice; +use sys::c; + +#[repr(transparent)] +pub struct IoVec<'a> { + vec: c::WSABUF, + _p: PhantomData<&'a [u8]>, +} + +impl<'a> IoVec<'a> { + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { + assert!(buf.len() <= c::ULONG::max_value() as usize); + IoVec { + vec: c::WSABUF { + len: buf.len() as c::ULONG, + buf: buf.as_ptr() as *mut u8 as *mut c::CHAR, + }, + _p: PhantomData, + } + } + + #[inline] + pub fn as_slice(&self) -> &'a [u8] { + unsafe { + slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) + } + } +} + +pub struct IoVecMut<'a> { + vec: c::WSABUF, + _p: PhantomData<&'a mut [u8]>, +} + +impl<'a> IoVecMut<'a> { + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { + assert!(buf.len() <= c::ULONG::max_value() as usize); + IoVecMut { + vec: c::WSABUF { + len: buf.len() as c::ULONG, + buf: buf.as_mut_ptr() as *mut c::CHAR, + }, + _p: PhantomData, + } + } + + #[inline] + pub fn as_slice(&self) -> &'a [u8] { + unsafe { + slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) + } + } + + #[inline] + pub fn as_mut_slice(&mut self) -> &'a mut [u8] { + unsafe { + slice::from_raw_parts_mut(self.vec.buf as *mut u8, self.vec.len as usize) + } + } +} diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index e97e436efbf..56c76a169fe 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -2,7 +2,7 @@ use ptr; use ffi::{OsStr, OsString}; -use io::{self, ErrorKind}; +use io::ErrorKind; use os::windows::ffi::{OsStrExt, OsStringExt}; use path::PathBuf; use time::Duration; @@ -26,6 +26,7 @@ pub mod ext; pub mod fast_thread_local; pub mod fs; pub mod handle; +pub mod io; pub mod memchr; pub mod mutex; pub mod net; @@ -75,12 +76,12 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { } } -pub fn to_u16s>(s: S) -> io::Result> { - fn inner(s: &OsStr) -> io::Result> { +pub fn to_u16s>(s: S) -> ::io::Result> { + fn inner(s: &OsStr) -> ::io::Result> { let mut maybe_result: Vec = s.encode_wide().collect(); if maybe_result.iter().any(|&u| u == 0) { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "strings passed to WinAPI cannot contain NULs")); + return Err(::io::Error::new(::io::ErrorKind::InvalidInput, + "strings passed to WinAPI cannot contain NULs")); } maybe_result.push(0); Ok(maybe_result) @@ -102,7 +103,7 @@ pub fn to_u16s>(s: S) -> io::Result> { // Once the syscall has completed (errors bail out early) the second closure is // yielded the data which has been read from the syscall. The return value // from this closure is then the return value of the function. -fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result +fn fill_utf16_buf(mut f1: F1, f2: F2) -> ::io::Result where F1: FnMut(*mut u16, c::DWORD) -> c::DWORD, F2: FnOnce(&[u16]) -> T { @@ -134,7 +135,7 @@ fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result c::SetLastError(0); let k = match f1(buf.as_mut_ptr(), n as c::DWORD) { 0 if c::GetLastError() == 0 => 0, - 0 => return Err(io::Error::last_os_error()), + 0 => return Err(::io::Error::last_os_error()), n => n, } as usize; if k == n && c::GetLastError() == c::ERROR_INSUFFICIENT_BUFFER { @@ -157,7 +158,7 @@ fn wide_char_to_multi_byte(code_page: u32, flags: u32, s: &[u16], no_default_char: bool) - -> io::Result> { + -> ::io::Result> { unsafe { let mut size = c::WideCharToMultiByte(code_page, flags, @@ -168,7 +169,7 @@ fn wide_char_to_multi_byte(code_page: u32, ptr::null(), ptr::null_mut()); if size == 0 { - return Err(io::Error::last_os_error()); + return Err(::io::Error::last_os_error()); } let mut buf = Vec::with_capacity(size as usize); @@ -185,10 +186,10 @@ fn wide_char_to_multi_byte(code_page: u32, if no_default_char { &mut used_default_char } else { ptr::null_mut() }); if size == 0 { - return Err(io::Error::last_os_error()); + return Err(::io::Error::last_os_error()); } if no_default_char && used_default_char == c::TRUE { - return Err(io::Error::new(io::ErrorKind::InvalidData, + return Err(::io::Error::new(::io::ErrorKind::InvalidData, "string cannot be converted to requested code page")); } @@ -220,9 +221,9 @@ macro_rules! impl_is_zero { impl_is_zero! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize } -pub fn cvt(i: I) -> io::Result { +pub fn cvt(i: I) -> ::io::Result { if i.is_zero() { - Err(io::Error::last_os_error()) + Err(::io::Error::last_os_error()) } else { Ok(i) } diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index acda81dcde5..76be26a9d1a 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -1,7 +1,7 @@ #![unstable(issue = "0", feature = "windows_net")] use cmp; -use io::{self, Read}; +use io::{self, Read, IoVec, IoVecMut}; use libc::{c_int, c_void, c_ulong, c_long}; use mem; use net::{SocketAddr, Shutdown}; @@ -207,6 +207,30 @@ impl Socket { self.recv_with_flags(buf, 0) } + pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + // On unix when a socket is shut down all further reads return 0, so we + // do the same on windows to map a shut down socket to returning EOF. + let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD; + let mut nread = 0; + let mut flags = 0; + unsafe { + let ret = c::WSARecv( + self.0, + bufs.as_mut_ptr() as *mut c::WSABUF, + len, + &mut nread, + &mut flags, + ptr::null_mut(), + ptr::null_mut(), + ); + match ret { + 0 => Ok(nread as usize), + _ if c::WSAGetLastError() == c::WSAESHUTDOWN => Ok(0), + _ => Err(last_error()), + } + } + } + pub fn peek(&self, buf: &mut [u8]) -> io::Result { self.recv_with_flags(buf, c::MSG_PEEK) } @@ -243,6 +267,23 @@ impl Socket { self.recv_from_with_flags(buf, c::MSG_PEEK) } + pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD; + let mut nwritten = 0; + unsafe { + cvt(c::WSASend( + self.0, + bufs.as_ptr() as *const c::WSABUF as *mut c::WSABUF, + len, + &mut nwritten, + 0, + ptr::null_mut(), + ptr::null_mut(), + ))?; + } + Ok(nwritten as usize) + } + pub fn set_timeout(&self, dur: Option, kind: c_int) -> io::Result<()> { let timeout = match dur { -- cgit 1.4.1-3-g733a5 From 596f18201c7863d8b02fe6fa1872cf3ba2b6b381 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 11 Feb 2019 19:31:37 -0800 Subject: impl Deref/DerefMut for IoVec types Returning &'a mut [u8] was unsound, and we may as well just have them directly deref to their slices to make it easier to work with them. --- src/libstd/io/buffered.rs | 4 ++-- src/libstd/io/cursor.rs | 4 +--- src/libstd/io/impls.rs | 8 ++++---- src/libstd/io/mod.rs | 36 ++++++++++++++++++++++-------------- src/libstd/io/util.rs | 4 ++-- src/libstd/sys/cloudabi/io.rs | 6 +++--- src/libstd/sys/redox/io.rs | 6 +++--- src/libstd/sys/redox/net/tcp.rs | 4 ++-- src/libstd/sys/sgx/io.rs | 6 +++--- src/libstd/sys/sgx/net.rs | 4 ++-- src/libstd/sys/unix/io.rs | 6 +++--- src/libstd/sys/wasm/io.rs | 6 +++--- src/libstd/sys/windows/io.rs | 6 +++--- 13 files changed, 53 insertions(+), 47 deletions(-) (limited to 'src/libstd/sys/windows') diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index a5edc4360ca..d8a5f5a4d8c 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -236,7 +236,7 @@ impl Read for BufReader { } fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { - let total_len = bufs.iter().map(|b| b.as_slice().len()).sum::(); + let total_len = bufs.iter().map(|b| b.len()).sum::(); if self.pos == self.cap && total_len >= self.buf.len() { return self.inner.read_vectored(bufs); } @@ -595,7 +595,7 @@ impl Write for BufWriter { } fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { - let total_len = bufs.iter().map(|b| b.as_slice().len()).sum::(); + let total_len = bufs.iter().map(|b| b.len()).sum::(); if self.buf.len() + total_len > self.buf.capacity() { self.flush_buf()?; } diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index ef636cc6f8c..d1739894a27 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -224,7 +224,6 @@ impl Read for Cursor where T: AsRef<[u8]> { fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { let mut nread = 0; for buf in bufs { - let buf = buf.as_mut_slice(); let n = self.read(buf)?; nread += n; if n < buf.len() { @@ -272,7 +271,6 @@ fn slice_write_vectored( { let mut nwritten = 0; for buf in bufs { - let buf = buf.as_slice(); let n = slice_write(pos_mut, slice, buf)?; nwritten += n; if n < buf.len() { @@ -317,7 +315,7 @@ fn vec_write_vectored( { let mut nwritten = 0; for buf in bufs { - nwritten += vec_write(pos_mut, vec, buf.as_slice())?; + nwritten += vec_write(pos_mut, vec, buf)?; } Ok(nwritten) } diff --git a/src/libstd/io/impls.rs b/src/libstd/io/impls.rs index 4bba4af77c4..57d8cf40a79 100644 --- a/src/libstd/io/impls.rs +++ b/src/libstd/io/impls.rs @@ -196,7 +196,7 @@ impl<'a> Read for &'a [u8] { fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { let mut nread = 0; for buf in bufs { - nread += self.read(buf.as_mut_slice())?; + nread += self.read(buf)?; if self.is_empty() { break; } @@ -269,7 +269,7 @@ impl<'a> Write for &'a mut [u8] { fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { let mut nwritten = 0; for buf in bufs { - nwritten += self.write(buf.as_slice())?; + nwritten += self.write(buf)?; if self.is_empty() { break; } @@ -303,10 +303,10 @@ impl Write for Vec { #[inline] fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { - let len = bufs.iter().map(|b| b.as_slice().len()).sum(); + let len = bufs.iter().map(|b| b.len()).sum(); self.reserve(len); for buf in bufs { - self.extend_from_slice(buf.as_slice()); + self.extend_from_slice(buf); } Ok(len) } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index b9765605f8e..7f9c5a0316c 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -264,6 +264,7 @@ use fmt; use slice; use str; use memchr; +use ops::{Deref, DerefMut}; use ptr; use sys; @@ -531,7 +532,7 @@ pub trait Read { /// `read`. #[unstable(feature = "iovec", issue = "0")] fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { - match bufs.iter_mut().map(|b| b.as_mut_slice()).find(|b| !b.is_empty()) { + match bufs.iter_mut().find(|b| !b.is_empty()) { Some(buf) => self.read(buf), None => Ok(0), } @@ -896,7 +897,7 @@ pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); #[unstable(feature = "iovec", issue = "0")] impl<'a> fmt::Debug for IoVecMut<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(self.as_slice(), fmt) + fmt::Debug::fmt(self.0.as_slice(), fmt) } } @@ -911,18 +912,22 @@ impl<'a> IoVecMut<'a> { pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { IoVecMut(sys::io::IoVecMut::new(buf)) } +} + +#[unstable(feature = "iovec", issue = "0")] +impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; - /// Returns a shared reference to the inner slice. - #[unstable(feature = "iovec", issue = "0")] #[inline] - pub fn as_slice(&self) -> &'a [u8] { + fn deref(&self) -> &[u8] { self.0.as_slice() } +} - /// Returns a mutable reference to the inner slice. - #[unstable(feature = "iovec", issue = "0")] +#[unstable(feature = "iovec", issue = "0")] +impl<'a> DerefMut for IoVecMut<'a> { #[inline] - pub fn as_mut_slice(&mut self) -> &'a mut [u8] { + fn deref_mut(&mut self) -> &mut [u8] { self.0.as_mut_slice() } } @@ -939,7 +944,7 @@ pub struct IoVec<'a>(sys::io::IoVec<'a>); #[unstable(feature = "iovec", issue = "0")] impl<'a> fmt::Debug for IoVec<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(self.as_slice(), fmt) + fmt::Debug::fmt(self.0.as_slice(), fmt) } } @@ -954,11 +959,14 @@ impl<'a> IoVec<'a> { pub fn new(buf: &'a [u8]) -> IoVec<'a> { IoVec(sys::io::IoVec::new(buf)) } +} + +#[unstable(feature = "iovec", issue = "0")] +impl<'a> Deref for IoVec<'a> { + type Target = [u8]; - /// Returns a shared reference to the inner slice. - #[unstable(feature = "iovec", issue = "0")] #[inline] - pub fn as_slice(&self) -> &'a [u8] { + fn deref(&self) -> &[u8] { self.0.as_slice() } } @@ -1103,7 +1111,7 @@ pub trait Write { /// `write`. #[unstable(feature = "iovec", issue = "0")] fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { - match bufs.iter().map(|b| b.as_slice()).find(|b| !b.is_empty()) { + match bufs.iter().find(|b| !b.is_empty()) { Some(buf) => self.write(buf), None => Ok(0), } @@ -1813,7 +1821,7 @@ impl Read for Chain { fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { if !self.done_first { match self.first.read_vectored(bufs)? { - 0 if bufs.iter().any(|b| !b.as_slice().is_empty()) => self.done_first = true, + 0 if bufs.iter().any(|b| !b.is_empty()) => self.done_first = true, n => return Ok(n), } } diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 6743018793f..5ce955eb1e4 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -156,7 +156,7 @@ impl Read for Repeat { fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { let mut nwritten = 0; for buf in bufs { - nwritten += self.read(buf.as_mut_slice())?; + nwritten += self.read(buf)?; } Ok(nwritten) } @@ -207,7 +207,7 @@ impl Write for Sink { #[inline] fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { - let total_len = bufs.iter().map(|b| b.as_slice().len()).sum(); + let total_len = bufs.iter().map(|b| b.len()).sum(); Ok(total_len) } diff --git a/src/libstd/sys/cloudabi/io.rs b/src/libstd/sys/cloudabi/io.rs index 9ee5788c580..8b02d3fd19d 100644 --- a/src/libstd/sys/cloudabi/io.rs +++ b/src/libstd/sys/cloudabi/io.rs @@ -7,7 +7,7 @@ impl<'a> IoVec<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { self.0 } } @@ -21,12 +21,12 @@ impl<'a> IoVecMut<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { self.0 } #[inline] - pub fn as_mut_slice(&mut self) -> &'a mut [u8] { + pub fn as_mut_slice(&mut self) -> &mut [u8] { self.0 } } diff --git a/src/libstd/sys/redox/io.rs b/src/libstd/sys/redox/io.rs index 9ee5788c580..8b02d3fd19d 100644 --- a/src/libstd/sys/redox/io.rs +++ b/src/libstd/sys/redox/io.rs @@ -7,7 +7,7 @@ impl<'a> IoVec<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { self.0 } } @@ -21,12 +21,12 @@ impl<'a> IoVecMut<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { self.0 } #[inline] - pub fn as_mut_slice(&mut self) -> &'a mut [u8] { + pub fn as_mut_slice(&mut self) -> &mut [u8] { self.0 } } diff --git a/src/libstd/sys/redox/net/tcp.rs b/src/libstd/sys/redox/net/tcp.rs index 08e12dc1ab1..4396a6f963c 100644 --- a/src/libstd/sys/redox/net/tcp.rs +++ b/src/libstd/sys/redox/net/tcp.rs @@ -35,7 +35,7 @@ impl TcpStream { } pub fn read_vectored(&self, buf: &mut [IoVecMut<'_>]) -> io::Result { - match buf.iter_mut().map(|b| b.as_mut_slice()).find(|b| !b.is_empty()) { + match buf.iter_mut().find(|b| !b.is_empty()) { Some(buf) => self.read(buf), None => Ok(0), } @@ -46,7 +46,7 @@ impl TcpStream { } pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { - match buf.iter().map(|b| b.as_slice()).find(|b| !b.is_empty()) { + match buf.iter().find(|b| !b.is_empty()) { Some(buf) => self.write(buf), None => Ok(0), } diff --git a/src/libstd/sys/sgx/io.rs b/src/libstd/sys/sgx/io.rs index 9ee5788c580..8b02d3fd19d 100644 --- a/src/libstd/sys/sgx/io.rs +++ b/src/libstd/sys/sgx/io.rs @@ -7,7 +7,7 @@ impl<'a> IoVec<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { self.0 } } @@ -21,12 +21,12 @@ impl<'a> IoVecMut<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { self.0 } #[inline] - pub fn as_mut_slice(&mut self) -> &'a mut [u8] { + pub fn as_mut_slice(&mut self) -> &mut [u8] { self.0 } } diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs index 2ecae1d746f..f46ed022b21 100644 --- a/src/libstd/sys/sgx/net.rs +++ b/src/libstd/sys/sgx/net.rs @@ -105,7 +105,7 @@ impl TcpStream { pub fn read_vectored(&self, buf: &mut [IoVecMut<'_>]) -> io::Result { let buf = match buf.get(0) { - Some(buf) => buf.as_mut_slice(), + Some(buf) => buf, None => return Ok(0), }; self.read(buf) @@ -117,7 +117,7 @@ impl TcpStream { pub fn write_vectored(&self, buf: &[IoVec<'_>]) -> io::Result { let buf = match buf.get(0) { - Some(buf) => buf.as_slice(), + Some(buf) => buf, None => return Ok(0), }; self.read(buf) diff --git a/src/libstd/sys/unix/io.rs b/src/libstd/sys/unix/io.rs index 69b2db82ea3..65e4c6e0577 100644 --- a/src/libstd/sys/unix/io.rs +++ b/src/libstd/sys/unix/io.rs @@ -21,7 +21,7 @@ impl<'a> IoVec<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) } @@ -46,14 +46,14 @@ impl<'a> IoVecMut<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) } } #[inline] - pub fn as_mut_slice(&mut self) -> &'a mut [u8] { + pub fn as_mut_slice(&mut self) -> &mut [u8] { unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) } diff --git a/src/libstd/sys/wasm/io.rs b/src/libstd/sys/wasm/io.rs index 9ee5788c580..8b02d3fd19d 100644 --- a/src/libstd/sys/wasm/io.rs +++ b/src/libstd/sys/wasm/io.rs @@ -7,7 +7,7 @@ impl<'a> IoVec<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { self.0 } } @@ -21,12 +21,12 @@ impl<'a> IoVecMut<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { self.0 } #[inline] - pub fn as_mut_slice(&mut self) -> &'a mut [u8] { + pub fn as_mut_slice(&mut self) -> &mut [u8] { self.0 } } diff --git a/src/libstd/sys/windows/io.rs b/src/libstd/sys/windows/io.rs index a14bfea9a21..662e3047923 100644 --- a/src/libstd/sys/windows/io.rs +++ b/src/libstd/sys/windows/io.rs @@ -22,7 +22,7 @@ impl<'a> IoVec<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { unsafe { slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) } @@ -48,14 +48,14 @@ impl<'a> IoVecMut<'a> { } #[inline] - pub fn as_slice(&self) -> &'a [u8] { + pub fn as_slice(&self) -> &[u8] { unsafe { slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) } } #[inline] - pub fn as_mut_slice(&mut self) -> &'a mut [u8] { + pub fn as_mut_slice(&mut self) -> &mut [u8] { unsafe { slice::from_raw_parts_mut(self.vec.buf as *mut u8, self.vec.len as usize) } -- cgit 1.4.1-3-g733a5