From 1384b31d60b401c28a8ecb7544ecbe7381faa574 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 9 Mar 2017 09:16:04 -0800 Subject: [PATCH] process: Update to tokio-io, mio, and tokio-core changes --- Cargo.toml | 9 +++++---- src/lib.rs | 16 +++++++++++++++- src/unix.rs | 11 ++++++----- src/windows.rs | 14 ++++++++------ tests/stdio.rs | 5 +++-- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d88accfdc..82fae17ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,11 @@ travis-ci = { repository = "alexcrichton/tokio-process" } appveyor = { repository = "alexcrichton/tokio-process" } [dependencies] -tokio-core = "0.1.2" -futures = "0.1.7" -mio = "0.6" +futures = "0.1.11" log = "0.3" +mio = "0.6.5" +tokio-core = "0.1.6" +tokio-io = "0.1" [dev-dependencies] env_logger = { version = "0.3", default-features = false } @@ -31,4 +32,4 @@ mio-named-pipes = "0.1" [target.'cfg(unix)'.dependencies] libc = "0.2" -tokio-signal = "0.1.2" +tokio-signal = "0.1" diff --git a/src/lib.rs b/src/lib.rs index f17a36259..5938ce55a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,6 +86,7 @@ #[macro_use] extern crate futures; extern crate tokio_core; +extern crate tokio_io; extern crate mio; #[macro_use] extern crate log; @@ -98,7 +99,8 @@ use std::process::{self, ExitStatus, Output, Stdio}; use futures::{Future, Poll, IntoFuture}; use futures::future::{Flatten, FutureResult, Either, ok}; use tokio_core::reactor::Handle; -use tokio_core::io::{IoFuture, read_to_end}; +use tokio_io::io::{read_to_end}; +use tokio_io::{AsyncWrite, AsyncRead, IoFuture}; #[path = "unix.rs"] #[cfg(unix)] @@ -423,18 +425,30 @@ impl Write for ChildStdin { } } +impl AsyncWrite for ChildStdin { + fn shutdown(&mut self) -> Poll<(), io::Error> { + self.inner.shutdown() + } +} + impl Read for ChildStdout { fn read(&mut self, bytes: &mut [u8]) -> io::Result { self.inner.read(bytes) } } +impl AsyncRead for ChildStdout { +} + impl Read for ChildStderr { fn read(&mut self, bytes: &mut [u8]) -> io::Result { self.inner.read(bytes) } } +impl AsyncRead for ChildStderr { +} + // deprecated from 0.1.0 #[deprecated(note = "use std::process::Command instead")] diff --git a/src/unix.rs b/src/unix.rs index b29e9b1f7..47cec7b77 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -30,12 +30,13 @@ use std::process::{self, ExitStatus}; use futures::future::FlattenStream; use futures::{Future, Poll, Async, Stream}; -use mio::unix::EventedFd; -use mio::{Evented, PollOpt, Ready, Token}; +use mio::unix::{EventedFd, UnixReady}; +use mio::{PollOpt, Ready, Token}; +use mio::event::Evented; use mio; use self::libc::c_int; use self::tokio_signal::unix::Signal; -use tokio_core::io::IoFuture; +use tokio_io::IoFuture; use tokio_core::reactor::{Handle, PollEvented}; pub struct Child { @@ -155,7 +156,7 @@ impl Evented for Fd where T: AsRawFd { -> io::Result<()> { EventedFd(&self.0.as_raw_fd()).register(poll, token, - interest | Ready::hup(), + interest | UnixReady::hup(), opts) } @@ -167,7 +168,7 @@ impl Evented for Fd where T: AsRawFd { -> io::Result<()> { EventedFd(&self.0.as_raw_fd()).reregister(poll, token, - interest | Ready::hup(), + interest | UnixReady::hup(), opts) } diff --git a/src/windows.rs b/src/windows.rs index 7feaa6e05..4febf57f0 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -24,7 +24,9 @@ use std::os::windows::prelude::*; use std::os::windows::process::ExitStatusExt; use std::process::{self, ExitStatus}; -use futures::{Future, Poll, Async, Oneshot, Complete, oneshot, Fuse}; +use futures::{Future, Poll, Async} ; +use futures::sync::oneshot; +use futures::future::Fuse; use self::mio_named_pipes::NamedPipe; use tokio_core::reactor::{PollEvented, Handle}; @@ -34,9 +36,9 @@ pub struct Child { } struct Waiting { - rx: Fuse>, + rx: Fuse>, wait_object: winapi::HANDLE, - tx: *mut Option>, + tx: *mut Option>, } unsafe impl Sync for Waiting {} @@ -87,7 +89,7 @@ impl Child { if let Some(e) = try!(try_wait(&self.child)) { return Ok(e.into()) } - let (tx, rx) = oneshot(); + let (tx, rx) = oneshot::channel(); let ptr = Box::into_raw(Box::new(Some(tx))); let mut wait_object = 0 as *mut _; let rc = unsafe { @@ -128,8 +130,8 @@ impl Drop for Waiting { unsafe extern "system" fn callback(ptr: winapi::PVOID, _timer_fired: winapi::BOOLEAN) { - let mut complete = &mut *(ptr as *mut Option>); - complete.take().unwrap().complete(()); + let mut complete = &mut *(ptr as *mut Option>); + drop(complete.take().unwrap().send(())); } pub fn try_wait(child: &process::Child) -> io::Result> { diff --git a/tests/stdio.rs b/tests/stdio.rs index a09426453..e1353ec1f 100644 --- a/tests/stdio.rs +++ b/tests/stdio.rs @@ -1,6 +1,7 @@ extern crate futures; #[macro_use] extern crate tokio_core; +extern crate tokio_io; extern crate tokio_process; #[macro_use] extern crate log; @@ -9,9 +10,9 @@ extern crate env_logger; use std::io; use std::process::{Stdio, ExitStatus, Command}; -use futures::{Future, BoxFuture}; +use futures::future::{BoxFuture, Future}; use futures::stream::{self, Stream}; -use tokio_core::io::{read_until, write_all, read_to_end}; +use tokio_io::io::{read_until, write_all, read_to_end}; use tokio_core::reactor::Core; use tokio_process::{CommandExt, Child};