Skip to content

Commit 1763f36

Browse files
committed
Bring native process bindings up to date
Move the tests into libstd, use the `iotest!` macro to test both native and uv bindings, and use the cloexec trick to figure out when the child process fails in exec.
1 parent 00d87e0 commit 1763f36

File tree

9 files changed

+288
-254
lines changed

9 files changed

+288
-254
lines changed

src/libnative/io/file.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn keep_going(data: &[u8], f: |*u8, uint| -> i64) -> i64 {
3737
let mut ret;
3838
loop {
3939
ret = f(data, amt);
40-
if cfg!(not(windows)) { break } // windows has no eintr
40+
if cfg!(windows) { break } // windows has no eintr
4141
// if we get an eintr, then try again
4242
if ret != -1 || os::errno() as int != eintr { break }
4343
}
@@ -73,7 +73,10 @@ impl FileDesc {
7373
FileDesc { fd: fd, close_on_drop: close_on_drop }
7474
}
7575

76-
fn inner_read(&mut self, buf: &mut [u8]) -> Result<uint, IoError> {
76+
// FIXME(#10465) these functions should not be public, but anything in
77+
// native::io wanting to use them is forced to have all the
78+
// rtio traits in scope
79+
pub fn inner_read(&mut self, buf: &mut [u8]) -> Result<uint, IoError> {
7780
#[cfg(windows)] type rlen = libc::c_uint;
7881
#[cfg(not(windows))] type rlen = libc::size_t;
7982
let ret = keep_going(buf, |buf, len| {
@@ -899,7 +902,7 @@ pub fn utime(p: &CString, atime: u64, mtime: u64) -> IoResult<()> {
899902

900903
#[cfg(test)]
901904
mod tests {
902-
use super::{CFile, FileDesc};
905+
use super::{CFile, FileDesc, CloseFd};
903906
use std::io;
904907
use std::libc;
905908
use std::os;

src/libnative/io/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn unimpl() -> IoError {
5555
}
5656
}
5757

58-
fn last_error() -> IoError {
58+
fn translate_error(errno: i32, detail: bool) -> IoError {
5959
#[cfg(windows)]
6060
fn get_err(errno: i32) -> (io::IoErrorKind, &'static str) {
6161
match errno {
@@ -79,14 +79,16 @@ fn last_error() -> IoError {
7979
}
8080
}
8181

82-
let (kind, desc) = get_err(os::errno() as i32);
82+
let (kind, desc) = get_err(errno);
8383
IoError {
8484
kind: kind,
8585
desc: desc,
86-
detail: Some(os::last_os_error())
86+
detail: if detail {Some(os::last_os_error())} else {None},
8787
}
8888
}
8989

90+
fn last_error() -> IoError { translate_error(os::errno() as i32, true) }
91+
9092
// unix has nonzero values as errors
9193
fn mkerr_libc(ret: libc::c_int) -> IoResult<()> {
9294
if ret != 0 {
@@ -106,6 +108,17 @@ fn mkerr_winbool(ret: libc::c_int) -> IoResult<()> {
106108
}
107109
}
108110

111+
#[cfg(unix)]
112+
fn retry(f: || -> libc::c_int) -> IoResult<libc::c_int> {
113+
loop {
114+
match f() {
115+
-1 if os::errno() as int == libc::EINTR as int => {}
116+
-1 => return Err(last_error()),
117+
n => return Ok(n),
118+
}
119+
}
120+
}
121+
109122
/// Implementation of rt::rtio's IoFactory trait to generate handles to the
110123
/// native I/O functionality.
111124
pub struct IoFactory;

0 commit comments

Comments
 (0)