Skip to content

Commit

Permalink
Update client.rs
Browse files Browse the repository at this point in the history
re-fix the issue shadowsocks#3
  • Loading branch information
dev4u authored Mar 15, 2022
1 parent 3c231ab commit d748fc8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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, ..
Expand Down

0 comments on commit d748fc8

Please sign in to comment.