mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
process: Simplify child IO registration
This commit is contained in:
+10
-19
@@ -164,7 +164,7 @@ extern crate tokio_reactor;
|
|||||||
extern crate mio;
|
extern crate mio;
|
||||||
|
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::process::{self, ExitStatus, Output, Stdio};
|
use std::process::{Command, ExitStatus, Output, Stdio};
|
||||||
|
|
||||||
use futures::{Future, Poll, IntoFuture};
|
use futures::{Future, Poll, IntoFuture};
|
||||||
use futures::future::{Either, ok};
|
use futures::future::{Either, ok};
|
||||||
@@ -320,25 +320,16 @@ pub trait CommandExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl CommandExt for process::Command {
|
impl CommandExt for Command {
|
||||||
fn spawn_async_with_handle(&mut self, handle: &Handle) -> io::Result<Child> {
|
fn spawn_async_with_handle(&mut self, handle: &Handle) -> io::Result<Child> {
|
||||||
let mut child = Child {
|
imp::Child::new(self.spawn()?, handle)
|
||||||
child: imp::Child::new(try!(self.spawn()), handle),
|
.map(|(child, stdin, stdout, stderr)| Child {
|
||||||
stdin: None,
|
child,
|
||||||
stdout: None,
|
stdin: stdin.map(|inner| ChildStdin { inner }),
|
||||||
stderr: None,
|
stdout: stdout.map(|inner| ChildStdout { inner }),
|
||||||
kill_on_drop: true,
|
stderr: stderr.map(|inner| ChildStderr { inner }),
|
||||||
};
|
kill_on_drop: true,
|
||||||
child.stdin = try!(child.child.register_stdin(handle)).map(|io| {
|
})
|
||||||
ChildStdin { inner: io }
|
|
||||||
});
|
|
||||||
child.stdout = try!(child.child.register_stdout(handle)).map(|io| {
|
|
||||||
ChildStdout { inner: io }
|
|
||||||
});
|
|
||||||
child.stderr = try!(child.child.register_stderr(handle)).map(|io| {
|
|
||||||
ChildStderr { inner: io }
|
|
||||||
});
|
|
||||||
Ok(child)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn status_async_with_handle(&mut self, handle: &Handle) -> io::Result<StatusAsync> {
|
fn status_async_with_handle(&mut self, handle: &Handle) -> io::Result<StatusAsync> {
|
||||||
|
|||||||
+10
-17
@@ -58,27 +58,20 @@ impl fmt::Debug for Child {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Child {
|
impl Child {
|
||||||
pub fn new(inner: process::Child, handle: &Handle) -> Child {
|
pub fn new(mut inner: process::Child, handle: &Handle)
|
||||||
Child {
|
-> io::Result<(Child, Option<ChildStdin>, Option<ChildStdout>, Option<ChildStderr>)>
|
||||||
|
{
|
||||||
|
let stdin = stdio(inner.stdin.take(), handle)?;
|
||||||
|
let stdout = stdio(inner.stdout.take(), handle)?;
|
||||||
|
let stderr = stdio(inner.stderr.take(), handle)?;
|
||||||
|
|
||||||
|
let child = Child {
|
||||||
inner: inner,
|
inner: inner,
|
||||||
reaped: false,
|
reaped: false,
|
||||||
sigchld: Signal::with_handle(libc::SIGCHLD, handle).flatten_stream(),
|
sigchld: Signal::with_handle(libc::SIGCHLD, handle).flatten_stream(),
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register_stdin(&mut self, handle: &Handle)
|
Ok((child, stdin, stdout, stderr))
|
||||||
-> io::Result<Option<ChildStdin>> {
|
|
||||||
stdio(self.inner.stdin.take(), handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register_stdout(&mut self, handle: &Handle)
|
|
||||||
-> io::Result<Option<ChildStdout>> {
|
|
||||||
stdio(self.inner.stdout.take(), handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register_stderr(&mut self, handle: &Handle)
|
|
||||||
-> io::Result<Option<ChildStderr>> {
|
|
||||||
stdio(self.inner.stderr.take(), handle)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id(&self) -> u32 {
|
pub fn id(&self) -> u32 {
|
||||||
|
|||||||
+11
-18
@@ -64,26 +64,19 @@ unsafe impl Sync for Waiting {}
|
|||||||
unsafe impl Send for Waiting {}
|
unsafe impl Send for Waiting {}
|
||||||
|
|
||||||
impl Child {
|
impl Child {
|
||||||
pub fn new(child: process::Child, _handle: &Handle) -> Child {
|
pub fn new(mut inner: process::Child, handle: &Handle)
|
||||||
Child {
|
-> io::Result<(Child, Option<ChildStdin>, Option<ChildStdout>, Option<ChildStderr>)>
|
||||||
child: child,
|
{
|
||||||
|
let stdin = stdio(inner.stdin.take(), handle)?;
|
||||||
|
let stdout = stdio(inner.stdout.take(), handle)?;
|
||||||
|
let stderr = stdio(inner.stderr.take(), handle)?;
|
||||||
|
|
||||||
|
let child = Child {
|
||||||
|
child: inner,
|
||||||
waiting: None,
|
waiting: None,
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register_stdin(&mut self, handle: &Handle)
|
Ok((child, stdin, stdout, stderr))
|
||||||
-> io::Result<Option<ChildStdin>> {
|
|
||||||
stdio(self.child.stdin.take(), handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register_stdout(&mut self, handle: &Handle)
|
|
||||||
-> io::Result<Option<ChildStdout>> {
|
|
||||||
stdio(self.child.stdout.take(), handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register_stderr(&mut self, handle: &Handle)
|
|
||||||
-> io::Result<Option<ChildStderr>> {
|
|
||||||
stdio(self.child.stderr.take(), handle)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id(&self) -> u32 {
|
pub fn id(&self) -> u32 {
|
||||||
|
|||||||
Reference in New Issue
Block a user