1
Fork 0

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:
0eaf304644/src/proto/h1/io.rs (L582-L594)
This commit is contained in:
Steven Fackler 2020-01-03 11:26:05 -08:00
parent 019ab732ce
commit 15262ec6be
43 changed files with 556 additions and 0 deletions

View file

@ -226,6 +226,11 @@ impl Socket {
self.0.read_vectored(bufs)
}
#[inline]
pub fn can_read_vectored(&self) -> bool {
self.0.can_read_vectored()
}
fn recv_from_with_flags(
&self,
buf: &mut [u8],
@ -263,6 +268,11 @@ impl Socket {
self.0.write_vectored(bufs)
}
#[inline]
pub fn can_write_vectored(&self) -> bool {
self.0.can_write_vectored()
}
pub fn set_timeout(&self, dur: Option<Duration>, kind: libc::c_int) -> io::Result<()> {
let timeout = match dur {
Some(dur) => {