about summary refs log tree commit diff
path: root/src/libstd/sys/cloudabi
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-02-26 02:48:13 +0000
committerbors <bors@rust-lang.org>2019-02-26 02:48:13 +0000
commitfb162e69449b423c5aed0d9c39f6c046fa300c30 (patch)
tree5d4292df6a7db1b62137c4472f1e65317d3919e1 /src/libstd/sys/cloudabi
parent55c173c8ae8bda689fd609f391ee5e2e5b1b6d44 (diff)
parent4785c748f2190440fb3f90b5319f121f2d31e0e4 (diff)
downloadrust-fb162e69449b423c5aed0d9c39f6c046fa300c30.tar.gz
rust-fb162e69449b423c5aed0d9c39f6c046fa300c30.zip
Auto merge of #58357 - sfackler:vectored-io, r=alexcrichton
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.

r? @alexcrichton
Diffstat (limited to 'src/libstd/sys/cloudabi')
-rw-r--r--src/libstd/sys/cloudabi/io.rs32
-rw-r--r--src/libstd/sys/cloudabi/mod.rs36
-rw-r--r--src/libstd/sys/cloudabi/shims/net.rs10
3 files changed, 59 insertions, 19 deletions
diff --git a/src/libstd/sys/cloudabi/io.rs b/src/libstd/sys/cloudabi/io.rs
new file mode 100644
index 00000000000..8b02d3fd19d
--- /dev/null
+++ b/src/libstd/sys/cloudabi/io.rs
@@ -0,0 +1,32 @@
+pub struct IoVec<'a>(&'a [u8]);
+
+impl<'a> IoVec<'a> {
+    #[inline]
+    pub fn new(buf: &'a [u8]) -> IoVec<'a> {
+        IoVec(buf)
+    }
+
+    #[inline]
+    pub fn as_slice(&self) -> &[u8] {
+        self.0
+    }
+}
+
+pub struct IoVecMut<'a>(&'a mut [u8]);
+
+impl<'a> IoVecMut<'a> {
+    #[inline]
+    pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> {
+        IoVecMut(buf)
+    }
+
+    #[inline]
+    pub fn as_slice(&self) -> &[u8] {
+        self.0
+    }
+
+    #[inline]
+    pub fn as_mut_slice(&mut self) -> &mut [u8] {
+        self.0
+    }
+}
diff --git a/src/libstd/sys/cloudabi/mod.rs b/src/libstd/sys/cloudabi/mod.rs
index cd621b76945..d9bc21861c9 100644
--- a/src/libstd/sys/cloudabi/mod.rs
+++ b/src/libstd/sys/cloudabi/mod.rs
@@ -1,4 +1,3 @@
-use io;
 use libc;
 use mem;
 
@@ -10,6 +9,7 @@ pub mod backtrace;
 #[path = "../unix/cmath.rs"]
 pub mod cmath;
 pub mod condvar;
+pub mod io;
 #[path = "../unix/memchr.rs"]
 pub mod memchr;
 pub mod mutex;
@@ -32,24 +32,24 @@ pub use self::shims::*;
 #[allow(dead_code)]
 pub fn init() {}
 
-pub fn decode_error_kind(errno: i32) -> io::ErrorKind {
+pub fn decode_error_kind(errno: i32) -> ::io::ErrorKind {
     match errno {
-        x if x == abi::errno::ACCES as i32 => io::ErrorKind::PermissionDenied,
-        x if x == abi::errno::ADDRINUSE as i32 => io::ErrorKind::AddrInUse,
-        x if x == abi::errno::ADDRNOTAVAIL as i32 => io::ErrorKind::AddrNotAvailable,
-        x if x == abi::errno::AGAIN as i32 => io::ErrorKind::WouldBlock,
-        x if x == abi::errno::CONNABORTED as i32 => io::ErrorKind::ConnectionAborted,
-        x if x == abi::errno::CONNREFUSED as i32 => io::ErrorKind::ConnectionRefused,
-        x if x == abi::errno::CONNRESET as i32 => io::ErrorKind::ConnectionReset,
-        x if x == abi::errno::EXIST as i32 => io::ErrorKind::AlreadyExists,
-        x if x == abi::errno::INTR as i32 => io::ErrorKind::Interrupted,
-        x if x == abi::errno::INVAL as i32 => io::ErrorKind::InvalidInput,
-        x if x == abi::errno::NOENT as i32 => io::ErrorKind::NotFound,
-        x if x == abi::errno::NOTCONN as i32 => io::ErrorKind::NotConnected,
-        x if x == abi::errno::PERM as i32 => io::ErrorKind::PermissionDenied,
-        x if x == abi::errno::PIPE as i32 => io::ErrorKind::BrokenPipe,
-        x if x == abi::errno::TIMEDOUT as i32 => io::ErrorKind::TimedOut,
-        _ => io::ErrorKind::Other,
+        x if x == abi::errno::ACCES as i32 => ::io::ErrorKind::PermissionDenied,
+        x if x == abi::errno::ADDRINUSE as i32 => ::io::ErrorKind::AddrInUse,
+        x if x == abi::errno::ADDRNOTAVAIL as i32 => ::io::ErrorKind::AddrNotAvailable,
+        x if x == abi::errno::AGAIN as i32 => ::io::ErrorKind::WouldBlock,
+        x if x == abi::errno::CONNABORTED as i32 => ::io::ErrorKind::ConnectionAborted,
+        x if x == abi::errno::CONNREFUSED as i32 => ::io::ErrorKind::ConnectionRefused,
+        x if x == abi::errno::CONNRESET as i32 => ::io::ErrorKind::ConnectionReset,
+        x if x == abi::errno::EXIST as i32 => ::io::ErrorKind::AlreadyExists,
+        x if x == abi::errno::INTR as i32 => ::io::ErrorKind::Interrupted,
+        x if x == abi::errno::INVAL as i32 => ::io::ErrorKind::InvalidInput,
+        x if x == abi::errno::NOENT as i32 => ::io::ErrorKind::NotFound,
+        x if x == abi::errno::NOTCONN as i32 => ::io::ErrorKind::NotConnected,
+        x if x == abi::errno::PERM as i32 => ::io::ErrorKind::PermissionDenied,
+        x if x == abi::errno::PIPE as i32 => ::io::ErrorKind::BrokenPipe,
+        x if x == abi::errno::TIMEDOUT as i32 => ::io::ErrorKind::TimedOut,
+        _ => ::io::ErrorKind::Other,
     }
 }
 
diff --git a/src/libstd/sys/cloudabi/shims/net.rs b/src/libstd/sys/cloudabi/shims/net.rs
index b4caa899a75..869a0ef87a7 100644
--- a/src/libstd/sys/cloudabi/shims/net.rs
+++ b/src/libstd/sys/cloudabi/shims/net.rs
@@ -1,5 +1,5 @@
 use fmt;
-use io;
+use io::{self, IoVec, IoVecMut};
 use net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr};
 use time::Duration;
 use sys::{unsupported, Void};
@@ -42,10 +42,18 @@ impl TcpStream {
         match self.0 {}
     }
 
+    pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result<usize> {
+        match self.0 {}
+    }
+
     pub fn write(&self, _: &[u8]) -> io::Result<usize> {
         match self.0 {}
     }
 
+    pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result<usize> {
+        match self.0 {}
+    }
+
     pub fn peer_addr(&self) -> io::Result<SocketAddr> {
         match self.0 {}
     }