File tree Expand file tree Collapse file tree 4 files changed +44
-6
lines changed Expand file tree Collapse file tree 4 files changed +44
-6
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5
5
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
- refs/heads/try2: 262b958a4bedf419335069c95f054a22da48a88a
8
+ refs/heads/try2: 816e46dd633cf4cc5741dde6ce3bffd4a9ba67a7
9
9
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change 16
16
use prelude:: * ;
17
17
use super :: { Reader , Writer } ;
18
18
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} ;
20
21
21
22
pub struct PipeStream {
22
23
priv obj: ~RtioPipe ,
23
24
}
24
25
25
26
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
+
26
58
pub fn new ( inner : ~RtioPipe ) -> PipeStream {
27
59
PipeStream { obj : inner }
28
60
}
Original file line number Diff line number Diff line change @@ -322,6 +322,7 @@ mod tests {
322
322
use path:: Path ;
323
323
use run;
324
324
use str;
325
+ use task:: spawn;
325
326
use unstable:: running_on_valgrind;
326
327
use rt:: io:: native:: file;
327
328
use rt:: io:: { Writer , Reader } ;
@@ -394,6 +395,7 @@ mod tests {
394
395
}
395
396
396
397
#[test]
398
+ #[ignore] // FIXME(#10016) cat never sees stdin close
397
399
fn test_pipes() {
398
400
399
401
let pipe_in = os::pipe();
@@ -412,13 +414,14 @@ mod tests {
412
414
os::close(pipe_out.out);
413
415
os::close(pipe_err.out);
414
416
415
- let expected = ~" test";
416
- writeclose(pipe_in.out, expected);
417
+ do spawn {
418
+ writeclose(pipe_in.out, ~" test");
419
+ }
417
420
let actual = readclose(pipe_out.input);
418
421
readclose(pipe_err.input);
419
422
proc.finish();
420
423
421
- assert_eq!(expected , actual);
424
+ assert_eq!(~" test " , actual);
422
425
}
423
426
424
427
fn writeclose(fd: c_int, s: &str) {
Original file line number Diff line number Diff line change 18
18
use std:: libc;
19
19
use std:: run;
20
20
use std:: str;
21
+ use std:: rt:: io;
21
22
22
23
#[ test]
23
24
fn test_destroy_once ( ) {
@@ -29,7 +30,9 @@ fn test_destroy_once() {
29
30
fn test_destroy_twice ( ) {
30
31
let mut p = run:: Process :: new ( "echo" , [ ] , run:: ProcessOptions :: new ( ) ) ;
31
32
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
+ }
33
36
}
34
37
35
38
fn test_destroy_actually_kills ( force : bool ) {
You can’t perform that action at this time.
0 commit comments