Skip to content

Commit 73f24d4

Browse files
committed
Simple implementation of read2
1 parent de68ace commit 73f24d4

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/libstd/sys/redox/pipe.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
2323

2424
libc::pipe2(&mut fds, libc::O_CLOEXEC).map_err(|err| io::Error::from_raw_os_error(err.errno))?;
2525

26-
let fd0 = FileDesc::new(fds[0]);
27-
let fd1 = FileDesc::new(fds[1]);
28-
Ok((AnonPipe::from_fd(fd0)?, AnonPipe::from_fd(fd1)?))
26+
Ok((AnonPipe(FileDesc::new(fds[0])), AnonPipe(FileDesc::new(fds[1]))))
2927
}
3028

3129
impl AnonPipe {
@@ -50,12 +48,18 @@ impl AnonPipe {
5048
pub fn into_fd(self) -> FileDesc { self.0 }
5149
}
5250

53-
pub fn read2(_p1: AnonPipe,
54-
_v1: &mut Vec<u8>,
55-
_p2: AnonPipe,
56-
_v2: &mut Vec<u8>) -> io::Result<()> {
57-
::sys_common::util::dumb_print(format_args!("read2\n"));
58-
unimplemented!();
51+
pub fn read2(p1: AnonPipe,
52+
v1: &mut Vec<u8>,
53+
p2: AnonPipe,
54+
v2: &mut Vec<u8>) -> io::Result<()> {
55+
//TODO: Use event based I/O multiplexing
56+
//unimplemented!()
57+
58+
p1.read_to_end(v1)?;
59+
p2.read_to_end(v2)?;
60+
61+
Ok(())
62+
5963
/*
6064
// Set both pipes into nonblocking mode as we're gonna be reading from both
6165
// in the `select` loop below, and we wouldn't want one to block the other!
@@ -64,7 +68,6 @@ pub fn read2(_p1: AnonPipe,
6468
p1.set_nonblocking(true)?;
6569
p2.set_nonblocking(true)?;
6670
67-
let max = cmp::max(p1.raw(), p2.raw());
6871
loop {
6972
// wait for either pipe to become readable using `select`
7073
cvt_r(|| unsafe {

0 commit comments

Comments
 (0)