diff options
author | alborq <alborq@users.noreply.github.com> | 2020-07-12 20:33:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-12 20:33:20 +0200 |
commit | 8411a6945f2d4711a9422dfd4d3362e08b6e8f99 (patch) | |
tree | 942b23ae60a4987af910178074ec453b22e70b07 /examples | |
parent | f69e5bfb87eda2b8de9b762b9280f1733cdaa096 (diff) |
example: close pending connection on proxy exemple (#2590)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/proxy.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/examples/proxy.rs b/examples/proxy.rs index f7a9111f..144f0179 100644 --- a/examples/proxy.rs +++ b/examples/proxy.rs @@ -23,6 +23,7 @@ #![warn(rust_2018_idioms)] use tokio::io; +use tokio::io::AsyncWriteExt; use tokio::net::{TcpListener, TcpStream}; use futures::future::try_join; @@ -63,8 +64,15 @@ async fn transfer(mut inbound: TcpStream, proxy_addr: String) -> Result<(), Box< let (mut ri, mut wi) = inbound.split(); let (mut ro, mut wo) = outbound.split(); - let client_to_server = io::copy(&mut ri, &mut wo); - let server_to_client = io::copy(&mut ro, &mut wi); + let client_to_server = async { + io::copy(&mut ri, &mut wo).await?; + wo.shutdown().await + }; + + let server_to_client = async { + io::copy(&mut ro, &mut wi).await?; + wi.shutdown().await + }; try_join(client_to_server, server_to_client).await?; |