Skip to content

Commit 9bf13eb

Browse files
committed
---
yaml --- r: 146173 b: refs/heads/try2 c: 816e46d h: refs/heads/master i: 146171: 97e2529 v: v3
1 parent 925b4b1 commit 9bf13eb

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 262b958a4bedf419335069c95f054a22da48a88a
8+
refs/heads/try2: 816e46dd633cf4cc5741dde6ce3bffd4a9ba67a7
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/rt/io/pipe.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,45 @@
1616
use prelude::*;
1717
use super::{Reader, Writer};
1818
use rt::io::{io_error, EndOfFile};
19-
use rt::rtio::RtioPipe;
19+
use rt::io::native::file;
20+
use rt::rtio::{RtioPipe, with_local_io};
2021

2122
pub struct PipeStream {
2223
priv obj: ~RtioPipe,
2324
}
2425

2526
impl PipeStream {
27+
/// Consumes a file descriptor to return a pipe stream that will have
28+
/// synchronous, but non-blocking reads/writes. This is useful if the file
29+
/// descriptor is acquired via means other than the standard methods.
30+
///
31+
/// This operation consumes ownership of the file descriptor and it will be
32+
/// closed once the object is deallocated.
33+
///
34+
/// # Example
35+
///
36+
/// use std::libc;
37+
/// use std::rt::io::pipe;
38+
///
39+
/// let mut pipe = PipeStream::open(libc::STDERR_FILENO);
40+
/// pipe.write(bytes!("Hello, stderr!"));
41+
///
42+
/// # Failure
43+
///
44+
/// If the pipe cannot be created, an error will be raised on the
45+
/// `io_error` condition.
46+
pub fn open(fd: file::fd_t) -> Option<PipeStream> {
47+
do with_local_io |io| {
48+
match io.pipe_open(fd) {
49+
Ok(obj) => Some(PipeStream { obj: obj }),
50+
Err(e) => {
51+
io_error::cond.raise(e);
52+
None
53+
}
54+
}
55+
}
56+
}
57+
2658
pub fn new(inner: ~RtioPipe) -> PipeStream {
2759
PipeStream { obj: inner }
2860
}

branches/try2/src/libstd/run.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ mod tests {
322322
use path::Path;
323323
use run;
324324
use str;
325+
use task::spawn;
325326
use unstable::running_on_valgrind;
326327
use rt::io::native::file;
327328
use rt::io::{Writer, Reader};
@@ -394,6 +395,7 @@ mod tests {
394395
}
395396
396397
#[test]
398+
#[ignore] // FIXME(#10016) cat never sees stdin close
397399
fn test_pipes() {
398400
399401
let pipe_in = os::pipe();
@@ -412,13 +414,14 @@ mod tests {
412414
os::close(pipe_out.out);
413415
os::close(pipe_err.out);
414416
415-
let expected = ~"test";
416-
writeclose(pipe_in.out, expected);
417+
do spawn {
418+
writeclose(pipe_in.out, ~"test");
419+
}
417420
let actual = readclose(pipe_out.input);
418421
readclose(pipe_err.input);
419422
proc.finish();
420423
421-
assert_eq!(expected, actual);
424+
assert_eq!(~"test", actual);
422425
}
423426
424427
fn writeclose(fd: c_int, s: &str) {

branches/try2/src/test/run-pass/core-run-destroy.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use std::libc;
1919
use std::run;
2020
use std::str;
21+
use std::rt::io;
2122

2223
#[test]
2324
fn test_destroy_once() {
@@ -29,7 +30,9 @@ fn test_destroy_once() {
2930
fn test_destroy_twice() {
3031
let mut p = run::Process::new("echo", [], run::ProcessOptions::new());
3132
p.destroy(); // this shouldnt crash...
32-
p.destroy(); // ...and nor should this (and nor should the destructor)
33+
do io::io_error::cond.trap(|_| {}).inside {
34+
p.destroy(); // ...and nor should this (and nor should the destructor)
35+
}
3336
}
3437

3538
fn test_destroy_actually_kills(force: bool) {

0 commit comments

Comments
 (0)