Skip to content

Commit 0a98dc4

Browse files
committed
---
yaml --- r: 127741 b: refs/heads/snap-stage3 c: 4475e6a h: refs/heads/master i: 127739: 090f3df v: v3
1 parent 2b47ba0 commit 0a98dc4

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 49a970f2449a78f28b6c301e542d38593094ca77
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 9fdcddb3178d4705db4aee5ee12c05796203658c
4+
refs/heads/snap-stage3: 4475e6a095a8fe4459ac8b854ae2336e47aaafe5
55
refs/heads/try: d9c23fcbaea89871667272a67ecb8d3a512162f3
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/io/net/tcp.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,27 @@ impl TcpStream {
9393
}
9494

9595
/// Creates a TCP connection to a remote socket address, timing out after
96-
/// the specified number of milliseconds.
96+
/// the specified duration.
9797
///
9898
/// This is the same as the `connect` method, except that if the timeout
9999
/// specified (in milliseconds) elapses before a connection is made an error
100100
/// will be returned. The error's kind will be `TimedOut`.
101101
///
102102
/// Note that the `addr` argument may one day be split into a separate host
103103
/// and port, similar to the API seen in `connect`.
104+
///
105+
/// # Failure
106+
///
107+
/// Fails on a `timeout` of zero or negative duration.
104108
#[experimental = "the timeout argument may eventually change types"]
105109
pub fn connect_timeout(addr: SocketAddr,
106110
timeout: Duration) -> IoResult<TcpStream> {
111+
assert!(timeout > Duration::milliseconds(0));
112+
107113
let SocketAddr { ip, port } = addr;
108114
let addr = rtio::SocketAddr { ip: super::to_rtio(ip), port: port };
109115
LocalIo::maybe_raise(|io| {
110-
io.tcp_connect(addr, Some(in_ms_u64(timeout))).map(TcpStream::new)
116+
io.tcp_connect(addr, Some(timeout.num_milliseconds() as u64)).map(TcpStream::new)
111117
}).map_err(IoError::from_rtio_error)
112118
}
113119

@@ -444,12 +450,6 @@ impl Acceptor<TcpStream> for TcpAcceptor {
444450
}
445451
}
446452

447-
fn in_ms_u64(d: Duration) -> u64 {
448-
let ms = d.num_milliseconds();
449-
if ms < 0 { return 0 };
450-
return ms as u64;
451-
}
452-
453453
#[cfg(test)]
454454
#[allow(experimental)]
455455
mod test {

branches/snap-stage3/src/libstd/io/net/unix.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ impl UnixStream {
6767
///
6868
/// This function is similar to `connect`, except that if `timeout_ms`
6969
/// elapses the function will return an error of kind `TimedOut`.
70+
///
71+
/// # Failure
72+
///
73+
/// Fails on a `timeout` of zero or negative duration.
7074
#[experimental = "the timeout argument is likely to change types"]
7175
pub fn connect_timeout<P: ToCStr>(path: &P,
7276
timeout: Duration) -> IoResult<UnixStream> {
77+
assert!(timeout > Duration::milliseconds(0));
78+
7379
LocalIo::maybe_raise(|io| {
74-
let s = io.unix_connect(&path.to_c_str(), Some(in_ms_u64(timeout)));
80+
let s = io.unix_connect(&path.to_c_str(), Some(timeout.num_milliseconds() as u64));
7581
s.map(|p| UnixStream { obj: p })
7682
}).map_err(IoError::from_rtio_error)
7783
}
@@ -509,6 +515,18 @@ mod tests {
509515
assert!(UnixStream::connect_timeout(&addr, Duration::milliseconds(100)).is_ok());
510516
})
511517

518+
iotest!(fn connect_timeout_zero() {
519+
let addr = next_test_unix();
520+
let _a = UnixListener::bind(&addr).unwrap().listen().unwrap();
521+
assert!(UnixStream::connect_timeout(&addr, Duration::milliseconds(0)).is_ok());
522+
} #[should_fail])
523+
524+
iotest!(fn connect_timeout_negative() {
525+
let addr = next_test_unix();
526+
let _a = UnixListener::bind(&addr).unwrap().listen().unwrap();
527+
assert!(UnixStream::connect_timeout(&addr, Duration::milliseconds(-1)).is_ok());
528+
} #[should_fail])
529+
512530
iotest!(fn close_readwrite_smoke() {
513531
let addr = next_test_unix();
514532
let a = UnixListener::bind(&addr).listen().unwrap();

0 commit comments

Comments
 (0)