diff options
| author | bors <bors@rust-lang.org> | 2014-05-08 00:01:41 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-08 00:01:41 -0700 |
| commit | c39b1cb1bed78d989b1011f54f6febb7e9e46d94 (patch) | |
| tree | 0f7ecbfb7edaa18fe4c4036a719fd969a076d414 /src/libstd/rt | |
| parent | 26632d541c3f548b064ffea57f0cb2057b48f947 (diff) | |
| parent | 418f197351fbc570a0e7bbf93d509cd44f988467 (diff) | |
| download | rust-c39b1cb1bed78d989b1011f54f6febb7e9e46d94.tar.gz rust-c39b1cb1bed78d989b1011f54f6febb7e9e46d94.zip | |
auto merge of #13814 : alexcrichton/rust/read-timeout, r=brson
This PR is an implementation of `set_timeout`, `set_read_timeout`, and `set_write_timeout` for TCP, UDP, and Unix streams (named pipes on windows).
The implementation was much more difficult than I imagined it was going to be throughout the 9 categories ({tcp, udp, unix} x {windows, unix, green}). The major snag is that libuv doesn't support canceling writes, so I chose to word the `set_write_timeout` documentation in such a way that it accomadates the behavior seen when running around with libgreen.
The first commit is from #13751, and I just included it to pre-emptively avoid rebase conflicts. The following commits are relevant to this PR. The tests aren't quite passing on windows just yet, but I should have those working by tomorrow once my VM is back up and running. For now, I wanted to see what others' thoughts were on this strategy.
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/rtio.rs | 9 | ||||
| -rw-r--r-- | src/libstd/rt/task.rs | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index c5afe7887ad..16882624ab7 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -222,6 +222,9 @@ pub trait RtioTcpStream : RtioSocket { fn clone(&self) -> Box<RtioTcpStream:Send>; fn close_write(&mut self) -> IoResult<()>; fn close_read(&mut self) -> IoResult<()>; + fn set_timeout(&mut self, timeout_ms: Option<u64>); + fn set_read_timeout(&mut self, timeout_ms: Option<u64>); + fn set_write_timeout(&mut self, timeout_ms: Option<u64>); } pub trait RtioSocket { @@ -245,6 +248,9 @@ pub trait RtioUdpSocket : RtioSocket { fn ignore_broadcasts(&mut self) -> IoResult<()>; fn clone(&self) -> Box<RtioUdpSocket:Send>; + fn set_timeout(&mut self, timeout_ms: Option<u64>); + fn set_read_timeout(&mut self, timeout_ms: Option<u64>); + fn set_write_timeout(&mut self, timeout_ms: Option<u64>); } pub trait RtioTimer { @@ -278,6 +284,9 @@ pub trait RtioPipe { fn close_write(&mut self) -> IoResult<()>; fn close_read(&mut self) -> IoResult<()>; + fn set_timeout(&mut self, timeout_ms: Option<u64>); + fn set_read_timeout(&mut self, timeout_ms: Option<u64>); + fn set_write_timeout(&mut self, timeout_ms: Option<u64>); } pub trait RtioUnixListener { diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 909df5618aa..8924ed7cfd2 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -323,6 +323,12 @@ impl BlockedTask { } } + /// Reawakens this task if ownership is acquired. If finer-grained control + /// is desired, use `wake` instead. + pub fn reawaken(self) { + self.wake().map(|t| t.reawaken()); + } + // This assertion has two flavours because the wake involves an atomic op. // In the faster version, destructors will fail dramatically instead. #[cfg(not(test))] pub fn trash(self) { } |
