@@ -29,6 +29,7 @@ use prelude::*;
29
29
use c_str:: ToCStr ;
30
30
use clone:: Clone ;
31
31
use io:: { Listener , Acceptor , Reader , Writer , IoResult , IoError } ;
32
+ use io:: { standard_error, TimedOut } ;
32
33
use kinds:: Send ;
33
34
use boxed:: Box ;
34
35
use rt:: rtio:: { IoFactory , LocalIo , RtioUnixListener } ;
@@ -68,13 +69,14 @@ impl UnixStream {
68
69
/// This function is similar to `connect`, except that if `timeout_ms`
69
70
/// elapses the function will return an error of kind `TimedOut`.
70
71
///
71
- /// # Failure
72
- ///
73
- /// Fails on a `timeout` of zero or negative duration.
72
+ /// If a `timeout` with zero or negative duration is specified then
73
+ /// the function returns `Err`, with the error kind set to `TimedOut`.
74
74
#[ experimental = "the timeout argument is likely to change types" ]
75
75
pub fn connect_timeout < P : ToCStr > ( path : & P ,
76
76
timeout : Duration ) -> IoResult < UnixStream > {
77
- assert ! ( timeout > Duration :: milliseconds( 0 ) ) ;
77
+ if timeout <= Duration :: milliseconds ( 0 ) {
78
+ return standard_error ( TimedOut ) ;
79
+ }
78
80
79
81
LocalIo :: maybe_raise ( |io| {
80
82
let s = io. unix_connect ( & path. to_c_str ( ) , Some ( timeout. num_milliseconds ( ) as u64 ) ) ;
@@ -518,14 +520,14 @@ mod tests {
518
520
iotest ! ( fn connect_timeout_zero( ) {
519
521
let addr = next_test_unix( ) ;
520
522
let _a = UnixListener :: bind( & addr) . unwrap( ) . listen( ) . unwrap( ) ;
521
- assert!( UnixStream :: connect_timeout( & addr, Duration :: milliseconds( 0 ) ) . is_ok ( ) ) ;
522
- } # [ should_fail ] )
523
+ assert!( UnixStream :: connect_timeout( & addr, Duration :: milliseconds( 0 ) ) . is_err ( ) ) ;
524
+ } )
523
525
524
526
iotest ! ( fn connect_timeout_negative( ) {
525
527
let addr = next_test_unix( ) ;
526
528
let _a = UnixListener :: bind( & addr) . unwrap( ) . listen( ) . unwrap( ) ;
527
- assert!( UnixStream :: connect_timeout( & addr, Duration :: milliseconds( -1 ) ) . is_ok ( ) ) ;
528
- } # [ should_fail ] )
529
+ assert!( UnixStream :: connect_timeout( & addr, Duration :: milliseconds( -1 ) ) . is_err ( ) ) ;
530
+ } )
529
531
530
532
iotest ! ( fn close_readwrite_smoke( ) {
531
533
let addr = next_test_unix( ) ;
0 commit comments