@@ -150,12 +150,16 @@ pub mod client {
150150 ///
151151 /// # Errors
152152 /// - `io::Error(std::io::ErrorKind::*, socks2::Error::*?)`
153- pub fn connect < T , U > ( proxy : T , target : & U , timeout : Option < Duration > ) -> io:: Result < Self >
153+ pub fn connect < T , U > (
154+ proxy : T ,
155+ target : & U ,
156+ connect_timeout : Option < Duration > ,
157+ ) -> io:: Result < Self >
154158 where
155159 T : ToSocketAddrs ,
156160 U : ToTargetAddr ,
157161 {
158- Self :: connect_raw ( 1 , proxy, target, & Authentication :: None , timeout )
162+ Self :: connect_raw ( 1 , proxy, target, & Authentication :: None , connect_timeout )
159163 }
160164
161165 /// Connects to a target server through a SOCKS5 proxy using given
@@ -168,29 +172,30 @@ pub mod client {
168172 target : & U ,
169173 username : & str ,
170174 password : & str ,
171- timeout : Option < Duration > ,
175+ connect_timeout : Option < Duration > ,
172176 ) -> io:: Result < Self >
173177 where
174178 T : ToSocketAddrs ,
175179 U : ToTargetAddr ,
176180 {
177181 let auth = Authentication :: Password { username, password } ;
178- Self :: connect_raw ( 1 , proxy, target, & auth, timeout )
182+ Self :: connect_raw ( 1 , proxy, target, & auth, connect_timeout )
179183 }
180184
181185 pub ( super ) fn connect_raw < T , U > (
182186 command : u8 ,
183187 proxy : T ,
184188 target : & U ,
185189 auth : & Authentication ,
186- timeout : Option < Duration > ,
190+ connect_timeout : Option < Duration > ,
187191 ) -> io:: Result < Self >
188192 where
189193 T : ToSocketAddrs ,
190194 U : ToTargetAddr ,
191195 {
192- let mut socket = match timeout {
196+ let mut socket = match connect_timeout {
193197 None => TcpStream :: connect ( proxy) ?,
198+ // TODO: Connect timeout for each address until one works?
194199 Some ( t) => TcpStream :: connect_timeout (
195200 & proxy
196201 . to_socket_addrs ( ) ?
@@ -384,12 +389,16 @@ pub mod bind {
384389 ///
385390 /// # Errors
386391 /// - `io::Error(std::io::ErrorKind::*, socks2::Error::*?)`
387- pub fn bind < T , U > ( proxy : T , target : & U , timeout : Option < Duration > ) -> io:: Result < Self >
392+ pub fn bind < T , U > (
393+ proxy : T ,
394+ target : & U ,
395+ connect_timeout : Option < Duration > ,
396+ ) -> io:: Result < Self >
388397 where
389398 T : ToSocketAddrs ,
390399 U : ToTargetAddr ,
391400 {
392- Socks5Stream :: connect_raw ( 2 , proxy, target, & Authentication :: None , timeout )
401+ Socks5Stream :: connect_raw ( 2 , proxy, target, & Authentication :: None , connect_timeout )
393402 . map ( Socks5Listener )
394403 }
395404 /// Initiates a BIND request to the specified proxy using given username
@@ -405,14 +414,14 @@ pub mod bind {
405414 target : & U ,
406415 username : & str ,
407416 password : & str ,
408- timeout : Option < Duration > ,
417+ connect_timeout : Option < Duration > ,
409418 ) -> io:: Result < Self >
410419 where
411420 T : ToSocketAddrs ,
412421 U : ToTargetAddr ,
413422 {
414423 let auth = Authentication :: Password { username, password } ;
415- Socks5Stream :: connect_raw ( 2 , proxy, target, & auth, timeout ) . map ( Socks5Listener )
424+ Socks5Stream :: connect_raw ( 2 , proxy, target, & auth, connect_timeout ) . map ( Socks5Listener )
416425 }
417426
418427 /// The address of the proxy-side TCP listener.
@@ -467,12 +476,12 @@ pub mod udp {
467476 ///
468477 /// # Errors
469478 /// - `io::Error(std::io::ErrorKind::*, socks2::Error::*?)`
470- pub fn bind < T , U > ( proxy : T , addr : U , timeout : Option < Duration > ) -> io:: Result < Self >
479+ pub fn bind < T , U > ( proxy : T , addr : U , connect_timeout : Option < Duration > ) -> io:: Result < Self >
471480 where
472481 T : ToSocketAddrs ,
473482 U : ToSocketAddrs ,
474483 {
475- Self :: bind_internal ( proxy, addr, & Authentication :: None , timeout )
484+ Self :: bind_internal ( proxy, addr, & Authentication :: None , connect_timeout )
476485 }
477486
478487 /// Creates a UDP socket bound to the specified address which will have its
@@ -486,21 +495,21 @@ pub mod udp {
486495 addr : U ,
487496 username : & str ,
488497 password : & str ,
489- timeout : Option < Duration > ,
498+ connect_timeout : Option < Duration > ,
490499 ) -> io:: Result < Self >
491500 where
492501 T : ToSocketAddrs ,
493502 U : ToSocketAddrs ,
494503 {
495504 let auth = Authentication :: Password { username, password } ;
496- Self :: bind_internal ( proxy, addr, & auth, timeout )
505+ Self :: bind_internal ( proxy, addr, & auth, connect_timeout )
497506 }
498507
499508 fn bind_internal < T , U > (
500509 proxy : T ,
501510 addr : U ,
502511 auth : & Authentication ,
503- timeout : Option < Duration > ,
512+ connect_timeout : Option < Duration > ,
504513 ) -> io:: Result < Self >
505514 where
506515 T : ToSocketAddrs ,
@@ -512,7 +521,7 @@ pub mod udp {
512521 Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ,
513522 0 ,
514523 ) ) ) ;
515- let stream = Socks5Stream :: connect_raw ( 3 , proxy, & dst, auth, timeout ) ?;
524+ let stream = Socks5Stream :: connect_raw ( 3 , proxy, & dst, auth, connect_timeout ) ?;
516525
517526 let socket = UdpSocket :: bind ( addr) ?;
518527 socket. connect ( & stream. proxy_addr ) ?;
@@ -540,6 +549,7 @@ pub mod udp {
540549 // third byte is the fragment id at 0
541550 let len = write_addr ( & mut header[ 3 ..] , & addr) ?;
542551
552+ // TODO: Use write_vectored?
543553 self . socket . writev ( [ & header[ ..len + 3 ] , buf] )
544554 }
545555
@@ -549,6 +559,7 @@ pub mod udp {
549559 /// - `io::Error(std::io::ErrorKind::*, socks2::Error::*?)`
550560 pub fn recv_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , TargetAddr ) > {
551561 let mut header = [ 0 ; MAX_ADDR_LEN + 3 ] ;
562+ // TODO: Use read_vectored?
552563 let len = self . socket . readv ( [ & mut header, buf] ) ?;
553564
554565 let overflow = len. saturating_sub ( header. len ( ) ) ;
0 commit comments