From 02028c54b8d5e99a1cab1857b964f17180f023b9 Mon Sep 17 00:00:00 2001 From: quininer Date: Mon, 2 Dec 2019 23:43:49 +0800 Subject: [PATCH] Fix client example --- examples/client/Cargo.toml | 2 +- examples/client/src/main.rs | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/client/Cargo.toml b/examples/client/Cargo.toml index 4e29373..20313b9 100644 --- a/examples/client/Cargo.toml +++ b/examples/client/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] futures-util = "0.3" -tokio = { version = "0.2", features = [ "net", "io-util", "rt-threaded" ] } +tokio = { version = "0.2", features = [ "net", "io-std", "io-util", "rt-threaded" ] } structopt = "0.2" tokio-rustls = { path = "../.." } webpki-roots = "0.18" diff --git a/examples/client/src/main.rs b/examples/client/src/main.rs index 8f130d2..6012c7e 100644 --- a/examples/client/src/main.rs +++ b/examples/client/src/main.rs @@ -8,9 +8,12 @@ use futures_util::future; use structopt::StructOpt; use tokio::runtime; use tokio::net::TcpStream; -use tokio::io::{ AsyncWriteExt, copy, split }; +use tokio::io::{ + AsyncWriteExt, + copy, split, + stdin as tokio_stdin, stdout as tokio_stdout +}; use tokio_rustls::{ TlsConnector, rustls::ClientConfig, webpki::DNSNameRef }; -use tokio_stdin_stdout::{ stdin as tokio_stdin, stdout as tokio_stdout }; #[derive(StructOpt)] @@ -61,8 +64,7 @@ fn main() -> io::Result<()> { let fut = async { let stream = TcpStream::connect(&addr).await?; - // TODO tokio-compat - let (mut stdin, mut stdout) = (tokio_stdin(0).compat(), tokio_stdout(0).compat()); + let (mut stdin, mut stdout) = (tokio_stdin(), tokio_stdout()); let domain = DNSNameRef::try_from_ascii_str(&domain) .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid dnsname"))?; @@ -71,10 +73,13 @@ fn main() -> io::Result<()> { stream.write_all(content.as_bytes()).await?; let (mut reader, mut writer) = split(stream); - future::try_join( + future::select( copy(&mut reader, &mut stdout), copy(&mut stdin, &mut writer) - ).await?; + ) + .await + .factor_first() + .0?; Ok(()) };