about summary refs log tree commit diff
path: root/src/libstd/sys/hermit
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2020-01-03 11:26:05 -0800
committerSteven Fackler <sfackler@gmail.com>2020-04-26 04:23:39 -0700
commit15262ec6be6fcfc9f27e174a0714d5a62e775fb0 (patch)
treea962ae80ff3cbdb331c76426c200cdec0d82219c /src/libstd/sys/hermit
parent019ab732ce63a117cbb446db1488916c5c0bd2a7 (diff)
Add Read/Write::can_read/write_vectored
When working with an arbitrary reader or writer, code that uses vectored
operations may end up being slower than code that copies into a single
buffer when the underlying reader or writer doesn't actually support
vectored operations. These new methods allow you to ask the reader or
witer up front if vectored operations are efficiently supported.

Currently, you have to use some heuristics to guess by e.g. checking if
the read or write only accessed the first buffer. Hyper is one concrete
example of a library that has to do this dynamically:
https://github.com/hyperium/hyper/blob/0eaf304644a396895a4ce1f0146e596640bb666a/src/proto/h1/io.rs#L582-L594
Diffstat (limited to 'src/libstd/sys/hermit')
-rw-r--r--src/libstd/sys/hermit/fs.rs10
-rw-r--r--src/libstd/sys/hermit/net.rs10
-rw-r--r--src/libstd/sys/hermit/pipe.rs8
-rw-r--r--src/libstd/sys/hermit/stdio.rs15
4 files changed, 43 insertions, 0 deletions
diff --git a/src/libstd/sys/hermit/fs.rs b/src/libstd/sys/hermit/fs.rs
index 287a0390667..8d9a359f94b 100644
--- a/src/libstd/sys/hermit/fs.rs
+++ b/src/libstd/sys/hermit/fs.rs
@@ -301,6 +301,11 @@ impl File {
         crate::io::default_read_vectored(|buf| self.read(buf), bufs)
     }
 
+    #[inline]
+    pub fn can_read_vectored(&self) -> bool {
+        false
+    }
+
     pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
         self.0.write(buf)
     }
@@ -309,6 +314,11 @@ impl File {
         crate::io::default_write_vectored(|buf| self.write(buf), bufs)
     }
 
+    #[inline]
+    pub fn can_write_vectored(&self) -> bool {
+        false
+    }
+
     pub fn flush(&self) -> io::Result<()> {
         Ok(())
     }
diff --git a/src/libstd/sys/hermit/net.rs b/src/libstd/sys/hermit/net.rs
index 377c3132c5a..a8a82dba62e 100644
--- a/src/libstd/sys/hermit/net.rs
+++ b/src/libstd/sys/hermit/net.rs
@@ -99,6 +99,11 @@ impl TcpStream {
         Ok(size)
     }
 
+    #[inline]
+    pub fn can_read_vectored(&self) -> bool {
+        true
+    }
+
     pub fn write(&self, buffer: &[u8]) -> io::Result<usize> {
         self.write_vectored(&[IoSlice::new(buffer)])
     }
@@ -114,6 +119,11 @@ impl TcpStream {
         Ok(size)
     }
 
+    #[inline]
+    pub fn can_write_vectored(&self) -> bool {
+        true
+    }
+
     pub fn peer_addr(&self) -> io::Result<SocketAddr> {
         Err(io::Error::new(ErrorKind::Other, "peer_addr isn't supported"))
     }
diff --git a/src/libstd/sys/hermit/pipe.rs b/src/libstd/sys/hermit/pipe.rs
index fb14dc59101..eed8d1fdd56 100644
--- a/src/libstd/sys/hermit/pipe.rs
+++ b/src/libstd/sys/hermit/pipe.rs
@@ -12,6 +12,10 @@ impl AnonPipe {
         match self.0 {}
     }
 
+    pub fn can_read_vectored(&self) -> bool {
+        match self.0 {}
+    }
+
     pub fn write(&self, _buf: &[u8]) -> io::Result<usize> {
         match self.0 {}
     }
@@ -20,6 +24,10 @@ impl AnonPipe {
         match self.0 {}
     }
 
+    pub fn can_write_vectored(&self) -> bool {
+        match self.0 {}
+    }
+
     pub fn diverge(&self) -> ! {
         match self.0 {}
     }
diff --git a/src/libstd/sys/hermit/stdio.rs b/src/libstd/sys/hermit/stdio.rs
index 2eb011ccb39..ba72775e145 100644
--- a/src/libstd/sys/hermit/stdio.rs
+++ b/src/libstd/sys/hermit/stdio.rs
@@ -20,6 +20,11 @@ impl Stdin {
         //    .read(data)
         Ok(0)
     }
+
+    #[inline]
+    pub fn can_read_vectored(&self) -> bool {
+        true
+    }
 }
 
 impl Stdout {
@@ -51,6 +56,11 @@ impl Stdout {
         }
     }
 
+    #[inline]
+    pub fn can_write_vectored(&self) -> bool {
+        true
+    }
+
     pub fn flush(&self) -> io::Result<()> {
         Ok(())
     }
@@ -85,6 +95,11 @@ impl Stderr {
         }
     }
 
+    #[inline]
+    pub fn can_write_vectored(&self) -> bool {
+        true
+    }
+
     pub fn flush(&self) -> io::Result<()> {
         Ok(())
     }