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:
Carl Lerche
2018-08-09 21:56:53 -07:00
committed by GitHub
parent 96b556fbff
commit d91c775f36
31 changed files with 67 additions and 1380 deletions
-15
View File
@@ -5,9 +5,6 @@ use std::io;
use futures::stream::Stream;
use futures::{Poll, Async};
#[cfg(feature = "unstable-futures")]
use futures2;
/// Stream returned by the `TcpListener::incoming` function representing the
/// stream of sockets received from a listener.
#[must_use = "streams do nothing unless polled"]
@@ -31,15 +28,3 @@ impl Stream for Incoming {
Ok(Async::Ready(Some(socket)))
}
}
#[cfg(feature = "unstable-futures")]
impl futures2::Stream for Incoming {
type Item = TcpStream;
type Error = io::Error;
fn poll_next(&mut self, cx: &mut futures2::task::Context)
-> futures2::Poll<Option<Self::Item>, io::Error>
{
Ok(self.inner.poll_accept2(cx)?.map(|(sock, _)| Some(sock)))
}
}
-19
View File
@@ -30,9 +30,6 @@ extern crate mio;
extern crate tokio_io;
extern crate tokio_reactor;
#[cfg(feature = "unstable-futures")]
extern crate futures2;
mod incoming;
mod listener;
mod stream;
@@ -41,19 +38,3 @@ pub use self::incoming::Incoming;
pub use self::listener::TcpListener;
pub use self::stream::TcpStream;
pub use self::stream::ConnectFuture;
#[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,
}
}
-38
View File
@@ -9,9 +9,6 @@ use futures::{Poll, Async};
use mio;
use tokio_reactor::{Handle, PollEvented};
#[cfg(feature = "unstable-futures")]
use futures2;
/// An I/O object representing a TCP socket listening for incoming connections.
///
/// This object can be converted into a stream of incoming connections for
@@ -66,22 +63,6 @@ impl TcpListener {
Ok((io, addr).into())
}
/// Like `poll_accept`, but for futures 0.2
#[cfg(feature = "unstable-futures")]
pub fn poll_accept2(&mut self, cx: &mut futures2::task::Context)
-> futures2::Poll<(TcpStream, SocketAddr), io::Error>
{
let (io, addr) = match self.poll_accept_std2(cx)? {
futures2::Async::Ready(x) => x,
futures2::Async::Pending => return Ok(futures2::Async::Pending),
};
let io = mio::net::TcpStream::from_stream(io)?;
let io = TcpStream::new(io);
Ok((io, addr).into())
}
#[deprecated(since = "0.1.2", note = "use poll_accept_std instead")]
#[doc(hidden)]
pub fn accept_std(&mut self) -> io::Result<(net::TcpStream, SocketAddr)> {
@@ -123,25 +104,6 @@ impl TcpListener {
}
}
/// Like `poll_accept_std`, but for futures 0.2.
#[cfg(feature = "unstable-futures")]
pub fn poll_accept_std2(&mut self, cx: &mut futures2::task::Context)
-> futures2::Poll<(net::TcpStream, SocketAddr), io::Error>
{
if let futures2::Async::Pending = self.io.poll_read_ready2(cx, mio::Ready::readable())? {
return Ok(futures2::Async::Pending);
}
match self.io.get_ref().accept_std() {
Ok(pair) => Ok(pair.into()),
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
self.io.clear_read_ready2(cx, mio::Ready::readable())?;
Ok(futures2::Async::Pending)
}
Err(e) => Err(e),
}
}
/// Create a new TCP listener from the standard library's TCP listener.
///
/// This method can be used when the `Handle::tcp_listen` method isn't
-173
View File
@@ -11,9 +11,6 @@ use mio;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_reactor::{Handle, PollEvented};
#[cfg(feature = "unstable-futures")]
use futures2;
/// An I/O object representing a TCP stream connected to a remote endpoint.
///
/// A TCP stream can either be created by connecting to an endpoint, via the
@@ -138,14 +135,6 @@ impl TcpStream {
self.io.poll_read_ready(mask)
}
/// 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>
{
self.io.poll_read_ready2(cx, mask)
}
/// Check the TCP stream's write readiness state.
///
/// This always checks for writable readiness and also checks for HUP
@@ -164,14 +153,6 @@ impl TcpStream {
self.io.poll_write_ready()
}
/// 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>
{
self.io.poll_write_ready2(cx)
}
/// Returns the local address that this stream is bound to.
pub fn local_addr(&self) -> io::Result<SocketAddr> {
self.io.get_ref().local_addr()
@@ -222,25 +203,6 @@ impl TcpStream {
}
}
/// Like `poll_peek` but compatible with futures 0.2
#[cfg(feature = "unstable-futures")]
pub fn poll_peek2(&mut self, cx: &mut futures2::task::Context, buf: &mut [u8])
-> futures2::Poll<usize, io::Error>
{
if let futures2::Async::Pending = self.io.poll_read_ready2(cx, mio::Ready::readable())? {
return Ok(futures2::Async::Pending);
}
match self.io.get_ref().peek(buf) {
Ok(ret) => Ok(ret.into()),
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
self.io.clear_read_ready2(cx, mio::Ready::readable())?;
Ok(futures2::Async::Pending)
}
Err(e) => Err(e),
}
}
/// Shuts down the read, write, or both halves of this connection.
///
/// This function will cause all pending and future I/O on the specified
@@ -411,25 +373,6 @@ impl AsyncRead for TcpStream {
}
}
#[cfg(feature = "unstable-futures")]
impl futures2::io::AsyncRead for TcpStream {
fn poll_read(&mut self, cx: &mut futures2::task::Context, buf: &mut [u8])
-> futures2::Poll<usize, io::Error>
{
futures2::io::AsyncRead::poll_read(&mut self.io, cx, buf)
}
fn poll_vectored_read(&mut self, cx: &mut futures2::task::Context, vec: &mut [&mut IoVec])
-> futures2::Poll<usize, io::Error>
{
futures2::io::AsyncRead::poll_vectored_read(&mut &*self, cx, vec)
}
unsafe fn initializer(&self) -> futures2::io::Initializer {
futures2::io::Initializer::nop()
}
}
impl AsyncWrite for TcpStream {
fn shutdown(&mut self) -> Poll<(), io::Error> {
<&TcpStream>::shutdown(&mut &*self)
@@ -440,29 +383,6 @@ impl AsyncWrite for TcpStream {
}
}
#[cfg(feature = "unstable-futures")]
impl futures2::io::AsyncWrite for TcpStream {
fn poll_write(&mut self, cx: &mut futures2::task::Context, buf: &[u8])
-> futures2::Poll<usize, io::Error>
{
futures2::io::AsyncWrite::poll_write(&mut self.io, cx, buf)
}
fn poll_vectored_write(&mut self, cx: &mut futures2::task::Context, vec: &[&IoVec])
-> futures2::Poll<usize, io::Error>
{
futures2::io::AsyncWrite::poll_vectored_write(&mut &*self, cx, vec)
}
fn poll_flush(&mut self, cx: &mut futures2::task::Context) -> futures2::Poll<(), io::Error> {
futures2::io::AsyncWrite::poll_flush(&mut self.io, cx)
}
fn poll_close(&mut self, cx: &mut futures2::task::Context) -> futures2::Poll<(), io::Error> {
futures2::io::AsyncWrite::poll_close(&mut self.io, cx)
}
}
// ===== impl Read / Write for &'a =====
impl<'a> Read for &'a TcpStream {
@@ -535,40 +455,6 @@ impl<'a> AsyncRead for &'a TcpStream {
}
}
#[cfg(feature = "unstable-futures")]
impl<'a> futures2::io::AsyncRead for &'a TcpStream {
fn poll_read(&mut self, cx: &mut futures2::task::Context, buf: &mut [u8])
-> futures2::Poll<usize, io::Error>
{
futures2::io::AsyncRead::poll_read(&mut &self.io, cx, buf)
}
fn poll_vectored_read(&mut self, cx: &mut futures2::task::Context, vec: &mut [&mut IoVec])
-> futures2::Poll<usize, io::Error>
{
if let futures2::Async::Pending = self.io.poll_read_ready2(cx, mio::Ready::readable())? {
return Ok(futures2::Async::Pending)
}
let r = self.io.get_ref().read_bufs(vec);
match r {
Ok(n) => {
Ok(futures2::Async::Ready(n))
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
self.io.clear_read_ready2(cx, mio::Ready::readable())?;
Ok(futures2::Async::Pending)
}
Err(e) => Err(e),
}
}
unsafe fn initializer(&self) -> futures2::io::Initializer {
futures2::io::Initializer::nop()
}
}
impl<'a> AsyncWrite for &'a TcpStream {
fn shutdown(&mut self) -> Poll<(), io::Error> {
Ok(().into())
@@ -603,44 +489,6 @@ impl<'a> AsyncWrite for &'a TcpStream {
}
}
#[cfg(feature = "unstable-futures")]
impl<'a> futures2::io::AsyncWrite for &'a TcpStream {
fn poll_write(&mut self, cx: &mut futures2::task::Context, buf: &[u8])
-> futures2::Poll<usize, io::Error>
{
futures2::io::AsyncWrite::poll_write(&mut &self.io, cx, buf)
}
fn poll_vectored_write(&mut self, cx: &mut futures2::task::Context, vec: &[&IoVec])
-> futures2::Poll<usize, io::Error>
{
if let futures2::Async::Pending = self.io.poll_write_ready2(cx)? {
return Ok(futures2::Async::Pending)
}
let r = self.io.get_ref().write_bufs(vec);
match r {
Ok(n) => {
Ok(futures2::Async::Ready(n))
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
self.io.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> {
futures2::io::AsyncWrite::poll_flush(&mut &self.io, cx)
}
fn poll_close(&mut self, cx: &mut futures2::task::Context) -> futures2::Poll<(), io::Error> {
futures2::io::AsyncWrite::poll_close(&mut &self.io, cx)
}
}
impl fmt::Debug for TcpStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.io.get_ref().fmt(f)
@@ -656,16 +504,6 @@ impl Future for ConnectFuture {
}
}
#[cfg(feature = "unstable-futures")]
impl futures2::Future for ConnectFuture {
type Item = TcpStream;
type Error = io::Error;
fn poll(&mut self, cx: &mut futures2::task::Context) -> futures2::Poll<TcpStream, io::Error> {
futures2::Future::poll(&mut self.inner, cx)
}
}
impl ConnectFutureState {
fn poll_inner<F>(&mut self, f: F) -> Poll<TcpStream, io::Error>
where F: FnOnce(&mut PollEvented<mio::net::TcpStream>) -> Poll<mio::Ready, io::Error>
@@ -714,17 +552,6 @@ impl Future for ConnectFutureState {
}
}
#[cfg(feature = "unstable-futures")]
impl futures2::Future for ConnectFutureState {
type Item = TcpStream;
type Error = io::Error;
fn poll(&mut self, cx: &mut futures2::task::Context) -> futures2::Poll<TcpStream, io::Error> {
self.poll_inner(|io| io.poll_write_ready2(cx).map(::lower_async))
.map(::lift_async)
}
}
#[cfg(unix)]
mod sys {
use std::os::unix::prelude::*;