mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
example: close pending connection on proxy exemple (#2590)
This commit is contained in:
+10
-2
@@ -23,6 +23,7 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
|
|
||||||
use tokio::io;
|
use tokio::io;
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
use tokio::net::{TcpListener, TcpStream};
|
use tokio::net::{TcpListener, TcpStream};
|
||||||
|
|
||||||
use futures::future::try_join;
|
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 ri, mut wi) = inbound.split();
|
||||||
let (mut ro, mut wo) = outbound.split();
|
let (mut ro, mut wo) = outbound.split();
|
||||||
|
|
||||||
let client_to_server = io::copy(&mut ri, &mut wo);
|
let client_to_server = async {
|
||||||
let server_to_client = io::copy(&mut ro, &mut wi);
|
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?;
|
try_join(client_to_server, server_to_client).await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user