about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-10-16 11:39:51 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-10-24 14:21:56 -0700
commit32b07c6a40bd7e1874244096f413096a6e059a29 (patch)
tree6ac20628e90c670b3447e31259c833176cb6e49e /src/libstd
parentc6fa4e277f5eb873e979d8ac1ae7a4c3ccb1e9cc (diff)
downloadrust-32b07c6a40bd7e1874244096f413096a6e059a29.tar.gz
rust-32b07c6a40bd7e1874244096f413096a6e059a29.zip
Remove unbound pipes from io::pipe
This isn't necessary for creating processes (or at least not right now), and
it inherently attempts to expose implementation details.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/rt/io/mod.rs1
-rw-r--r--src/libstd/rt/io/pipe.rs24
-rw-r--r--src/libstd/rt/io/process.rs8
-rw-r--r--src/libstd/rt/rtio.rs2
-rw-r--r--src/libstd/rt/uv/process.rs13
-rw-r--r--src/libstd/rt/uv/uvio.rs15
6 files changed, 22 insertions, 41 deletions
diff --git a/src/libstd/rt/io/mod.rs b/src/libstd/rt/io/mod.rs
index a703f9885ac..eaff43378f2 100644
--- a/src/libstd/rt/io/mod.rs
+++ b/src/libstd/rt/io/mod.rs
@@ -261,7 +261,6 @@ pub use self::net::tcp::TcpListener;
 pub use self::net::tcp::TcpStream;
 pub use self::net::udp::UdpStream;
 pub use self::pipe::PipeStream;
-pub use self::pipe::UnboundPipeStream;
 pub use self::process::Process;
 
 // Some extension traits that all Readers and Writers get.
diff --git a/src/libstd/rt/io/pipe.rs b/src/libstd/rt/io/pipe.rs
index ff1bd55d594..67e04f57f4f 100644
--- a/src/libstd/rt/io/pipe.rs
+++ b/src/libstd/rt/io/pipe.rs
@@ -16,35 +16,13 @@
 use prelude::*;
 use super::{Reader, Writer};
 use rt::io::{io_error, read_error, EndOfFile};
-use rt::local::Local;
-use rt::rtio::{RtioPipe, RtioPipeObject, IoFactoryObject, IoFactory};
-use rt::rtio::RtioUnboundPipeObject;
+use rt::rtio::{RtioPipe, RtioPipeObject};
 
 pub struct PipeStream {
     priv obj: ~RtioPipeObject
 }
 
-// This should not be a newtype, but rt::uv::process::set_stdio needs to reach
-// into the internals of this :(
-pub struct UnboundPipeStream(~RtioUnboundPipeObject);
-
 impl PipeStream {
-    /// Creates a new pipe initialized, but not bound to any particular
-    /// source/destination
-    pub fn new() -> Option<UnboundPipeStream> {
-        let pipe = unsafe {
-            let io: *mut IoFactoryObject = Local::unsafe_borrow();
-            (*io).pipe_init(false)
-        };
-        match pipe {
-            Ok(p) => Some(UnboundPipeStream(p)),
-            Err(ioerr) => {
-                io_error::cond.raise(ioerr);
-                None
-            }
-        }
-    }
-
     pub fn new_bound(inner: ~RtioPipeObject) -> PipeStream {
         PipeStream { obj: inner }
     }
diff --git a/src/libstd/rt/io/process.rs b/src/libstd/rt/io/process.rs
index 0da9c2166b1..f6e8b87344f 100644
--- a/src/libstd/rt/io/process.rs
+++ b/src/libstd/rt/io/process.rs
@@ -70,15 +70,13 @@ pub enum StdioContainer {
     /// specified for.
     InheritFd(libc::c_int),
 
-    /// Creates a pipe for the specified file descriptor which will be directed
-    /// into the previously-initialized pipe passed in.
+    /// Creates a pipe for the specified file descriptor which will be created
+    /// when the process is spawned.
     ///
     /// The first boolean argument is whether the pipe is readable, and the
     /// second is whether it is writable. These properties are from the view of
     /// the *child* process, not the parent process.
-    CreatePipe(io::UnboundPipeStream,
-               bool /* readable */,
-               bool /* writable */),
+    CreatePipe(bool /* readable */, bool /* writable */),
 }
 
 impl Process {
diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs
index 4a290ca46e5..c37d9bf913b 100644
--- a/src/libstd/rt/rtio.rs
+++ b/src/libstd/rt/rtio.rs
@@ -35,7 +35,6 @@ pub type RtioUdpSocketObject = uvio::UvUdpSocket;
 pub type RtioTimerObject = uvio::UvTimer;
 pub type PausibleIdleCallback = uvio::UvPausibleIdleCallback;
 pub type RtioPipeObject = uvio::UvPipeStream;
-pub type RtioUnboundPipeObject = uvio::UvUnboundPipe;
 pub type RtioProcessObject = uvio::UvProcess;
 pub type RtioUnixListenerObject = uvio::UvUnixListener;
 pub type RtioUnixAcceptorObject = uvio::UvUnixAcceptor;
@@ -88,7 +87,6 @@ pub trait IoFactory {
     fn fs_rmdir<P: PathLike>(&mut self, path: &P) -> Result<(), IoError>;
     fn fs_readdir<P: PathLike>(&mut self, path: &P, flags: c_int) ->
         Result<~[Path], IoError>;
-    fn pipe_init(&mut self, ipc: bool) -> Result<~RtioUnboundPipeObject, IoError>;
     fn spawn(&mut self, config: ProcessConfig)
             -> Result<(~RtioProcessObject, ~[Option<~RtioPipeObject>]), IoError>;
 
diff --git a/src/libstd/rt/uv/process.rs b/src/libstd/rt/uv/process.rs
index 3c629a783cf..25c516b6008 100644
--- a/src/libstd/rt/uv/process.rs
+++ b/src/libstd/rt/uv/process.rs
@@ -17,7 +17,7 @@ use vec;
 
 use rt::io::process::*;
 use rt::uv;
-use rt::uv::uvio::UvPipeStream;
+use rt::uv::uvio::{UvPipeStream, UvUnboundPipe};
 use rt::uv::uvll;
 
 /// A process wraps the handle of the underlying uv_process_t.
@@ -68,7 +68,8 @@ impl Process {
         unsafe {
             vec::raw::set_len(&mut stdio, io.len());
             for (slot, other) in stdio.iter().zip(io.move_iter()) {
-                let io = set_stdio(slot as *uvll::uv_stdio_container_t, other);
+                let io = set_stdio(slot as *uvll::uv_stdio_container_t, other,
+                                   loop_);
                 ret_io.push(io);
             }
         }
@@ -144,7 +145,8 @@ impl Process {
 }
 
 unsafe fn set_stdio(dst: *uvll::uv_stdio_container_t,
-                    io: StdioContainer) -> Option<~UvPipeStream> {
+                    io: StdioContainer,
+                    loop_: &uv::Loop) -> Option<~UvPipeStream> {
     match io {
         Ignored => {
             uvll::set_stdio_container_flags(dst, uvll::STDIO_IGNORE);
@@ -155,7 +157,7 @@ unsafe fn set_stdio(dst: *uvll::uv_stdio_container_t,
             uvll::set_stdio_container_fd(dst, fd);
             None
         }
-        CreatePipe(pipe, readable, writable) => {
+        CreatePipe(readable, writable) => {
             let mut flags = uvll::STDIO_CREATE_PIPE as libc::c_int;
             if readable {
                 flags |= uvll::STDIO_READABLE_PIPE as libc::c_int;
@@ -163,10 +165,11 @@ unsafe fn set_stdio(dst: *uvll::uv_stdio_container_t,
             if writable {
                 flags |= uvll::STDIO_WRITABLE_PIPE as libc::c_int;
             }
+            let pipe = UvUnboundPipe::new_fresh(loop_);
             let handle = pipe.pipe.as_stream().native_handle();
             uvll::set_stdio_container_flags(dst, flags);
             uvll::set_stdio_container_stream(dst, handle);
-            Some(~UvPipeStream::new(**pipe))
+            Some(~UvPipeStream::new(pipe))
         }
     }
 }
diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs
index bc9be40cde5..db19bc7463a 100644
--- a/src/libstd/rt/uv/uvio.rs
+++ b/src/libstd/rt/uv/uvio.rs
@@ -749,11 +749,6 @@ impl IoFactory for UvIoFactory {
         return result_cell.take();
     }
 
-    fn pipe_init(&mut self, ipc: bool) -> Result<~RtioUnboundPipeObject, IoError> {
-        let home = get_handle_to_current_scheduler!();
-        Ok(~UvUnboundPipe::new(Pipe::new(self.uv_loop(), ipc), home))
-    }
-
     fn spawn(&mut self, config: ProcessConfig)
             -> Result<(~RtioProcessObject, ~[Option<~RtioPipeObject>]), IoError>
     {
@@ -1069,9 +1064,19 @@ pub struct UvUnboundPipe {
 }
 
 impl UvUnboundPipe {
+    /// Takes ownership of an unbound pipe along with the scheduler that it is
+    /// homed on.
     fn new(pipe: Pipe, home: SchedHandle) -> UvUnboundPipe {
         UvUnboundPipe { pipe: pipe, home: home }
     }
+
+    /// Creates a fresh new unbound pipe on the specified I/O loop
+    pub fn new_fresh(loop_: &Loop) -> UvUnboundPipe {
+        UvUnboundPipe {
+            pipe: Pipe::new(loop_, false),
+            home: get_handle_to_current_scheduler!(),
+        }
+    }
 }
 
 impl HomingIO for UvUnboundPipe {