Skip to content

Commit 295e0a0

Browse files
committed
native: Implement timeouts for unix networking
This commit has an implementation of the previous commit's timeout interface for I/O objects on unix platforms. For implementation details, see the large comment at the end of libnative/io/net.rs which talks about the general strategy taken. Thankfully, all of these implementations can share code because they're performing all the same operations. This commit does not implement timeouts for named pipes on windows, only tcp/udp objects on windows (which are quite similar to their unix equivalents).
1 parent e27f27c commit 295e0a0

File tree

7 files changed

+493
-157
lines changed

7 files changed

+493
-157
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)