Skip to content

Commit b787555

Browse files
committed
---
yaml --- r: 127814 b: refs/heads/master c: ee10f35 h: refs/heads/master v: v3
1 parent d2dfb4d commit b787555

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a391934ba8fb99b999f9956e855316692612f1ab
2+
refs/heads/master: ee10f3501c1df04a015a5331c8343792e519c7a7
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: aa98b25c4f0c10729dff37c699904ad57b8fbda8
55
refs/heads/try: d9c23fcbaea89871667272a67ecb8d3a512162f3

trunk/src/libstd/io/net/tcp.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use io::net::addrinfo::get_host_addresses;
2727
use io::net::ip::SocketAddr;
2828
use io::{IoError, ConnectionFailed, InvalidInput};
2929
use io::{Reader, Writer, Listener, Acceptor};
30+
use io::{standard_error, TimedOut};
3031
use from_str::FromStr;
3132
use kinds::Send;
3233
use option::{None, Some, Option};
@@ -102,13 +103,14 @@ impl TcpStream {
102103
/// Note that the `addr` argument may one day be split into a separate host
103104
/// and port, similar to the API seen in `connect`.
104105
///
105-
/// # Failure
106-
///
107-
/// Fails on a `timeout` of zero or negative duration.
106+
/// If a `timeout` with zero or negative duration is specified then
107+
/// the function returns `Err`, with the error kind set to `TimedOut`.
108108
#[experimental = "the timeout argument may eventually change types"]
109109
pub fn connect_timeout(addr: SocketAddr,
110110
timeout: Duration) -> IoResult<TcpStream> {
111-
assert!(timeout > Duration::milliseconds(0));
111+
if timeout <= Duration::milliseconds(0) {
112+
return standard_error(TimedOut);
113+
}
112114

113115
let SocketAddr { ip, port } = addr;
114116
let addr = rtio::SocketAddr { ip: super::to_rtio(ip), port: port };

trunk/src/libstd/io/net/unix.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use prelude::*;
2929
use c_str::ToCStr;
3030
use clone::Clone;
3131
use io::{Listener, Acceptor, Reader, Writer, IoResult, IoError};
32+
use io::{standard_error, TimedOut};
3233
use kinds::Send;
3334
use boxed::Box;
3435
use rt::rtio::{IoFactory, LocalIo, RtioUnixListener};
@@ -68,13 +69,14 @@ impl UnixStream {
6869
/// This function is similar to `connect`, except that if `timeout_ms`
6970
/// elapses the function will return an error of kind `TimedOut`.
7071
///
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`.
7474
#[experimental = "the timeout argument is likely to change types"]
7575
pub fn connect_timeout<P: ToCStr>(path: &P,
7676
timeout: Duration) -> IoResult<UnixStream> {
77-
assert!(timeout > Duration::milliseconds(0));
77+
if timeout <= Duration::milliseconds(0) {
78+
return standard_error(TimedOut);
79+
}
7880

7981
LocalIo::maybe_raise(|io| {
8082
let s = io.unix_connect(&path.to_c_str(), Some(timeout.num_milliseconds() as u64));
@@ -518,14 +520,14 @@ mod tests {
518520
iotest!(fn connect_timeout_zero() {
519521
let addr = next_test_unix();
520522
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+
})
523525

524526
iotest!(fn connect_timeout_negative() {
525527
let addr = next_test_unix();
526528
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+
})
529531

530532
iotest!(fn close_readwrite_smoke() {
531533
let addr = next_test_unix();

trunk/src/test/run-pass/tcp-connect-timeouts.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,14 @@ iotest!(fn timeout_error() {
9696

9797
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(1000)).is_err());
9898
})
99+
100+
iotest!(fn connect_timeout_zero() {
101+
let addr = next_test_ip4();
102+
assert!(TcpStream::connect_timeout(&addr, Duration::milliseconds(0)).is_err());
103+
})
104+
105+
iotest!(fn connect_timeout_negative() {
106+
let addr = next_test_ip4();
107+
assert!(TcpStream::connect_timeout(&addr, Duration::milliseconds(-1)).is_err());
108+
})
109+

0 commit comments

Comments
 (0)