move sleep
This commit is contained in:
parent
369c13d6a5
commit
d8235071cd
@ -10,7 +10,6 @@ use std::task::{ Context, Poll };
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::prelude::*;
|
use tokio::prelude::*;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
use tokio::io::split;
|
|
||||||
use tokio::timer::delay_for;
|
use tokio::timer::delay_for;
|
||||||
use futures_util::{ future, ready };
|
use futures_util::{ future, ready };
|
||||||
use rustls::ClientConfig;
|
use rustls::ClientConfig;
|
||||||
@ -41,22 +40,17 @@ async fn send(config: Arc<ClientConfig>, addr: SocketAddr, data: &[u8])
|
|||||||
stream.write_all(data).await?;
|
stream.write_all(data).await?;
|
||||||
stream.flush().await?;
|
stream.flush().await?;
|
||||||
|
|
||||||
let (r, mut w) = split(stream);
|
// sleep 3s
|
||||||
let fut = Read1(r);
|
//
|
||||||
let fut2 = async move {
|
// see https://www.mail-archive.com/openssl-users@openssl.org/msg84451.html
|
||||||
// sleep 3s
|
let sleep3 = delay_for(Duration::from_secs(3));
|
||||||
//
|
let mut stream = match future::select(Read1(stream), sleep3).await {
|
||||||
// see https://www.mail-archive.com/openssl-users@openssl.org/msg84451.html
|
future::Either::Right((_, Read1(stream))) => stream,
|
||||||
delay_for(Duration::from_secs(3)).await;
|
future::Either::Left((Err(err), _)) => return Err(err),
|
||||||
w.shutdown().await?;
|
future::Either::Left((Ok(_), _)) => unreachable!(),
|
||||||
Ok(w) as io::Result<_>
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let stream = match future::select(fut, fut2.boxed()).await {
|
stream.shutdown().await?;
|
||||||
future::Either::Left(_) => unreachable!(),
|
|
||||||
future::Either::Right((Ok(w), Read1(r))) => r.unsplit(w),
|
|
||||||
future::Either::Right((Err(err), _)) => return Err(err)
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(stream)
|
Ok(stream)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user