about summary refs log tree commit diff
path: root/src/libstd/sys/windows/process.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-05-12 11:03:49 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-05-16 11:18:36 -0700
commit3dd3450484c1a914d07da2ab522e3bd27ce2a4bb (patch)
tree036734c4a002be0f56eb75901802ac32f9a5000d /src/libstd/sys/windows/process.rs
parent5e535eae5c4b70879aefc050a5fe0b8137c07eac (diff)
downloadrust-3dd3450484c1a914d07da2ab522e3bd27ce2a4bb.tar.gz
rust-3dd3450484c1a914d07da2ab522e3bd27ce2a4bb.zip
std: Implement lowering and raising for process IO
This commit implements a number of standard traits for the standard library's
process I/O handles. The `FromRaw{Fd,Handle}` traits are now implemented for the
`Stdio` type and the `AsRaw{Fd,Handle}` traits are now implemented for the
`Child{Stdout,Stdin,Stderr}` types. Additionally this implements the
`AsRawHandle` trait for `Child` on Windows.

The stability markers for these implementations mention that they are stable for
1.1 as I will nominate this commit for cherry-picking to beta.
Diffstat (limited to 'src/libstd/sys/windows/process.rs')
-rw-r--r--src/libstd/sys/windows/process.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs
index 032a349b00e..9b0ab692a34 100644
--- a/src/libstd/sys/windows/process.rs
+++ b/src/libstd/sys/windows/process.rs
@@ -27,7 +27,7 @@ use ptr;
 use sync::{StaticMutex, MUTEX_INIT};
 use sys::c;
 use sys::fs::{OpenOptions, File};
-use sys::handle::Handle;
+use sys::handle::{Handle, RawHandle};
 use sys::pipe::AnonPipe;
 use sys::stdio;
 use sys::{self, cvt};
@@ -109,6 +109,7 @@ pub enum Stdio {
     Inherit,
     Piped(AnonPipe),
     None,
+    Handle(RawHandle),
 }
 
 impl Process {
@@ -211,6 +212,8 @@ impl Process {
             }
         }
     }
+
+    pub fn handle(&self) -> &Handle { &self.handle }
 }
 
 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
@@ -347,6 +350,15 @@ fn make_dirp(d: Option<&OsString>) -> (*const u16, Vec<u16>) {
 }
 
 impl Stdio {
+    pub fn clone_if_copy(&self) -> Stdio {
+        match *self {
+            Stdio::Inherit => Stdio::Inherit,
+            Stdio::None => Stdio::None,
+            Stdio::Handle(handle) => Stdio::Handle(handle),
+            Stdio::Piped(_) => unreachable!(),
+        }
+    }
+
     fn to_handle(&self, stdio_id: libc::DWORD) -> io::Result<Handle> {
         use libc::DUPLICATE_SAME_ACCESS;
 
@@ -356,6 +368,9 @@ impl Stdio {
                     io.handle().duplicate(0, true, DUPLICATE_SAME_ACCESS)
                 })
             }
+            Stdio::Handle(ref handle) => {
+                handle.duplicate(0, true, DUPLICATE_SAME_ACCESS)
+            }
             Stdio::Piped(ref pipe) => {
                 pipe.handle().duplicate(0, true, DUPLICATE_SAME_ACCESS)
             }