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.
This commit is contained in:
quininer 2020-05-19 11:57:14 +08:00 committed by GitHub
parent 3c9b126993
commit 3be701cefb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "tokio-rustls" name = "tokio-rustls"
version = "0.13.0" version = "0.13.1"
authors = ["quininer kel <quininer@live.com>"] authors = ["quininer kel <quininer@live.com>"]
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
repository = "https://github.com/tokio-rs/tls" repository = "https://github.com/tokio-rs/tls"

View File

@ -218,7 +218,10 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> {
while !self.eof && self.session.wants_read() { while !self.eof && self.session.wants_read() {
match self.read_io(cx) { match self.read_io(cx) {
Poll::Ready(Ok(0)) => self.eof = true, 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 => { Poll::Pending => {
read_would_block = true; read_would_block = true;
break; 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()) { return match (self.eof, self.session.is_handshaking()) {
(true, true) => { (true, true) => {
let err = io::Error::new(io::ErrorKind::UnexpectedEof, "tls handshake eof"); 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; self.eof = true;
break; break;
} }
Poll::Ready(Ok(_)) => (), Poll::Ready(Ok(_)) => self.process_new_packets(cx)?,
Poll::Pending => { Poll::Pending => {
would_block = true; would_block = true;
break; 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..]) { return match self.session.read(&mut buf[pos..]) {
Ok(0) if pos == 0 && would_block => Poll::Pending, Ok(0) if pos == 0 && would_block => Poll::Pending,
Ok(n) if self.eof || would_block => Poll::Ready(Ok(pos + n)), Ok(n) if self.eof || would_block => Poll::Ready(Ok(pos + n)),