diff --git a/tokio-rustls/Cargo.toml b/tokio-rustls/Cargo.toml index b63bf86..0cfb0f5 100644 --- a/tokio-rustls/Cargo.toml +++ b/tokio-rustls/Cargo.toml @@ -12,7 +12,7 @@ categories = ["asynchronous", "cryptography", "network-programming"] edition = "2018" [dependencies] -tokio = "0.3" +tokio = "0.3.5" rustls = "0.19" webpki = "0.21" @@ -21,7 +21,7 @@ early-data = [] dangerous_configuration = ["rustls/dangerous_configuration"] [dev-dependencies] -tokio = { version = "0.3", features = ["full"] } +tokio = { version = "0.3.5", features = ["full"] } futures-util = "0.3.1" lazy_static = "1" webpki-roots = "0.21" diff --git a/tokio-rustls/src/common/mod.rs b/tokio-rustls/src/common/mod.rs index 2a2d3e1..a7b9fa6 100644 --- a/tokio-rustls/src/common/mod.rs +++ b/tokio-rustls/src/common/mod.rs @@ -2,7 +2,7 @@ mod handshake; pub(crate) use handshake::{IoSession, MidHandshake}; use rustls::Session; -use std::io::{self, Read, Write}; +use std::io::{self, IoSlice, Read, Write}; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; @@ -127,20 +127,32 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> { cx: &'a mut Context<'b>, } - impl<'a, 'b, T: AsyncWrite + Unpin> Write for Writer<'a, 'b, T> { + impl<'a, 'b, T: Unpin> Writer<'a, 'b, T> { #[inline] - fn write(&mut self, buf: &[u8]) -> io::Result { - match Pin::new(&mut self.io).poll_write(self.cx, buf) { + fn poll_with( + &mut self, + f: impl FnOnce(Pin<&mut T>, &mut Context<'_>) -> Poll>, + ) -> io::Result { + match f(Pin::new(&mut self.io), self.cx) { Poll::Ready(result) => result, Poll::Pending => Err(io::ErrorKind::WouldBlock.into()), } } + } + + impl<'a, 'b, T: AsyncWrite + Unpin> Write for Writer<'a, 'b, T> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + self.poll_with(|io, cx| io.poll_write(cx, buf)) + } + + #[inline] + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { + self.poll_with(|io, cx| io.poll_write_vectored(cx, bufs)) + } fn flush(&mut self) -> io::Result<()> { - match Pin::new(&mut self.io).poll_flush(self.cx) { - Poll::Ready(result) => result, - Poll::Pending => Err(io::ErrorKind::WouldBlock.into()), - } + self.poll_with(|io, cx| io.poll_flush(cx)) } }