mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
Remove dead futures2 code. (#538)
The futures 0.2 crate is not intended for widespread usage. Also, the futures team is exploring the compat shim route. If futures 0.3 support is added to Tokio 0.1, then a different integration route will be explored, making the current code unhelpful.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use {Reactor, Handle, Task};
|
||||
use {Reactor, Handle};
|
||||
use atomic_task::AtomicTask;
|
||||
|
||||
use futures::{Future, Async, Poll, task};
|
||||
@@ -136,7 +136,7 @@ impl Future for Shutdown {
|
||||
type Error = ();
|
||||
|
||||
fn poll(&mut self) -> Poll<(), ()> {
|
||||
let task = Task::Futures1(task::current());
|
||||
let task = task::current();
|
||||
self.inner.shared.shutdown_task.register_task(task);
|
||||
|
||||
if !self.inner.is_shutdown() {
|
||||
|
||||
@@ -44,9 +44,6 @@ extern crate slab;
|
||||
extern crate tokio_executor;
|
||||
extern crate tokio_io;
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
extern crate futures2;
|
||||
|
||||
mod atomic_task;
|
||||
pub(crate) mod background;
|
||||
mod poll_evented;
|
||||
@@ -64,6 +61,7 @@ pub use self::poll_evented::PollEvented;
|
||||
use atomic_task::AtomicTask;
|
||||
use sharded_rwlock::RwLock;
|
||||
|
||||
use futures::task::Task;
|
||||
use tokio_executor::Enter;
|
||||
use tokio_executor::park::{Park, Unpark};
|
||||
|
||||
@@ -184,14 +182,6 @@ fn _assert_kinds() {
|
||||
_assert::<Handle>();
|
||||
}
|
||||
|
||||
/// A wakeup handle for a task, which may be either a futures 0.1 or 0.2 task
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) enum Task {
|
||||
Futures1(futures::task::Task),
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
Futures2(futures2::task::Waker),
|
||||
}
|
||||
|
||||
// ===== impl Reactor =====
|
||||
|
||||
/// Set the default reactor for the duration of the closure
|
||||
@@ -726,17 +716,6 @@ impl Direction {
|
||||
}
|
||||
}
|
||||
|
||||
impl Task {
|
||||
fn notify(&self) {
|
||||
match *self {
|
||||
Task::Futures1(ref task) => task.notify(),
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
Task::Futures2(ref waker) => waker.wake(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
mod platform {
|
||||
use mio::Ready;
|
||||
@@ -764,22 +743,6 @@ mod platform {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
fn lift_async<T>(old: futures::Async<T>) -> futures2::Async<T> {
|
||||
match old {
|
||||
futures::Async::Ready(x) => futures2::Async::Ready(x),
|
||||
futures::Async::NotReady => futures2::Async::Pending,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
fn lower_async<T>(new: futures2::Async<T>) -> futures::Async<T> {
|
||||
match new {
|
||||
futures2::Async::Ready(x) => futures::Async::Ready(x),
|
||||
futures2::Async::Pending => futures::Async::NotReady,
|
||||
}
|
||||
}
|
||||
|
||||
// ===== impl SetFallbackError =====
|
||||
|
||||
impl fmt::Display for SetFallbackError {
|
||||
|
||||
@@ -5,9 +5,6 @@ use mio;
|
||||
use mio::event::Evented;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
use futures2;
|
||||
|
||||
use std::fmt;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
@@ -228,19 +225,6 @@ where E: Evented
|
||||
)
|
||||
}
|
||||
|
||||
/// Like `poll_read_ready` but compatible with futures 0.2.
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
pub fn poll_read_ready2(&self, cx: &mut futures2::task::Context, mask: mio::Ready)
|
||||
-> futures2::Poll<mio::Ready, io::Error>
|
||||
{
|
||||
assert!(!mask.is_writable(), "cannot poll for write readiness");
|
||||
let mut res = || poll_ready!(
|
||||
self, mask, read_readiness, take_read_ready,
|
||||
self.inner.registration.poll_read_ready2(cx).map(::lower_async)
|
||||
);
|
||||
res().map(::lift_async)
|
||||
}
|
||||
|
||||
/// Clears the I/O resource's read readiness state and registers the current
|
||||
/// task to be notified once a read readiness event is received.
|
||||
///
|
||||
@@ -271,25 +255,6 @@ where E: Evented
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Like `clear_read_ready` but compatible with futures 0.2.
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
pub fn clear_read_ready2(&self, cx: &mut futures2::task::Context, ready: mio::Ready)
|
||||
-> io::Result<()>
|
||||
{
|
||||
// Cannot clear write readiness
|
||||
assert!(!ready.is_writable(), "cannot clear write readiness");
|
||||
assert!(!::platform::is_hup(&ready), "cannot clear HUP readiness");
|
||||
|
||||
self.inner.read_readiness.fetch_and(!ready.as_usize(), Relaxed);
|
||||
|
||||
if self.poll_read_ready2(cx, ready)?.is_ready() {
|
||||
// Notify the current task
|
||||
cx.waker().wake()
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check the I/O resource's write readiness state.
|
||||
///
|
||||
/// This always checks for writable readiness and also checks for HUP
|
||||
@@ -319,22 +284,6 @@ where E: Evented
|
||||
)
|
||||
}
|
||||
|
||||
/// Like `poll_write_ready` but compatible with futures 0.2.
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
pub fn poll_write_ready2(&self, cx: &mut futures2::task::Context)
|
||||
-> futures2::Poll<mio::Ready, io::Error>
|
||||
{
|
||||
let mut res = || poll_ready!(
|
||||
self,
|
||||
mio::Ready::writable(),
|
||||
write_readiness,
|
||||
take_write_ready,
|
||||
self.inner.registration.poll_write_ready2(cx).map(::lower_async)
|
||||
);
|
||||
res().map(::lift_async)
|
||||
}
|
||||
|
||||
|
||||
/// Resets the I/O resource's write readiness state and registers the current
|
||||
/// task to be notified once a write readiness event is received.
|
||||
///
|
||||
@@ -360,21 +309,6 @@ where E: Evented
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Like `clear_write_ready`, but compatible with futures 0.2.
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
pub fn clear_write_ready2(&self, cx: &mut futures2::task::Context) -> io::Result<()> {
|
||||
let ready = mio::Ready::writable();
|
||||
|
||||
self.inner.write_readiness.fetch_and(!ready.as_usize(), Relaxed);
|
||||
|
||||
if self.poll_write_ready2(cx)?.is_ready() {
|
||||
// Notify the current task
|
||||
cx.waker().wake()
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ensure that the I/O resource is registered with the reactor.
|
||||
fn register(&self) -> io::Result<()> {
|
||||
self.inner.registration.register(self.io.as_ref().unwrap())?;
|
||||
@@ -402,28 +336,6 @@ where E: Evented + Read,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
impl<E> futures2::io::AsyncRead for PollEvented<E>
|
||||
where E: Evented, E: Read,
|
||||
{
|
||||
fn poll_read(&mut self, cx: &mut futures2::task::Context, buf: &mut [u8])
|
||||
-> futures2::Poll<usize, io::Error>
|
||||
{
|
||||
if let futures2::Async::Pending = self.poll_read_ready2(cx, mio::Ready::readable())? {
|
||||
return Ok(futures2::Async::Pending);
|
||||
}
|
||||
|
||||
match self.get_mut().read(buf) {
|
||||
Ok(n) => Ok(futures2::Async::Ready(n)),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
self.clear_read_ready2(cx, mio::Ready::readable())?;
|
||||
Ok(futures2::Async::Pending)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> Write for PollEvented<E>
|
||||
where E: Evented + Write,
|
||||
{
|
||||
@@ -456,48 +368,6 @@ where E: Evented + Write,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
impl<E> futures2::io::AsyncWrite for PollEvented<E>
|
||||
where E: Evented, E: Write,
|
||||
{
|
||||
fn poll_write(&mut self, cx: &mut futures2::task::Context, buf: &[u8])
|
||||
-> futures2::Poll<usize, io::Error>
|
||||
{
|
||||
if let futures2::Async::Pending = self.poll_write_ready2(cx)? {
|
||||
return Ok(futures2::Async::Pending);
|
||||
}
|
||||
|
||||
match self.get_mut().write(buf) {
|
||||
Ok(n) => Ok(futures2::Async::Ready(n)),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
self.clear_write_ready2(cx)?;
|
||||
Ok(futures2::Async::Pending)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn poll_flush(&mut self, cx: &mut futures2::task::Context) -> futures2::Poll<(), io::Error> {
|
||||
if let futures2::Async::Pending = self.poll_write_ready2(cx)? {
|
||||
return Ok(futures2::Async::Pending);
|
||||
}
|
||||
|
||||
match self.get_mut().flush() {
|
||||
Ok(_) => Ok(futures2::Async::Ready(())),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
self.clear_write_ready2(cx)?;
|
||||
Ok(futures2::Async::Pending)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn poll_close(&mut self, cx: &mut futures2::task::Context) -> futures2::Poll<(), io::Error> {
|
||||
futures2::io::AsyncWrite::poll_flush(self, cx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<E> AsyncRead for PollEvented<E>
|
||||
where E: Evented + Read,
|
||||
{
|
||||
@@ -531,28 +401,6 @@ where E: Evented, &'a E: Read,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
impl<'a, E> futures2::io::AsyncRead for &'a PollEvented<E>
|
||||
where E: Evented, &'a E: Read,
|
||||
{
|
||||
fn poll_read(&mut self, cx: &mut futures2::task::Context, buf: &mut [u8])
|
||||
-> futures2::Poll<usize, io::Error>
|
||||
{
|
||||
if let futures2::Async::Pending = self.poll_read_ready2(cx, mio::Ready::readable())? {
|
||||
return Ok(futures2::Async::Pending);
|
||||
}
|
||||
|
||||
match self.get_ref().read(buf) {
|
||||
Ok(n) => Ok(futures2::Async::Ready(n)),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
self.clear_read_ready2(cx, mio::Ready::readable())?;
|
||||
Ok(futures2::Async::Pending)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> Write for &'a PollEvented<E>
|
||||
where E: Evented, &'a E: Write,
|
||||
{
|
||||
@@ -585,47 +433,6 @@ where E: Evented, &'a E: Write,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
impl<'a, E> futures2::io::AsyncWrite for &'a PollEvented<E>
|
||||
where E: Evented, &'a E: Write,
|
||||
{
|
||||
fn poll_write(&mut self, cx: &mut futures2::task::Context, buf: &[u8])
|
||||
-> futures2::Poll<usize, io::Error>
|
||||
{
|
||||
if let futures2::Async::Pending = self.poll_write_ready2(cx)? {
|
||||
return Ok(futures2::Async::Pending);
|
||||
}
|
||||
|
||||
match self.get_ref().write(buf) {
|
||||
Ok(n) => Ok(futures2::Async::Ready(n)),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
self.clear_write_ready2(cx)?;
|
||||
Ok(futures2::Async::Pending)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn poll_flush(&mut self, cx: &mut futures2::task::Context) -> futures2::Poll<(), io::Error> {
|
||||
if let futures2::Async::Pending = self.poll_write_ready2(cx)? {
|
||||
return Ok(futures2::Async::Pending);
|
||||
}
|
||||
|
||||
match self.get_ref().flush() {
|
||||
Ok(_) => Ok(futures2::Async::Ready(())),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
self.clear_write_ready2(cx)?;
|
||||
Ok(futures2::Async::Pending)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn poll_close(&mut self, cx: &mut futures2::task::Context) -> futures2::Poll<(), io::Error> {
|
||||
futures2::io::AsyncWrite::poll_flush(self, cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> AsyncRead for &'a PollEvented<E>
|
||||
where E: Evented, &'a E: Read,
|
||||
{
|
||||
|
||||
@@ -3,9 +3,6 @@ use {Handle, HandlePriv, Direction, Task};
|
||||
use futures::{Async, Poll, task};
|
||||
use mio::{self, Evented};
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
use futures2;
|
||||
|
||||
use std::{io, ptr, usize};
|
||||
use std::cell::UnsafeCell;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
@@ -279,26 +276,13 @@ impl Registration {
|
||||
///
|
||||
/// This function will panic if called from outside of a task context.
|
||||
pub fn poll_read_ready(&self) -> Poll<mio::Ready, io::Error> {
|
||||
self.poll_ready(Direction::Read, true, || Task::Futures1(task::current()))
|
||||
self.poll_ready(Direction::Read, true, || task::current())
|
||||
.map(|v| match v {
|
||||
Some(v) => Async::Ready(v),
|
||||
_ => Async::NotReady,
|
||||
})
|
||||
}
|
||||
|
||||
/// Like `poll_ready_ready`, but compatible with futures 0.2
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
pub fn poll_read_ready2(&self, cx: &mut futures2::task::Context)
|
||||
-> futures2::Poll<mio::Ready, io::Error>
|
||||
{
|
||||
use futures2::Async as Async2;
|
||||
self.poll_ready(Direction::Read, true, || Task::Futures2(cx.waker().clone()))
|
||||
.map(|v| match v {
|
||||
Some(v) => Async2::Ready(v),
|
||||
_ => Async2::Pending,
|
||||
})
|
||||
}
|
||||
|
||||
/// Consume any pending read readiness event.
|
||||
///
|
||||
/// This function is identical to [`poll_read_ready`] **except** that it
|
||||
@@ -344,26 +328,13 @@ impl Registration {
|
||||
///
|
||||
/// This function will panic if called from outside of a task context.
|
||||
pub fn poll_write_ready(&self) -> Poll<mio::Ready, io::Error> {
|
||||
self.poll_ready(Direction::Write, true, || Task::Futures1(task::current()))
|
||||
self.poll_ready(Direction::Write, true, || task::current())
|
||||
.map(|v| match v {
|
||||
Some(v) => Async::Ready(v),
|
||||
_ => Async::NotReady,
|
||||
})
|
||||
}
|
||||
|
||||
/// Like `poll_write_ready`, but compatible with futures 0.2
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
pub fn poll_write_ready2(&self, cx: &mut futures2::task::Context)
|
||||
-> futures2::Poll<mio::Ready, io::Error>
|
||||
{
|
||||
use futures2::Async as Async2;
|
||||
self.poll_ready(Direction::Write, true, || Task::Futures2(cx.waker().clone()))
|
||||
.map(|v| match v {
|
||||
Some(v) => Async2::Ready(v),
|
||||
_ => Async2::Pending,
|
||||
})
|
||||
}
|
||||
|
||||
/// Consume any pending write readiness event.
|
||||
///
|
||||
/// This function is identical to [`poll_write_ready`] **except** that it
|
||||
|
||||
Reference in New Issue
Block a user