Skip to content

Commit c39b1cb

Browse files
committed
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.
2 parents 26632d5 + 418f197 commit c39b1cb

File tree

22 files changed

+1697
-468
lines changed

22 files changed

+1697
-468
lines changed

src/libnative/io/c_unix.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ pub static FIOCLEX: libc::c_ulong = 0x20006601;
2727
#[cfg(target_os = "android")]
2828
pub static FIOCLEX: libc::c_ulong = 0x5451;
2929

30+
#[cfg(target_os = "macos")]
31+
#[cfg(target_os = "freebsd")]
32+
pub static MSG_DONTWAIT: libc::c_int = 0x80;
33+
#[cfg(target_os = "linux")]
34+
#[cfg(target_os = "android")]
35+
pub static MSG_DONTWAIT: libc::c_int = 0x40;
36+
3037
extern {
3138
pub fn gettimeofday(timeval: *mut libc::timeval,
3239
tzp: *libc::c_void) -> libc::c_int;

src/libnative/io/c_win32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub static WSADESCRIPTION_LEN: uint = 256;
1818
pub static WSASYS_STATUS_LEN: uint = 128;
1919
pub static FIONBIO: libc::c_long = 0x8004667e;
2020
static FD_SETSIZE: uint = 64;
21+
pub static MSG_DONTWAIT: libc::c_int = 0;
2122

2223
pub struct WSADATA {
2324
pub wVersion: libc::WORD,

src/libnative/io/file_unix.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ impl rtio::RtioPipe for FileDesc {
189189
fn close_write(&mut self) -> Result<(), IoError> {
190190
Err(io::standard_error(io::InvalidInput))
191191
}
192+
fn set_timeout(&mut self, _t: Option<u64>) {}
193+
fn set_read_timeout(&mut self, _t: Option<u64>) {}
194+
fn set_write_timeout(&mut self, _t: Option<u64>) {}
192195
}
193196

194197
impl rtio::RtioTTY for FileDesc {

src/libnative/io/file_win32.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ impl rtio::RtioPipe for FileDesc {
221221
fn close_write(&mut self) -> IoResult<()> {
222222
Err(io::standard_error(io::InvalidInput))
223223
}
224+
fn set_timeout(&mut self, _t: Option<u64>) {}
225+
fn set_read_timeout(&mut self, _t: Option<u64>) {}
226+
fn set_write_timeout(&mut self, _t: Option<u64>) {}
224227
}
225228

226229
impl rtio::RtioTTY for FileDesc {

0 commit comments

Comments
 (0)