Skip to content
Permalink
Browse files

Stabilized vectored IO

This renames `std::io::IoVec` to `std::io::IoSlice` and
`std::io::IoVecMut` to `std::io::IoSliceMut`, and stabilizes
`std::io::IoSlice`, `std::io::IoSliceMut`,
`std::io::Read::read_vectored`, and `std::io::Write::write_vectored`.

Closes #58452
  • Loading branch information...
sfackler committed Apr 27, 2019
1 parent d4a32d5 commit bd177f3ea31e47b94dd400239a9badfe2bd47355
Showing with 278 additions and 278 deletions.
  1. +5 −5 src/libstd/fs.rs
  2. +3 −3 src/libstd/io/buffered.rs
  3. +29 −29 src/libstd/io/cursor.rs
  4. +9 −9 src/libstd/io/impls.rs
  5. +31 −31 src/libstd/io/mod.rs
  6. +12 −12 src/libstd/io/stdio.rs
  7. +3 −3 src/libstd/io/util.rs
  8. +8 −8 src/libstd/net/tcp.rs
  9. +4 −4 src/libstd/process.rs
  10. +8 −8 src/libstd/sys/cloudabi/io.rs
  11. +3 −3 src/libstd/sys/cloudabi/shims/fs.rs
  12. +3 −3 src/libstd/sys/cloudabi/shims/net.rs
  13. +3 −3 src/libstd/sys/cloudabi/shims/pipe.rs
  14. +3 −3 src/libstd/sys/redox/fs.rs
  15. +8 −8 src/libstd/sys/redox/io.rs
  16. +3 −3 src/libstd/sys/redox/net/tcp.rs
  17. +3 −3 src/libstd/sys/redox/pipe.rs
  18. +3 −3 src/libstd/sys/sgx/fs.rs
  19. +8 −8 src/libstd/sys/sgx/io.rs
  20. +3 −3 src/libstd/sys/sgx/net.rs
  21. +3 −3 src/libstd/sys/sgx/pipe.rs
  22. +7 −7 src/libstd/sys/unix/ext/net.rs
  23. +3 −3 src/libstd/sys/unix/fd.rs
  24. +3 −3 src/libstd/sys/unix/fs.rs
  25. +8 −8 src/libstd/sys/unix/io.rs
  26. +5 −5 src/libstd/sys/unix/l4re.rs
  27. +3 −3 src/libstd/sys/unix/net.rs
  28. +3 −3 src/libstd/sys/unix/pipe.rs
  29. +4 −4 src/libstd/sys/unix/stdio.rs
  30. +5 −5 src/libstd/sys/wasi/ext/fs.rs
  31. +13 −13 src/libstd/sys/wasi/fd.rs
  32. +5 −5 src/libstd/sys/wasi/fs.rs
  33. +8 −8 src/libstd/sys/wasi/io.rs
  34. +3 −3 src/libstd/sys/wasi/net.rs
  35. +3 −3 src/libstd/sys/wasi/pipe.rs
  36. +7 −7 src/libstd/sys/wasi/stdio.rs
  37. +3 −3 src/libstd/sys/wasm/fs.rs
  38. +8 −8 src/libstd/sys/wasm/io.rs
  39. +3 −3 src/libstd/sys/wasm/net.rs
  40. +3 −3 src/libstd/sys/wasm/pipe.rs
  41. +3 −3 src/libstd/sys/windows/fs.rs
  42. +4 −4 src/libstd/sys/windows/handle.rs
  43. +8 −8 src/libstd/sys/windows/io.rs
  44. +3 −3 src/libstd/sys/windows/net.rs
  45. +3 −3 src/libstd/sys/windows/pipe.rs
  46. +3 −3 src/libstd/sys_common/net.rs
  47. +2 −2 src/tools/linkchecker/main.rs
@@ -11,7 +11,7 @@

use crate::fmt;
use crate::ffi::OsString;
use crate::io::{self, SeekFrom, Seek, Read, Initializer, Write, IoVec, IoVecMut};
use crate::io::{self, SeekFrom, Seek, Read, Initializer, Write, IoSlice, IoSliceMut};
use crate::path::{Path, PathBuf};
use crate::sys::fs as fs_imp;
use crate::sys_common::{AsInnerMut, FromInner, AsInner, IntoInner};
@@ -617,7 +617,7 @@ impl Read for File {
self.inner.read(buf)
}

fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
self.inner.read_vectored(bufs)
}

@@ -632,7 +632,7 @@ impl Write for File {
self.inner.write(buf)
}

fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.inner.write_vectored(bufs)
}

@@ -650,7 +650,7 @@ impl Read for &File {
self.inner.read(buf)
}

fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
self.inner.read_vectored(bufs)
}

@@ -665,7 +665,7 @@ impl Write for &File {
self.inner.write(buf)
}

fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.inner.write_vectored(bufs)
}

@@ -5,7 +5,7 @@ use crate::io::prelude::*;
use crate::cmp;
use crate::error;
use crate::fmt;
use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut};
use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoSlice, IoSliceMut};
use crate::memchr;

/// The `BufReader` struct adds buffering to any reader.
@@ -249,7 +249,7 @@ impl<R: Read> Read for BufReader<R> {
Ok(nread)
}

fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
let total_len = bufs.iter().map(|b| b.len()).sum::<usize>();
if self.pos == self.cap && total_len >= self.buf.len() {
self.discard_buffer();
@@ -609,7 +609,7 @@ impl<W: Write> Write for BufWriter<W> {
}
}

fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let total_len = bufs.iter().map(|b| b.len()).sum::<usize>();
if self.buf.len() + total_len > self.buf.capacity() {
self.flush_buf()?;
@@ -1,7 +1,7 @@
use crate::io::prelude::*;

use crate::cmp;
use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut};
use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoSlice, IoSliceMut};

use core::convert::TryInto;

@@ -230,7 +230,7 @@ impl<T> Read for Cursor<T> where T: AsRef<[u8]> {
Ok(n)
}

fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
let mut nread = 0;
for buf in bufs {
let n = self.read(buf)?;
@@ -275,7 +275,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result<us
fn slice_write_vectored(
pos_mut: &mut u64,
slice: &mut [u8],
bufs: &[IoVec<'_>],
bufs: &[IoSlice<'_>],
) -> io::Result<usize>
{
let mut nwritten = 0;
@@ -319,7 +319,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usi
fn vec_write_vectored(
pos_mut: &mut u64,
vec: &mut Vec<u8>,
bufs: &[IoVec<'_>],
bufs: &[IoSlice<'_>],
) -> io::Result<usize>
{
let mut nwritten = 0;
@@ -337,7 +337,7 @@ impl Write for Cursor<&mut [u8]> {
}

#[inline]
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
slice_write_vectored(&mut self.pos, self.inner, bufs)
}

@@ -350,7 +350,7 @@ impl Write for Cursor<&mut Vec<u8>> {
vec_write(&mut self.pos, self.inner, buf)
}

fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
vec_write_vectored(&mut self.pos, self.inner, bufs)
}

@@ -363,7 +363,7 @@ impl Write for Cursor<Vec<u8>> {
vec_write(&mut self.pos, &mut self.inner, buf)
}

fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
vec_write_vectored(&mut self.pos, &mut self.inner, bufs)
}

@@ -378,7 +378,7 @@ impl Write for Cursor<Box<[u8]>> {
}

#[inline]
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
slice_write_vectored(&mut self.pos, &mut self.inner, bufs)
}

@@ -388,7 +388,7 @@ impl Write for Cursor<Box<[u8]>> {
#[cfg(test)]
mod tests {
use crate::io::prelude::*;
use crate::io::{Cursor, SeekFrom, IoVec, IoVecMut};
use crate::io::{Cursor, SeekFrom, IoSlice, IoSliceMut};

#[test]
fn test_vec_writer() {
@@ -397,7 +397,7 @@ mod tests {
assert_eq!(writer.write(&[1, 2, 3]).unwrap(), 3);
assert_eq!(writer.write(&[4, 5, 6, 7]).unwrap(), 4);
assert_eq!(writer.write_vectored(
&[IoVec::new(&[]), IoVec::new(&[8, 9]), IoVec::new(&[10])],
&[IoSlice::new(&[]), IoSlice::new(&[8, 9]), IoSlice::new(&[10])],
).unwrap(), 3);
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(writer, b);
@@ -410,7 +410,7 @@ mod tests {
assert_eq!(writer.write(&[1, 2, 3]).unwrap(), 3);
assert_eq!(writer.write(&[4, 5, 6, 7]).unwrap(), 4);
assert_eq!(writer.write_vectored(
&[IoVec::new(&[]), IoVec::new(&[8, 9]), IoVec::new(&[10])],
&[IoSlice::new(&[]), IoSlice::new(&[8, 9]), IoSlice::new(&[10])],
).unwrap(), 3);
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(&writer.get_ref()[..], b);
@@ -424,7 +424,7 @@ mod tests {
assert_eq!(writer.write(&[1, 2, 3]).unwrap(), 3);
assert_eq!(writer.write(&[4, 5, 6, 7]).unwrap(), 4);
assert_eq!(writer.write_vectored(
&[IoVec::new(&[]), IoVec::new(&[8, 9]), IoVec::new(&[10])],
&[IoSlice::new(&[]), IoSlice::new(&[8, 9]), IoSlice::new(&[10])],
).unwrap(), 3);
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(&writer.get_ref()[..], b);
@@ -452,18 +452,18 @@ mod tests {
fn test_box_slice_writer_vectored() {
let mut writer = Cursor::new(vec![0u8; 9].into_boxed_slice());
assert_eq!(writer.position(), 0);
assert_eq!(writer.write_vectored(&[IoVec::new(&[0])]).unwrap(), 1);
assert_eq!(writer.write_vectored(&[IoSlice::new(&[0])]).unwrap(), 1);
assert_eq!(writer.position(), 1);
assert_eq!(
writer.write_vectored(&[IoVec::new(&[1, 2, 3]), IoVec::new(&[4, 5, 6, 7])]).unwrap(),
writer.write_vectored(&[IoSlice::new(&[1, 2, 3]), IoSlice::new(&[4, 5, 6, 7])]).unwrap(),
7,
);
assert_eq!(writer.position(), 8);
assert_eq!(writer.write_vectored(&[]).unwrap(), 0);
assert_eq!(writer.position(), 8);

assert_eq!(writer.write_vectored(&[IoVec::new(&[8, 9])]).unwrap(), 1);
assert_eq!(writer.write_vectored(&[IoVec::new(&[10])]).unwrap(), 0);
assert_eq!(writer.write_vectored(&[IoSlice::new(&[8, 9])]).unwrap(), 1);
assert_eq!(writer.write_vectored(&[IoSlice::new(&[10])]).unwrap(), 0);
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8];
assert_eq!(&**writer.get_ref(), b);
}
@@ -495,20 +495,20 @@ mod tests {
{
let mut writer = Cursor::new(&mut buf[..]);
assert_eq!(writer.position(), 0);
assert_eq!(writer.write_vectored(&[IoVec::new(&[0])]).unwrap(), 1);
assert_eq!(writer.write_vectored(&[IoSlice::new(&[0])]).unwrap(), 1);
assert_eq!(writer.position(), 1);
assert_eq!(
writer.write_vectored(
&[IoVec::new(&[1, 2, 3]), IoVec::new(&[4, 5, 6, 7])],
&[IoSlice::new(&[1, 2, 3]), IoSlice::new(&[4, 5, 6, 7])],
).unwrap(),
7,
);
assert_eq!(writer.position(), 8);
assert_eq!(writer.write_vectored(&[]).unwrap(), 0);
assert_eq!(writer.position(), 8);

assert_eq!(writer.write_vectored(&[IoVec::new(&[8, 9])]).unwrap(), 1);
assert_eq!(writer.write_vectored(&[IoVec::new(&[10])]).unwrap(), 0);
assert_eq!(writer.write_vectored(&[IoSlice::new(&[8, 9])]).unwrap(), 1);
assert_eq!(writer.write_vectored(&[IoSlice::new(&[10])]).unwrap(), 0);
}
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8];
assert_eq!(buf, b);
@@ -578,11 +578,11 @@ mod tests {
fn test_mem_reader_vectored() {
let mut reader = Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7]);
let mut buf = [];
assert_eq!(reader.read_vectored(&mut [IoVecMut::new(&mut buf)]).unwrap(), 0);
assert_eq!(reader.read_vectored(&mut [IoSliceMut::new(&mut buf)]).unwrap(), 0);
assert_eq!(reader.position(), 0);
let mut buf = [0];
assert_eq!(
reader.read_vectored(&mut [IoVecMut::new(&mut []), IoVecMut::new(&mut buf)]).unwrap(),
reader.read_vectored(&mut [IoSliceMut::new(&mut []), IoSliceMut::new(&mut buf)]).unwrap(),
1,
);
assert_eq!(reader.position(), 1);
@@ -592,7 +592,7 @@ mod tests {
let mut buf2 = [0; 4];
assert_eq!(
reader.read_vectored(
&mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)],
&mut [IoSliceMut::new(&mut buf1), IoSliceMut::new(&mut buf2)],
).unwrap(),
7,
);
@@ -629,11 +629,11 @@ mod tests {
fn test_boxed_slice_reader_vectored() {
let mut reader = Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7].into_boxed_slice());
let mut buf = [];
assert_eq!(reader.read_vectored(&mut [IoVecMut::new(&mut buf)]).unwrap(), 0);
assert_eq!(reader.read_vectored(&mut [IoSliceMut::new(&mut buf)]).unwrap(), 0);
assert_eq!(reader.position(), 0);
let mut buf = [0];
assert_eq!(
reader.read_vectored(&mut [IoVecMut::new(&mut []), IoVecMut::new(&mut buf)]).unwrap(),
reader.read_vectored(&mut [IoSliceMut::new(&mut []), IoSliceMut::new(&mut buf)]).unwrap(),
1,
);
assert_eq!(reader.position(), 1);
@@ -643,7 +643,7 @@ mod tests {
let mut buf2 = [0; 4];
assert_eq!(
reader.read_vectored(
&mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)],
&mut [IoSliceMut::new(&mut buf1), IoSliceMut::new(&mut buf2)],
).unwrap(),
7,
);
@@ -689,10 +689,10 @@ mod tests {
let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7];
let reader = &mut &in_buf[..];
let mut buf = [];
assert_eq!(reader.read_vectored(&mut [IoVecMut::new(&mut buf)]).unwrap(), 0);
assert_eq!(reader.read_vectored(&mut [IoSliceMut::new(&mut buf)]).unwrap(), 0);
let mut buf = [0];
assert_eq!(
reader.read_vectored(&mut [IoVecMut::new(&mut []), IoVecMut::new(&mut buf)]).unwrap(),
reader.read_vectored(&mut [IoSliceMut::new(&mut []), IoSliceMut::new(&mut buf)]).unwrap(),
1,
);
assert_eq!(reader.len(), 7);
@@ -702,7 +702,7 @@ mod tests {
let mut buf2 = [0; 4];
assert_eq!(
reader.read_vectored(
&mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)],
&mut [IoSliceMut::new(&mut buf1), IoSliceMut::new(&mut buf2)],
).unwrap(),
7,
);
@@ -1,6 +1,6 @@
use crate::cmp;
use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut,
IoVec};
use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoSliceMut,
IoSlice};
use crate::fmt;
use crate::mem;

@@ -15,7 +15,7 @@ impl<R: Read + ?Sized> Read for &mut R {
}

#[inline]
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
(**self).read_vectored(bufs)
}

@@ -45,7 +45,7 @@ impl<W: Write + ?Sized> Write for &mut W {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }

#[inline]
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
(**self).write_vectored(bufs)
}

@@ -94,7 +94,7 @@ impl<R: Read + ?Sized> Read for Box<R> {
}

#[inline]
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
(**self).read_vectored(bufs)
}

@@ -124,7 +124,7 @@ impl<W: Write + ?Sized> Write for Box<W> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }

#[inline]
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
(**self).write_vectored(bufs)
}

@@ -207,7 +207,7 @@ impl Read for &[u8] {
}

#[inline]
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
let mut nread = 0;
for buf in bufs {
nread += self.read(buf)?;
@@ -280,7 +280,7 @@ impl Write for &mut [u8] {
}

#[inline]
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let mut nwritten = 0;
for buf in bufs {
nwritten += self.write(buf)?;
@@ -316,7 +316,7 @@ impl Write for Vec<u8> {
}

#[inline]
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let len = bufs.iter().map(|b| b.len()).sum();
self.reserve(len);
for buf in bufs {
Oops, something went wrong.

0 comments on commit bd177f3

Please sign in to comment.
You can’t perform that action at this time.