Fix client example

This commit is contained in:
quininer 2019-12-02 23:43:49 +08:00
parent 34b1bc9c83
commit 02028c54b8
2 changed files with 12 additions and 7 deletions

View File

@ -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"

View File

@ -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(())
};