From 681cbe68caadc07b6208d08812c781bb073becfe Mon Sep 17 00:00:00 2001 From: quininer Date: Sat, 23 Feb 2019 01:38:55 +0800 Subject: [PATCH] fix: not write zero --- src/client.rs | 8 +++----- src/common/mod.rs | 8 +++++++- src/lib.rs | 2 ++ src/server.rs | 8 +++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/client.rs b/src/client.rs index 8d6758e..386d242 100644 --- a/src/client.rs +++ b/src/client.rs @@ -187,10 +187,8 @@ where IO: AsyncRead + AsyncWrite } } - { - let mut stream = Stream::new(&mut self.io, &mut self.session); - try_nb!(stream.complete_io()); - } - self.io.shutdown() + let mut stream = Stream::new(&mut self.io, &mut self.session); + try_nb!(stream.complete_io()); + stream.io.shutdown() } } diff --git a/src/common/mod.rs b/src/common/mod.rs index 9010d8d..a88a278 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -110,7 +110,13 @@ impl<'a, IO: AsyncRead + AsyncWrite, S: Session> Write for Stream<'a, IO, S> { Err(err) => return Err(err) } } - Ok(len) + + if len == 0 && !buf.is_empty() { + // not write zero + Err(io::ErrorKind::WouldBlock.into()) + } else { + Ok(len) + } } fn flush(&mut self) -> io::Result<()> { diff --git a/src/lib.rs b/src/lib.rs index 446e80d..511cdd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,12 +24,14 @@ use tokio_io::{ AsyncRead, AsyncWrite, try_nb }; use common::Stream; +/// A wrapper around a `rustls::ClientConfig`, providing an async `connect` method. #[derive(Clone)] pub struct TlsConnector { inner: Arc, early_data: bool } +/// A wrapper around a `rustls::ServerConfig`, providing an async `accept` method. #[derive(Clone)] pub struct TlsAcceptor { inner: Arc diff --git a/src/server.rs b/src/server.rs index 42dd18d..fd02a35 100644 --- a/src/server.rs +++ b/src/server.rs @@ -130,10 +130,8 @@ where IO: AsyncRead + AsyncWrite, } } - { - let mut stream = Stream::new(&mut self.io, &mut self.session); - try_nb!(stream.complete_io()); - } - self.io.shutdown() + let mut stream = Stream::new(&mut self.io, &mut self.session); + try_nb!(stream.complete_io()); + stream.io.shutdown() } }