about summary refs log tree commit diff
path: root/src/libstd/sys/cloudabi
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2019-02-08 20:42:34 +0100
committerSteven Fackler <sfackler@gmail.com>2019-02-13 19:40:17 -0800
commit31bcec648aa57391115f877a2ca022d7ff6415aa (patch)
tree2e9ba98a3146cb8eebf72d469a81615389edd4fd /src/libstd/sys/cloudabi
parent4772dc8087b1d0f2bab6d064fd930e596c82d439 (diff)
downloadrust-31bcec648aa57391115f877a2ca022d7ff6415aa.tar.gz
rust-31bcec648aa57391115f877a2ca022d7ff6415aa.zip
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.
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
2 files changed, 50 insertions, 18 deletions
diff --git a/src/libstd/sys/cloudabi/io.rs b/src/libstd/sys/cloudabi/io.rs
new file mode 100644
index 00000000000..9ee5788c580
--- /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) -> &'a [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) -> &'a [u8] {
+        self.0
+    }
+
+    #[inline]
+    pub fn as_mut_slice(&mut self) -> &'a 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,
     }
 }