@@ -38,6 +38,7 @@ use url::Url;
3838
3939#[ cfg( unix) ]  
4040use  std:: os:: fd:: RawFd ; 
41+ use  std:: time:: Duration ; 
4142#[ cfg( not( target_arch = "wasm32" ) ) ]  
4243use  tokio:: time:: sleep; 
4344
@@ -104,10 +105,13 @@ pub struct GatewayClient<C, St = EphemeralCredentialStorage> {
104105    // currently unused (but populated) 
105106    negotiated_protocol :  Option < u8 > , 
106107
107-     // Callback on the fd as soon as the connection has been established 
108+     ///  Callback on the fd as soon as the connection has been established 
108109#[ cfg( unix) ]  
109110    connection_fd_callback :  Option < Arc < dyn  Fn ( RawFd )  + Send  + Sync > > , 
110111
112+     /// Maximum duration to wait for a connection to be established when set 
113+ connect_timeout :  Option < Duration > , 
114+ 
111115    /// Listen to shutdown messages and send notifications back to the task manager 
112116shutdown_token :  ShutdownToken , 
113117} 
@@ -124,6 +128,7 @@ impl<C, St> GatewayClient<C, St> {
124128        bandwidth_controller :  Option < BandwidthController < C ,  St > > , 
125129        stats_reporter :  ClientStatsSender , 
126130        #[ cfg( unix) ]   connection_fd_callback :  Option < Arc < dyn  Fn ( RawFd )  + Send  + Sync > > , 
131+         connect_timeout :  Option < Duration > , 
127132        shutdown_token :  ShutdownToken , 
128133    )  -> Self  { 
129134        GatewayClient  { 
@@ -141,6 +146,7 @@ impl<C, St> GatewayClient<C, St> {
141146            negotiated_protocol :  None , 
142147            #[ cfg( unix) ]  
143148            connection_fd_callback, 
149+             connect_timeout, 
144150            shutdown_token, 
145151        } 
146152    } 
@@ -208,6 +214,7 @@ impl<C, St> GatewayClient<C, St> {
208214            & self . gateway_address , 
209215            #[ cfg( unix) ]  
210216            self . connection_fd_callback . clone ( ) , 
217+             self . connect_timeout , 
211218        ) 
212219        . await ?; 
213220
@@ -1132,6 +1139,7 @@ impl GatewayClient<InitOnly, EphemeralCredentialStorage> {
11321139        gateway_identity :  ed25519:: PublicKey , 
11331140        local_identity :  Arc < ed25519:: KeyPair > , 
11341141        #[ cfg( unix) ]   connection_fd_callback :  Option < Arc < dyn  Fn ( RawFd )  + Send  + Sync > > , 
1142+         connect_timeout :  Option < Duration > , 
11351143    )  -> Self  { 
11361144        log:: trace!( "Initialising gateway client" ) ; 
11371145        use  futures:: channel:: mpsc; 
@@ -1158,6 +1166,7 @@ impl GatewayClient<InitOnly, EphemeralCredentialStorage> {
11581166            negotiated_protocol :  None , 
11591167            #[ cfg( unix) ]  
11601168            connection_fd_callback, 
1169+             connect_timeout, 
11611170            shutdown_token, 
11621171        } 
11631172    } 
@@ -1190,6 +1199,7 @@ impl GatewayClient<InitOnly, EphemeralCredentialStorage> {
11901199            negotiated_protocol :  self . negotiated_protocol , 
11911200            #[ cfg( unix) ]  
11921201            connection_fd_callback :  self . connection_fd_callback , 
1202+             connect_timeout :  self . connect_timeout , 
11931203            shutdown_token, 
11941204        } 
11951205    } 
0 commit comments