fix early-data read
This commit is contained in:
parent
ee59a7cc8e
commit
d8ab52db55
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tokio-rustls"
|
name = "tokio-rustls"
|
||||||
version = "0.10.0-alpha"
|
version = "0.10.0-alpha.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/quininer/tokio-rustls"
|
repository = "https://github.com/quininer/tokio-rustls"
|
||||||
|
@ -79,45 +79,51 @@ impl<IO> io::Read for TlsStream<IO>
|
|||||||
where IO: AsyncRead + AsyncWrite
|
where IO: AsyncRead + AsyncWrite
|
||||||
{
|
{
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
let mut stream = Stream::new(&mut self.io, &mut self.session);
|
|
||||||
|
|
||||||
match self.state {
|
match self.state {
|
||||||
#[cfg(feature = "early-data")]
|
#[cfg(feature = "early-data")]
|
||||||
TlsState::EarlyData => {
|
TlsState::EarlyData => {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
let (pos, data) = &mut self.early_data;
|
{
|
||||||
|
let mut stream = Stream::new(&mut self.io, &mut self.session);
|
||||||
|
let (pos, data) = &mut self.early_data;
|
||||||
|
|
||||||
// complete handshake
|
// complete handshake
|
||||||
if stream.session.is_handshaking() {
|
if stream.session.is_handshaking() {
|
||||||
stream.complete_io()?;
|
stream.complete_io()?;
|
||||||
}
|
|
||||||
|
|
||||||
// write early data (fallback)
|
|
||||||
if !stream.session.is_early_data_accepted() {
|
|
||||||
while *pos < data.len() {
|
|
||||||
let len = stream.write(&data[*pos..])?;
|
|
||||||
*pos += len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write early data (fallback)
|
||||||
|
if !stream.session.is_early_data_accepted() {
|
||||||
|
while *pos < data.len() {
|
||||||
|
let len = stream.write(&data[*pos..])?;
|
||||||
|
*pos += len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// end
|
||||||
|
self.state = TlsState::Stream;
|
||||||
|
data.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// end
|
self.read(buf)
|
||||||
self.state = TlsState::Stream;
|
|
||||||
data.clear();
|
|
||||||
stream.read(buf)
|
|
||||||
},
|
},
|
||||||
TlsState::Stream => match stream.read(buf) {
|
TlsState::Stream => {
|
||||||
Ok(0) => {
|
let mut stream = Stream::new(&mut self.io, &mut self.session);
|
||||||
self.state = TlsState::Eof;
|
|
||||||
Ok(0)
|
match stream.read(buf) {
|
||||||
},
|
Ok(0) => {
|
||||||
Ok(n) => Ok(n),
|
self.state = TlsState::Eof;
|
||||||
Err(ref e) if e.kind() == io::ErrorKind::ConnectionAborted => {
|
Ok(0)
|
||||||
self.state = TlsState::Shutdown;
|
},
|
||||||
stream.session.send_close_notify();
|
Ok(n) => Ok(n),
|
||||||
Ok(0)
|
Err(ref e) if e.kind() == io::ErrorKind::ConnectionAborted => {
|
||||||
},
|
self.state = TlsState::Shutdown;
|
||||||
Err(e) => Err(e)
|
stream.session.send_close_notify();
|
||||||
|
Ok(0)
|
||||||
|
},
|
||||||
|
Err(e) => Err(e)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
TlsState::Eof | TlsState::Shutdown => Ok(0),
|
TlsState::Eof | TlsState::Shutdown => Ok(0),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user