Skip to content

Commit 080e465

Browse files
committed
---
yaml --- r: 132730 b: refs/heads/dist-snap c: ee10f35 h: refs/heads/master v: v3
1 parent 9aa106a commit 080e465

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
@@ -6,7 +6,7 @@ refs/heads/try: 457a3c991d79b971be07fce75f9d0c12848fb37c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: a391934ba8fb99b999f9956e855316692612f1ab
9+
refs/heads/dist-snap: ee10f3501c1df04a015a5331c8343792e519c7a7
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/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 };

branches/dist-snap/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();

branches/dist-snap/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)