diff options
| author | Steven Fackler <sfackler@gmail.com> | 2020-01-03 11:26:05 -0800 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2020-04-26 04:23:39 -0700 |
| commit | 15262ec6be6fcfc9f27e174a0714d5a62e775fb0 (patch) | |
| tree | a962ae80ff3cbdb331c76426c200cdec0d82219c /src/libstd/sys/sgx | |
| parent | 019ab732ce63a117cbb446db1488916c5c0bd2a7 (diff) | |
| download | rust-15262ec6be6fcfc9f27e174a0714d5a62e775fb0.tar.gz rust-15262ec6be6fcfc9f27e174a0714d5a62e775fb0.zip | |
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/sgx')
| -rw-r--r-- | src/libstd/sys/sgx/fd.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/fs.rs | 8 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/net.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/pipe.rs | 8 |
4 files changed, 36 insertions, 0 deletions
diff --git a/src/libstd/sys/sgx/fd.rs b/src/libstd/sys/sgx/fd.rs index 7da2424a642..6cc7adde4d1 100644 --- a/src/libstd/sys/sgx/fd.rs +++ b/src/libstd/sys/sgx/fd.rs @@ -34,6 +34,11 @@ impl FileDesc { usercalls::read(self.fd, bufs) } + #[inline] + pub fn can_read_vectored(&self) -> bool { + true + } + pub fn write(&self, buf: &[u8]) -> io::Result<usize> { usercalls::write(self.fd, &[IoSlice::new(buf)]) } @@ -42,6 +47,11 @@ impl FileDesc { usercalls::write(self.fd, bufs) } + #[inline] + pub fn can_write_vectored(&self) -> bool { + true + } + pub fn flush(&self) -> io::Result<()> { usercalls::flush(self.fd) } diff --git a/src/libstd/sys/sgx/fs.rs b/src/libstd/sys/sgx/fs.rs index e6160d1457d..e34483447e9 100644 --- a/src/libstd/sys/sgx/fs.rs +++ b/src/libstd/sys/sgx/fs.rs @@ -202,6 +202,10 @@ impl File { 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 {} } @@ -210,6 +214,10 @@ impl File { match self.0 {} } + pub fn can_write_vectored(&self) -> bool { + match self.0 {} + } + pub fn flush(&self) -> io::Result<()> { match self.0 {} } diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs index bd0652ab464..12a9a1289df 100644 --- a/src/libstd/sys/sgx/net.rs +++ b/src/libstd/sys/sgx/net.rs @@ -149,6 +149,11 @@ impl TcpStream { self.inner.inner.read_vectored(bufs) } + #[inline] + pub fn can_read_vectored(&self) -> bool { + self.inner.inner.can_read_vectored() + } + pub fn write(&self, buf: &[u8]) -> io::Result<usize> { self.inner.inner.write(buf) } @@ -157,6 +162,11 @@ impl TcpStream { self.inner.inner.write_vectored(bufs) } + #[inline] + pub fn can_write_vectored(&self) -> bool { + self.inner.inner.can_write_vectored() + } + pub fn peer_addr(&self) -> io::Result<SocketAddr> { addr_to_sockaddr(&self.peer_addr) } diff --git a/src/libstd/sys/sgx/pipe.rs b/src/libstd/sys/sgx/pipe.rs index fb14dc59101..eed8d1fdd56 100644 --- a/src/libstd/sys/sgx/pipe.rs +++ b/src/libstd/sys/sgx/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 {} } |
