This commit is contained in:
quininer 2018-08-21 09:57:27 +08:00
parent f698c44e1a
commit 686b75bd46
2 changed files with 20 additions and 61 deletions

View File

@ -9,9 +9,4 @@ tokio-rustls = { path = "../.." }
tokio = "0.1" tokio = "0.1"
clap = "2" clap = "2"
webpki-roots = "0.15" webpki-roots = "0.15"
tokio-stdin-stdout = "0.1"
[target.'cfg(unix)'.dependencies]
tokio-file-unix = "0.5"
[target.'cfg(not(unix))'.dependencies]
tokio-fs = "0.1"

View File

@ -4,8 +4,7 @@ extern crate webpki;
extern crate webpki_roots; extern crate webpki_roots;
extern crate tokio_rustls; extern crate tokio_rustls;
#[cfg(unix)] extern crate tokio_file_unix; extern crate tokio_stdin_stdout;
#[cfg(not(unix))] extern crate tokio_fs;
use std::sync::Arc; use std::sync::Arc;
use std::net::ToSocketAddrs; use std::net::ToSocketAddrs;
@ -16,6 +15,7 @@ use tokio::net::TcpStream;
use tokio::prelude::*; use tokio::prelude::*;
use clap::{ App, Arg }; use clap::{ App, Arg };
use tokio_rustls::{ ClientConfigExt, rustls::ClientConfig }; use tokio_rustls::{ ClientConfigExt, rustls::ClientConfig };
use tokio_stdin_stdout::{ stdin as tokio_stdin, stdout as tokio_stdout };
fn app() -> App<'static, 'static> { fn app() -> App<'static, 'static> {
App::new("client") App::new("client")
@ -52,22 +52,9 @@ fn main() {
let arc_config = Arc::new(config); let arc_config = Arc::new(config);
let socket = TcpStream::connect(&addr); let socket = TcpStream::connect(&addr);
let (stdin, stdout) = (tokio_stdin(0), tokio_stdout(0));
#[cfg(unix)] let done = socket
let resp = {
use tokio::reactor::Handle;
use tokio_file_unix::{ raw_stdin, raw_stdout, File };
let stdin = raw_stdin()
.and_then(File::new_nb)
.and_then(|fd| fd.into_reader(&Handle::current()))
.unwrap();
let stdout = raw_stdout()
.and_then(File::new_nb)
.and_then(|fd| fd.into_io(&Handle::current()))
.unwrap();
socket
.and_then(move |stream| { .and_then(move |stream| {
let domain = webpki::DNSNameRef::try_from_ascii_str(&domain).unwrap(); let domain = webpki::DNSNameRef::try_from_ascii_str(&domain).unwrap();
arc_config.connect_async(domain, stream) arc_config.connect_async(domain, stream)
@ -81,30 +68,7 @@ fn main() {
.map_err(|res| res.split().0) .map_err(|res| res.split().0)
}) })
.map(drop) .map(drop)
.map_err(|err| eprintln!("{:?}", err)) .map_err(|err| eprintln!("{:?}", err));
};
#[cfg(not(unix))] tokio::run(done);
let resp = {
use tokio_fs::{ stdin as tokio_stdin, stdout as tokio_stdout };
let (stdin, stdout) = (tokio_stdin(), tokio_stdout());
socket
.and_then(move |stream| {
let domain = webpki::DNSNameRef::try_from_ascii_str(&domain).unwrap();
arc_config.connect_async(domain, stream)
})
.and_then(move |stream| io::write_all(stream, text))
.and_then(move |(stream, _)| {
let (r, w) = stream.split();
io::copy(r, stdout)
.map(drop)
.join(io::copy(stdin, w).map(drop))
})
.map(drop)
.map_err(|err| eprintln!("{:?}", err))
};
tokio::run(resp);
} }