fix early-data read

This commit is contained in:
quininer 2019-03-26 10:44:38 +08:00
parent ee59a7cc8e
commit d8ab52db55
2 changed files with 36 additions and 30 deletions

View File

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

View File

@ -79,13 +79,13 @@ impl<IO> io::Read for TlsStream<IO>
where IO: AsyncRead + AsyncWrite
{
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut stream = Stream::new(&mut self.io, &mut self.session);
match self.state {
#[cfg(feature = "early-data")]
TlsState::EarlyData => {
use std::io::Write;
{
let mut stream = Stream::new(&mut self.io, &mut self.session);
let (pos, data) = &mut self.early_data;
// complete handshake
@ -104,9 +104,14 @@ where IO: AsyncRead + AsyncWrite
// end
self.state = TlsState::Stream;
data.clear();
stream.read(buf)
}
self.read(buf)
},
TlsState::Stream => match stream.read(buf) {
TlsState::Stream => {
let mut stream = Stream::new(&mut self.io, &mut self.session);
match stream.read(buf) {
Ok(0) => {
self.state = TlsState::Eof;
Ok(0)
@ -118,6 +123,7 @@ where IO: AsyncRead + AsyncWrite
Ok(0)
},
Err(e) => Err(e)
}
},
TlsState::Eof | TlsState::Shutdown => Ok(0),
}