From 3d5a36590d21a1163558f81c17fde95fa77f53ae Mon Sep 17 00:00:00 2001 From: quininer kel Date: Fri, 14 Apr 2017 12:43:03 +0800 Subject: [PATCH] [Fixed] shutdown should only flush io --- Cargo.toml | 2 +- README.md | 4 ++-- examples/client.rs | 2 +- examples/server.rs | 6 +++--- src/lib.rs | 7 +++++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ace27ad..8343c6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tokio-rustls" -version = "0.1.6" +version = "0.1.7" authors = ["quininer kel "] license = "MIT/Apache-2.0" repository = "https://github.com/quininer/tokio-rustls" diff --git a/README.md b/README.md index d229186..4003d57 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ Asynchronous TLS/SSL streams for [Tokio](https://tokio.rs/) using ### Basic Structure of a Client ```rust -// ... - use rustls::ClientConfig; use tokio_rustls::ClientConfigExt; +// ... + let mut config = ClientConfig::new(); config.root_store.add_trust_anchors(&webpki_roots::ROOTS); let config = Arc::new(config); diff --git a/examples/client.rs b/examples/client.rs index 6ccafc9..cfc5bca 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -78,7 +78,7 @@ fn main() { #[cfg(unix)] let stdin = File::new_nb(StdFile(stdin.lock())).unwrap() .into_io(&handle).unwrap(); - + #[cfg(unix)] let stdout = stdout(); diff --git a/examples/server.rs b/examples/server.rs index 5d27474..89a049f 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -63,7 +63,7 @@ fn main() { let (reader, writer) = stream.split(); io::copy(reader, writer) }) - .map(move |(n, _, _)| println!("Echo: {} - {}", n, addr)) + .map(move |(n, ..)| println!("Echo: {} - {}", n, addr)) .map_err(move |err| println!("Error: {:?} - {}", err, addr)); handle.spawn(done); @@ -72,11 +72,11 @@ fn main() { let done = arc_config.accept_async(stream) .and_then(|stream| io::write_all( stream, - "HTTP/1.0 200 ok\r\n\ + &b"HTTP/1.0 200 ok\r\n\ Connection: close\r\n\ Content-length: 12\r\n\ \r\n\ - Hello world!".as_bytes() + Hello world!"[..] )) .and_then(|(stream, _)| io::flush(stream)) .map(move |_| println!("Accept: {}", addr)) diff --git a/src/lib.rs b/src/lib.rs index dc92868..1a48ddc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -227,7 +227,7 @@ impl io::Write for TlsStream while self.session.wants_write() { self.session.write_tls(&mut self.io)?; } - Ok(()) + self.io.flush() } } @@ -244,7 +244,10 @@ impl AsyncWrite for TlsStream { fn shutdown(&mut self) -> Poll<(), io::Error> { self.session.send_close_notify(); - try_nb!(io::Write::flush(self)); + while self.session.wants_write() { + try_nb!(self.session.write_tls(&mut self.io)); + } + try_nb!(self.io.flush()); self.io.shutdown() } }