[Fixed] empty handshake loop
This commit is contained in:
parent
91e2131653
commit
ffdf1ebcb8
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tokio-rustls"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["quininer kel <quininer@live.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/quininer/tokio-rustls"
|
||||
|
@ -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();
|
||||
}
|
||||
|
22
src/lib.rs
22
src/lib.rs
@ -98,16 +98,18 @@ impl<S, C> Future for MidHandshake<S, C>
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user