Skip to content

Commit 2b47ba0

Browse files
committed
---
yaml --- r: 127740 b: refs/heads/snap-stage3 c: 9fdcddb h: refs/heads/master v: v3
1 parent 090f3df commit 2b47ba0

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
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: 63cd4acf535f8df177459559fe2d7e6ab390c6d8
4+
refs/heads/snap-stage3: 9fdcddb3178d4705db4aee5ee12c05796203658c
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use boxed::Box;
3434
use rt::rtio::{IoFactory, LocalIo, RtioSocket, RtioTcpListener};
3535
use rt::rtio::{RtioTcpAcceptor, RtioTcpStream};
3636
use rt::rtio;
37+
use time::Duration;
3738

3839
/// A structure which represents a TCP stream between a local socket and a
3940
/// remote socket.
@@ -102,11 +103,11 @@ impl TcpStream {
102103
/// and port, similar to the API seen in `connect`.
103104
#[experimental = "the timeout argument may eventually change types"]
104105
pub fn connect_timeout(addr: SocketAddr,
105-
timeout_ms: u64) -> IoResult<TcpStream> {
106+
timeout: Duration) -> IoResult<TcpStream> {
106107
let SocketAddr { ip, port } = addr;
107108
let addr = rtio::SocketAddr { ip: super::to_rtio(ip), port: port };
108109
LocalIo::maybe_raise(|io| {
109-
io.tcp_connect(addr, Some(timeout_ms)).map(TcpStream::new)
110+
io.tcp_connect(addr, Some(in_ms_u64(timeout))).map(TcpStream::new)
110111
}).map_err(IoError::from_rtio_error)
111112
}
112113

@@ -443,6 +444,12 @@ impl Acceptor<TcpStream> for TcpAcceptor {
443444
}
444445
}
445446

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+
446453
#[cfg(test)]
447454
#[allow(experimental)]
448455
mod test {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use kinds::Send;
3333
use boxed::Box;
3434
use rt::rtio::{IoFactory, LocalIo, RtioUnixListener};
3535
use rt::rtio::{RtioUnixAcceptor, RtioPipe};
36+
use time::Duration;
3637

3738
/// A stream which communicates over a named pipe.
3839
pub struct UnixStream {
@@ -68,9 +69,9 @@ impl UnixStream {
6869
/// elapses the function will return an error of kind `TimedOut`.
6970
#[experimental = "the timeout argument is likely to change types"]
7071
pub fn connect_timeout<P: ToCStr>(path: &P,
71-
timeout_ms: u64) -> IoResult<UnixStream> {
72+
timeout: Duration) -> IoResult<UnixStream> {
7273
LocalIo::maybe_raise(|io| {
73-
let s = io.unix_connect(&path.to_c_str(), Some(timeout_ms));
74+
let s = io.unix_connect(&path.to_c_str(), Some(in_ms_u64(timeout)));
7475
s.map(|p| UnixStream { obj: p })
7576
}).map_err(IoError::from_rtio_error)
7677
}
@@ -499,13 +500,13 @@ mod tests {
499500

500501
iotest!(fn connect_timeout_error() {
501502
let addr = next_test_unix();
502-
assert!(UnixStream::connect_timeout(&addr, 100).is_err());
503+
assert!(UnixStream::connect_timeout(&addr, Duration::milliseconds(100)).is_err());
503504
})
504505

505506
iotest!(fn connect_timeout_success() {
506507
let addr = next_test_unix();
507508
let _a = UnixListener::bind(&addr).unwrap().listen().unwrap();
508-
assert!(UnixStream::connect_timeout(&addr, 100).is_ok());
509+
assert!(UnixStream::connect_timeout(&addr, Duration::milliseconds(100)).is_ok());
509510
})
510511

511512
iotest!(fn close_readwrite_smoke() {

branches/snap-stage3/src/libstd/io/timer.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ pub struct Timer {
7272

7373
struct TimerCallback { tx: Sender<()> }
7474

75-
fn in_ms(d: Duration) -> u64 {
76-
let ms = d.num_milliseconds();
77-
if ms < 0 { return 0 };
78-
return ms as u64;
79-
}
80-
8175
/// Sleep the current task for the specified duration.
8276
///
8377
/// When provided a zero or negative `duration`, the function will
@@ -108,7 +102,7 @@ impl Timer {
108102
/// return immediately.
109103
pub fn sleep(&mut self, duration: Duration) {
110104
// Short-circuit the timer backend for 0 duration
111-
let ms = in_ms(duration);
105+
let ms = in_ms_u64(duration);
112106
if ms == 0 { return }
113107
self.obj.sleep(ms);
114108
}
@@ -153,8 +147,8 @@ impl Timer {
153147
pub fn oneshot(&mut self, duration: Duration) -> Receiver<()> {
154148
let (tx, rx) = channel();
155149
// Short-circuit the timer backend for 0 duration
156-
if in_ms(duration) != 0 {
157-
self.obj.oneshot(in_ms(duration), box TimerCallback { tx: tx });
150+
if in_ms_u64(duration) != 0 {
151+
self.obj.oneshot(in_ms_u64(duration), box TimerCallback { tx: tx });
158152
} else {
159153
tx.send(());
160154
}
@@ -207,7 +201,7 @@ impl Timer {
207201
/// When provided a zero or negative `duration`, the messages will
208202
/// be sent without delay.
209203
pub fn periodic(&mut self, duration: Duration) -> Receiver<()> {
210-
let ms = in_ms(duration);
204+
let ms = in_ms_u64(duration);
211205
// FIXME: The backend implementations don't ever send a message
212206
// if given a 0 ms duration. Temporarily using 1ms. It's
213207
// not clear what use a 0ms period is anyway...
@@ -224,6 +218,12 @@ impl Callback for TimerCallback {
224218
}
225219
}
226220

221+
fn in_ms_u64(d: Duration) -> u64 {
222+
let ms = d.num_milliseconds();
223+
if ms < 0 { return 0 };
224+
return ms as u64;
225+
}
226+
227227
#[cfg(test)]
228228
mod test {
229229
iotest!(fn test_io_timer_sleep_simple() {

0 commit comments

Comments
 (0)