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/unix/ext | |
| 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/unix/ext')
| -rw-r--r-- | src/libstd/sys/unix/ext/net.rs | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 4c3cb67c9ee..60ec73d9de2 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -614,6 +614,11 @@ impl io::Read for UnixStream { } #[inline] + fn can_read_vectored(&self) -> bool { + io::Read::can_read_vectored(&&*self) + } + + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() } @@ -630,6 +635,11 @@ impl<'a> io::Read for &'a UnixStream { } #[inline] + fn can_read_vectored(&self) -> bool { + self.0.can_read_vectored() + } + + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() } @@ -645,6 +655,11 @@ impl io::Write for UnixStream { io::Write::write_vectored(&mut &*self, bufs) } + #[inline] + fn can_write_vectored(&self) -> bool { + io::Write::can_write_vectored(&&*self) + } + fn flush(&mut self) -> io::Result<()> { io::Write::flush(&mut &*self) } @@ -660,6 +675,11 @@ impl<'a> io::Write for &'a UnixStream { self.0.write_vectored(bufs) } + #[inline] + fn can_write_vectored(&self) -> bool { + self.0.can_write_vectored() + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } | 
