File tree 1 file changed +23
-2
lines changed
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ use tokio::net::{TcpListener, TcpStream};
5
5
6
6
use anyhow:: { anyhow, Result } ;
7
7
use futures:: future:: try_join;
8
- use log:: info;
8
+ use log:: { error, info} ;
9
+ use quinn:: ConnectionError ;
9
10
use quinn:: Endpoint ;
10
11
use structopt:: { self , StructOpt } ;
11
12
@@ -115,7 +116,27 @@ async fn transfer(
115
116
let new_conn = endpoint
116
117
. connect ( * remote, & host) ?
117
118
. await
118
- . map_err ( |e| anyhow ! ( "failed to connect: {}" , e) ) ?;
119
+ . map_err ( |e| {
120
+ if e == ConnectionError :: TimedOut {
121
+ let socket = if cfg ! ( target_os = "windows" ) {
122
+ std:: net:: UdpSocket :: bind ( "0.0.0.0:0" ) . unwrap ( )
123
+ } else {
124
+ std:: net:: UdpSocket :: bind ( "[::]:0" ) . unwrap ( )
125
+ } ;
126
+ let addr = socket. local_addr ( ) . unwrap ( ) ;
127
+ let ret = endpoint. rebind ( socket) ;
128
+ match ret {
129
+ Ok ( _) => {
130
+ info ! ( "rebinding to: {}" , addr) ;
131
+ }
132
+ Err ( e) => {
133
+ error ! ( "rebind fail: {:?}" , e) ;
134
+ }
135
+ }
136
+ }
137
+ anyhow ! ( "failed to connect: {:?}" , e)
138
+ } )
139
+ . unwrap ( ) ;
119
140
120
141
let quinn:: NewConnection {
121
142
connection : conn, ..
You can’t perform that action at this time.
0 commit comments