add read_bufs and write_bufs to Io and TcpStream

This commit is contained in:
Sean McArthur
2017-01-27 11:32:08 -08:00
parent a4b4d57cb7
commit 829563ccfc
2 changed files with 85 additions and 0 deletions
+32
View File
@@ -433,6 +433,38 @@ impl Io for TcpStream {
fn poll_write(&mut self) -> Async<()> {
<TcpStream>::poll_write(self)
}
fn read_vec(&mut self, bufs: &mut [&mut mio::IoVec]) -> io::Result<usize> {
if let Async::NotReady = self.poll_read() {
return Err(mio::would_block())
}
let r = self.io.get_ref().read_bufs(bufs);
if is_wouldblock(&r) {
self.io.need_read();
}
return r
}
fn write_vec(&mut self, bufs: &[&mio::IoVec]) -> io::Result<usize> {
if let Async::NotReady = self.poll_write() {
return Err(mio::would_block())
}
let r = self.io.get_ref().write_bufs(bufs);
if is_wouldblock(&r) {
self.io.need_write();
}
return r
}
}
fn is_wouldblock<T>(r: &io::Result<T>) -> bool {
match *r {
Ok(_) => false,
Err(ref e) => e.kind() == io::ErrorKind::WouldBlock,
}
}
impl<'a> Read for &'a TcpStream {