[Fixed] shutdown should only flush io

This commit is contained in:
quininer kel 2017-04-14 12:43:03 +08:00
parent 4843c68019
commit 3d5a36590d
5 changed files with 12 additions and 9 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "tokio-rustls" name = "tokio-rustls"
version = "0.1.6" version = "0.1.7"
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"

View File

@ -7,11 +7,11 @@ Asynchronous TLS/SSL streams for [Tokio](https://tokio.rs/) using
### Basic Structure of a Client ### Basic Structure of a Client
```rust ```rust
// ...
use rustls::ClientConfig; use rustls::ClientConfig;
use tokio_rustls::ClientConfigExt; use tokio_rustls::ClientConfigExt;
// ...
let mut config = ClientConfig::new(); let mut config = ClientConfig::new();
config.root_store.add_trust_anchors(&webpki_roots::ROOTS); config.root_store.add_trust_anchors(&webpki_roots::ROOTS);
let config = Arc::new(config); let config = Arc::new(config);

View File

@ -78,7 +78,7 @@ fn main() {
#[cfg(unix)] #[cfg(unix)]
let stdin = File::new_nb(StdFile(stdin.lock())).unwrap() let stdin = File::new_nb(StdFile(stdin.lock())).unwrap()
.into_io(&handle).unwrap(); .into_io(&handle).unwrap();
#[cfg(unix)] #[cfg(unix)]
let stdout = stdout(); let stdout = stdout();

View File

@ -63,7 +63,7 @@ fn main() {
let (reader, writer) = stream.split(); let (reader, writer) = stream.split();
io::copy(reader, writer) 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)); .map_err(move |err| println!("Error: {:?} - {}", err, addr));
handle.spawn(done); handle.spawn(done);
@ -72,11 +72,11 @@ fn main() {
let done = arc_config.accept_async(stream) let done = arc_config.accept_async(stream)
.and_then(|stream| io::write_all( .and_then(|stream| io::write_all(
stream, stream,
"HTTP/1.0 200 ok\r\n\ &b"HTTP/1.0 200 ok\r\n\
Connection: close\r\n\ Connection: close\r\n\
Content-length: 12\r\n\ Content-length: 12\r\n\
\r\n\ \r\n\
Hello world!".as_bytes() Hello world!"[..]
)) ))
.and_then(|(stream, _)| io::flush(stream)) .and_then(|(stream, _)| io::flush(stream))
.map(move |_| println!("Accept: {}", addr)) .map(move |_| println!("Accept: {}", addr))

View File

@ -227,7 +227,7 @@ impl<S, C> io::Write for TlsStream<S, C>
while self.session.wants_write() { while self.session.wants_write() {
self.session.write_tls(&mut self.io)?; self.session.write_tls(&mut self.io)?;
} }
Ok(()) self.io.flush()
} }
} }
@ -244,7 +244,10 @@ impl<S, C> AsyncWrite for TlsStream<S, C>
{ {
fn shutdown(&mut self) -> Poll<(), io::Error> { fn shutdown(&mut self) -> Poll<(), io::Error> {
self.session.send_close_notify(); 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() self.io.shutdown()
} }
} }