[Fixed] empty handshake loop

This commit is contained in:
quininer kel 2017-02-24 19:28:19 +08:00
parent 91e2131653
commit ffdf1ebcb8
3 changed files with 24 additions and 14 deletions

View File

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

@ -8,10 +8,10 @@ extern crate tokio_rustls;
use std::sync::Arc; use std::sync::Arc;
use std::net::ToSocketAddrs; use std::net::ToSocketAddrs;
use std::io::{ BufReader, stdout }; use std::io::{ BufReader, stdout, stdin };
use std::fs; use std::fs;
use futures::Future; use futures::Future;
use tokio_core::io; use tokio_core::io::{ self, Io };
use tokio_core::net::TcpStream; use tokio_core::net::TcpStream;
use tokio_core::reactor::Core; use tokio_core::reactor::Core;
use clap::{ App, Arg }; use clap::{ App, Arg };
@ -49,6 +49,9 @@ fn main() {
.to_socket_addrs().unwrap() .to_socket_addrs().unwrap()
.next().unwrap(); .next().unwrap();
let stdin = stdin();
let stdin = File::new_nb(StdFile(stdin.lock())).unwrap()
.into_io(&handle).unwrap();
let stdout = stdout(); let stdout = stdout();
let stdout = File::new_nb(StdFile(stdout.lock())).unwrap() let stdout = File::new_nb(StdFile(stdout.lock())).unwrap()
.into_io(&handle).unwrap(); .into_io(&handle).unwrap();
@ -66,7 +69,12 @@ fn main() {
let resp = socket let resp = socket
.and_then(|stream| arc_config.connect_async(domain, stream)) .and_then(|stream| arc_config.connect_async(domain, stream))
.and_then(|stream| io::write_all(stream, text.as_bytes())) .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(); core.run(resp).unwrap();
} }

View File

@ -98,16 +98,18 @@ impl<S, C> Future for MidHandshake<S, C>
if !stream.session.is_handshaking() { break }; if !stream.session.is_handshaking() { break };
match stream.do_io() { match stream.do_io() {
Ok(()) => continue, Ok(()) => if stream.eof {
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => (), return Err(io::Error::from(io::ErrorKind::UnexpectedEof))
Err(e) => return Err(e) } else if stream.session.is_handshaking() {
} continue
if !stream.session.is_handshaking() { break }; } else {
break
if stream.eof { },
return Err(io::Error::from(io::ErrorKind::UnexpectedEof)); Err(e) => match (e.kind(), stream.session.is_handshaking()) {
} else { (io::ErrorKind::WouldBlock, true) => return Ok(Async::NotReady),
return Ok(Async::NotReady); (io::ErrorKind::WouldBlock, false) => break,
(..) => return Err(e)
}
} }
} }