@@ -6,6 +6,7 @@ use std::io::Read;
66use std:: net:: { SocketAddr , TcpStream , ToSocketAddrs } ;
77use std:: path:: { Path , PathBuf } ;
88use std:: str:: FromStr ;
9+ use std:: time:: Duration ;
910
1011use remotefs:: { RemoteError , RemoteErrorType , RemoteResult } ;
1112use ssh2:: { MethodType as SshMethodType , Session } ;
@@ -61,9 +62,7 @@ pub fn connect(opts: &SshOpts) -> RemoteResult<Session> {
6162 socket_addr,
6263 ssh_config. connection_timeout. as_secs( )
6364 ) ;
64- if let Ok ( tcp_stream) =
65- TcpStream :: connect_timeout ( socket_addr, ssh_config. connection_timeout )
66- {
65+ if let Ok ( tcp_stream) = tcp_connect ( socket_addr, ssh_config. connection_timeout ) {
6766 debug ! ( "Connection established with address {}" , socket_addr) ;
6867 stream = Some ( tcp_stream) ;
6968 break ;
@@ -129,6 +128,16 @@ pub fn connect(opts: &SshOpts) -> RemoteResult<Session> {
129128 Ok ( session)
130129}
131130
131+ /// connect to socket address with provided timeout.
132+ /// If timeout is zero, don't set timeout
133+ fn tcp_connect ( address : & SocketAddr , timeout : Duration ) -> std:: io:: Result < TcpStream > {
134+ if timeout. is_zero ( ) {
135+ TcpStream :: connect ( address)
136+ } else {
137+ TcpStream :: connect_timeout ( address, timeout)
138+ }
139+ }
140+
132141/// Configure algorithm preferences into session
133142fn set_algo_prefs ( session : & mut Session , opts : & SshOpts , config : & Config ) -> RemoteResult < ( ) > {
134143 // Configure preferences from config
0 commit comments