From d748fc882ee1cd0a25fbfb10c59f35cf62bede60 Mon Sep 17 00:00:00 2001 From: dev4u Date: Wed, 16 Mar 2022 00:28:30 +0800 Subject: [PATCH] Update client.rs re-fix the issue https://github.com/shadowsocks/qtun/issues/3 --- src/client.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index 2cdbe18..94b5c66 100644 --- a/src/client.rs +++ b/src/client.rs @@ -94,12 +94,6 @@ async fn main() -> Result<()> { while let Ok((inbound, _)) = listener.accept().await { info!("connection incoming"); - let socket = if cfg!(target_os = "windows") { - std::net::UdpSocket::bind("0.0.0.0:0").unwrap() - } else { - std::net::UdpSocket::bind("[::]:0").unwrap() - }; - endpoint.rebind(socket)?; let remote = Arc::clone(&remote); let host = Arc::clone(&host); @@ -121,7 +115,19 @@ async fn transfer( let new_conn = endpoint .connect(*remote, &host)? .await - .map_err(|e| anyhow!("failed to connect: {}", e))?; + .map_err(|e| { + if e == ConnectionError::TimedOut { + let socket = if cfg!(target_os = "windows") { + std::net::UdpSocket::bind("0.0.0.0:0").unwrap() + } else { + std::net::UdpSocket::bind("[::]:0").unwrap() + }; + endpoint.rebind(socket)?; + Ok(()) + } else { + Err(anyhow!("failed to connect: {:?}", e)) + } + }).unwrap(); let quinn::NewConnection { connection: conn, ..