stream: implement write_vectored

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
This commit is contained in:
Marc-Antoine Perennou 2020-04-20 14:09:07 +02:00 committed by ctz
parent 68c276b97c
commit 2912dbffde
3 changed files with 32 additions and 3 deletions

View File

@ -18,7 +18,7 @@ use crate::vecbuf::WriteV;
use crate::log::trace;
use std::sync::Arc;
use std::io;
use std::io::{self, IoSlice};
use std::fmt;
use std::mem;
@ -742,6 +742,14 @@ impl io::Write for ClientSession {
self.imp.send_some_plaintext(buf)
}
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let mut sz = 0;
for buf in bufs {
sz += self.imp.send_some_plaintext(buf)?;
}
Ok(sz)
}
fn flush(&mut self) -> io::Result<()> {
self.imp.common.flush_plaintext();
Ok(())

View File

@ -17,7 +17,7 @@ use crate::log::trace;
use webpki;
use std::sync::Arc;
use std::io;
use std::io::{self, IoSlice};
use std::fmt;
#[macro_use]
@ -652,6 +652,14 @@ impl io::Write for ServerSession {
self.imp.send_some_plaintext(buf)
}
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let mut sz = 0;
for buf in bufs {
sz += self.imp.send_some_plaintext(buf)?;
}
Ok(sz)
}
fn flush(&mut self) -> io::Result<()> {
self.imp.common.flush_plaintext();
Ok(())

View File

@ -1,4 +1,4 @@
use std::io::{Read, Write, Result};
use std::io::{IoSlice, Read, Write, Result};
use crate::session::Session;
/// This type implements `io::Read` and `io::Write`, encapsulating
@ -68,6 +68,19 @@ impl<'a, S, T> Write for Stream<'a, S, T> where S: 'a + Session, T: 'a + Read +
Ok(len)
}
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize> {
self.complete_prior_io()?;
let len = self.sess.write_vectored(bufs)?;
// Try to write the underlying transport here, but don't let
// any errors mask the fact we've consumed `len` bytes.
// Callers will learn of permanent errors on the next call.
let _ = self.sess.complete_io(self.sock);
Ok(len)
}
fn flush(&mut self) -> Result<()> {
self.complete_prior_io()?;