diff --git a/README.md b/README.md index 66eb1f9..74997f1 100644 --- a/README.md +++ b/README.md @@ -31,25 +31,28 @@ TcpStream::connect(&addr) ### Client Example Program -See [examples/client.rs](examples/client.rs). You can run it with: +See [examples/client](examples/client/src/main.rs). You can run it with: ```sh -cargo run --example client hsts.badssl.com +cd examples/client +cargo run -- hsts.badssl.com ``` Currently on Windows the example client reads from stdin and writes to stdout using blocking I/O. Until this is fixed, do something this on Windows: ```sh -echo | cargo run --example client hsts.badssl.com +cd examples/client +echo | cargo run -- hsts.badssl.com ``` ### Server Example Program -See [examples/server.rs](examples/server.rs). You can run it with: +See [examples/server](examples/server/src/main.rs). You can run it with: ```sh -cargo run --example server -- 127.0.0.1 --cert mycert.der --key mykey.der +cd examples/server +cargo run -- 127.0.0.1 --cert mycert.der --key mykey.der ``` ### License & Origin diff --git a/examples/server/src/main.rs b/examples/server/src/main.rs index c321048..7e59cd1 100644 --- a/examples/server/src/main.rs +++ b/examples/server/src/main.rs @@ -52,20 +52,18 @@ fn main() { let done = socket.incoming() .for_each(move |stream| if flag_echo { let addr = stream.peer_addr().ok(); - let addr2 = addr.clone(); let done = arc_config.accept_async(stream) .and_then(|stream| { let (reader, writer) = stream.split(); io::copy(reader, writer) }) .map(move |(n, ..)| println!("Echo: {} - {:?}", n, addr)) - .map_err(move |err| println!("Error: {:?} - {:?}", err, addr2)); + .map_err(move |err| println!("Error: {:?} - {:?}", err, addr)); tokio::spawn(done); Ok(()) } else { let addr = stream.peer_addr().ok(); - let addr2 = addr.clone(); let done = arc_config.accept_async(stream) .and_then(|stream| io::write_all( stream, @@ -77,7 +75,7 @@ fn main() { )) .and_then(|(stream, _)| io::flush(stream)) .map(move |_| println!("Accept: {:?}", addr)) - .map_err(move |err| println!("Error: {:?} - {:?}", err, addr2)); + .map_err(move |err| println!("Error: {:?} - {:?}", err, addr)); tokio::spawn(done); Ok(()) diff --git a/src/futures_impl.rs b/src/futures_impl.rs index 86bc9da..13d3c35 100644 --- a/src/futures_impl.rs +++ b/src/futures_impl.rs @@ -143,9 +143,13 @@ impl AsyncWrite for TlsStream fn poll_flush(&mut self, ctx: &mut Context) -> Poll<(), Error> { let (io, session) = self.get_mut(); let mut taskio = TaskStream { io, task: ctx }; - let mut stream = Stream::new(session, &mut taskio); - async!(from io::Write::flush(&mut stream)) + { + let mut stream = Stream::new(session, &mut taskio); + async!(from io::Write::flush(&mut stream))?; + } + + async!(from io::Write::flush(&mut taskio)) } fn poll_close(&mut self, ctx: &mut Context) -> Poll<(), Error> { @@ -157,7 +161,7 @@ impl AsyncWrite for TlsStream { let (io, session) = self.get_mut(); let mut taskio = TaskStream { io, task: ctx }; - session.complete_io(&mut taskio)?; + async!(from session.complete_io(&mut taskio))?; } self.io.poll_close(ctx)