From 3be701cefb573341db74254f137a4d54aefa44ce Mon Sep 17 00:00:00 2001 From: quininer Date: Tue, 19 May 2020 11:57:14 +0800 Subject: [PATCH] Fix place wrong for process_new_packets (#14) The `wants_read` only changes after `process_new_packets`, which means that not immediately calling `process_new_packets` may cause rustls to cache too much data. --- tokio-rustls/Cargo.toml | 2 +- tokio-rustls/src/common/mod.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tokio-rustls/Cargo.toml b/tokio-rustls/Cargo.toml index c1cb01f..c0ffab1 100644 --- a/tokio-rustls/Cargo.toml +++ b/tokio-rustls/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tokio-rustls" -version = "0.13.0" +version = "0.13.1" authors = ["quininer kel "] license = "MIT/Apache-2.0" repository = "https://github.com/tokio-rs/tls" diff --git a/tokio-rustls/src/common/mod.rs b/tokio-rustls/src/common/mod.rs index 778fa92..53ed976 100644 --- a/tokio-rustls/src/common/mod.rs +++ b/tokio-rustls/src/common/mod.rs @@ -218,7 +218,10 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> { while !self.eof && self.session.wants_read() { match self.read_io(cx) { Poll::Ready(Ok(0)) => self.eof = true, - Poll::Ready(Ok(n)) => rdlen += n, + Poll::Ready(Ok(n)) => { + rdlen += n; + self.process_new_packets(cx)?; + } Poll::Pending => { read_would_block = true; break; @@ -227,8 +230,6 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> { } } - self.process_new_packets(cx)?; - return match (self.eof, self.session.is_handshaking()) { (true, true) => { let err = io::Error::new(io::ErrorKind::UnexpectedEof, "tls handshake eof"); @@ -266,7 +267,7 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> AsyncRead for Stream<'a self.eof = true; break; } - Poll::Ready(Ok(_)) => (), + Poll::Ready(Ok(_)) => self.process_new_packets(cx)?, Poll::Pending => { would_block = true; break; @@ -275,8 +276,6 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> AsyncRead for Stream<'a } } - self.process_new_packets(cx)?; - return match self.session.read(&mut buf[pos..]) { Ok(0) if pos == 0 && would_block => Poll::Pending, Ok(n) if self.eof || would_block => Poll::Ready(Ok(pos + n)),