diff --git a/Cargo.toml b/Cargo.toml index 20e5c2d..33930da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tokio-rustls" -version = "0.1.0" +version = "0.1.1" authors = ["quininer kel "] license = "MIT/Apache-2.0" repository = "https://github.com/quininer/tokio-rustls" diff --git a/examples/client.rs b/examples/client.rs index 471c484..63db56d 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -8,10 +8,10 @@ extern crate tokio_rustls; use std::sync::Arc; use std::net::ToSocketAddrs; -use std::io::{ BufReader, stdout }; +use std::io::{ BufReader, stdout, stdin }; use std::fs; use futures::Future; -use tokio_core::io; +use tokio_core::io::{ self, Io }; use tokio_core::net::TcpStream; use tokio_core::reactor::Core; use clap::{ App, Arg }; @@ -49,6 +49,9 @@ fn main() { .to_socket_addrs().unwrap() .next().unwrap(); + let stdin = stdin(); + let stdin = File::new_nb(StdFile(stdin.lock())).unwrap() + .into_io(&handle).unwrap(); let stdout = stdout(); let stdout = File::new_nb(StdFile(stdout.lock())).unwrap() .into_io(&handle).unwrap(); @@ -66,7 +69,12 @@ fn main() { let resp = socket .and_then(|stream| arc_config.connect_async(domain, stream)) .and_then(|stream| io::write_all(stream, text.as_bytes())) - .and_then(|(stream, _)| io::copy(stream, stdout)); + .and_then(|(stream, _)| { + let (r, w) = stream.split(); + io::copy(r, stdout).select(io::copy(stdin, w)) + .map(|_| ()) + .map_err(|(e, _)| e) + }); core.run(resp).unwrap(); } diff --git a/src/lib.rs b/src/lib.rs index 899efd7..89b6873 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,16 +98,18 @@ impl Future for MidHandshake if !stream.session.is_handshaking() { break }; match stream.do_io() { - Ok(()) => continue, - Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => (), - Err(e) => return Err(e) - } - if !stream.session.is_handshaking() { break }; - - if stream.eof { - return Err(io::Error::from(io::ErrorKind::UnexpectedEof)); - } else { - return Ok(Async::NotReady); + Ok(()) => if stream.eof { + return Err(io::Error::from(io::ErrorKind::UnexpectedEof)) + } else if stream.session.is_handshaking() { + continue + } else { + break + }, + Err(e) => match (e.kind(), stream.session.is_handshaking()) { + (io::ErrorKind::WouldBlock, true) => return Ok(Async::NotReady), + (io::ErrorKind::WouldBlock, false) => break, + (..) => return Err(e) + } } }