Reorganize the entire crate:

Renamed APIs

* Loop => reactor::Core
* LoopHandle => reactor::Handle
* LoopPin => reactor::Pinned
* TcpStream => net::TcpStream
* TcpListener => net::TcpListener
* UdpSocket => net::UdpSocket
* Sender => channel::Sender
* Receiver => channel::Receiver
* Timeout => reactor::Timeout
* ReadinessStream => reactor::PollEvented
* All `LoopHandle` methods to construct objects are now free functions on the
  associated types, e.g. `LoopHandle::tcp_listen` is now `TcpListener::bind`
* All APIs taking a `Handle` now take a `Handle` as the last argument
* All future-returning APIs now return concrete types instead of trait objects

Added APIs

* io::Io trait -- Read + Write + ability to poll

Removed without replacement:

* AddSource
* AddTimeout
* IoToken
* TimeoutToken

Closes #3
Closes #6
This commit is contained in:
Alex Crichton
2016-09-07 22:12:14 -07:00
parent 93c61bb384
commit 6c045d31ac
24 changed files with 811 additions and 476 deletions
+73 -2
View File
@@ -3,9 +3,9 @@
//! Contains various combinators to work with I/O objects and type definitions
//! as well.
use std::io;
use std::io::{self, Read, Write};
use futures::BoxFuture;
use futures::{BoxFuture, Async};
use futures::stream::BoxStream;
/// A convenience typedef around a `Future` whose error component is `io::Error`
@@ -45,3 +45,74 @@ pub use self::read_to_end::{read_to_end, ReadToEnd};
pub use self::task::{TaskIo, TaskIoRead, TaskIoWrite};
pub use self::window::Window;
pub use self::write_all::{write_all, WriteAll};
/// A trait for read/write I/O objects
///
/// This trait represents I/O object which are readable and writable.
/// Additionally, they're associated with the ability to test whether they're
/// readable or writable.
///
/// Imporantly, the methods of this trait are intended to be used in conjuction
/// with the current task of a future. Namely whenever any of them return a
/// value that indicates "would block" the current future's task is arranged to
/// receive a notification when the method would otherwise not indicate that it
/// would block.
pub trait Io: Read + Write {
/// Tests to see if this I/O object may be readable.
///
/// This method returns an `Async<()>` indicating whether the object
/// **might** be readable. It is possible that even if this method returns
/// `Async::Ready` that a call to `read` would return a `WouldBlock` error.
///
/// There is a default implementation for this function which always
/// indicates that an I/O object is readable, but objects which can
/// implement a finer grained version of this are recommended to do so.
///
/// If this function returns `Async::NotReady` then the current future's
/// task is arranged to receive a notification when it might not return
/// `NotReady`.
///
/// # Panics
///
/// This method is likely to panic if called from outside the context of a
/// future's task.
fn poll_read(&mut self) -> Async<()> {
Async::Ready(())
}
/// Tests to see if this I/O object may be writable.
///
/// This method returns an `Async<()>` indicating whether the object
/// **might** be writable. It is possible that even if this method returns
/// `Async::Ready` that a call to `write` would return a `WouldBlock` error.
///
/// There is a default implementation for this function which always
/// indicates that an I/O object is writable, but objects which can
/// implement a finer grained version of this are recommended to do so.
///
/// If this function returns `Async::NotReady` then the current future's
/// task is arranged to receive a notification when it might not return
/// `NotReady`.
///
/// # Panics
///
/// This method is likely to panic if called from outside the context of a
/// future's task.
fn poll_write(&mut self) -> Async<()> {
Async::Ready(())
}
/// Helper method for splitting this read/write object into two halves.
///
/// The two halves returned implement the `Read` and `Write` traits,
/// respectively, but are only usable on the current task.
///
/// # Panics
///
/// This method will panic if there is not currently an active future task.
fn task_split(self) -> (TaskIoRead<Self>, TaskIoWrite<Self>)
where Self: Sized
{
TaskIo::new(self).split()
}
}