-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename to tokio-core, add in futures-io
Renames the futures-mio crate to tokio-core, pulls in the futures-io crate under an `io` module, and gets everything compiling.
- Loading branch information
1 parent
e71d509
commit f107c8d
Showing
29 changed files
with
1,495 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
language: rust | ||
|
||
rust: | ||
- stable | ||
- beta | ||
- nightly | ||
sudo: false | ||
before_script: | ||
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH | ||
script: | ||
- cargo build | ||
- cargo test | ||
- cargo doc --no-deps | ||
after_success: | ||
- travis-cargo --only nightly doc-upload | ||
env: | ||
global: | ||
- secure: LVrtwDI0IJradnHRk53dGWtTS+limhkuHym17wuto/Zaz6IJB9aq7G5wSYuZU3qabcxah7pigjXPFgzYwFD6mNHW1DAuAko1qOi4AL0rvg+rA7Fa5E9NEIxoqzCf+wBtqCvomBe/akOs7UtHdjE3CZpIEPwSHVf3jf61suB0mPVUW0AFTHvYTvHT4lyHjlruY+Ifi350yb4t0Oy9rU1bHNtX0q1T0mKuTnKkmpCT2Kj+2L7afgsAR3UgBjL3Py89LXmnF5VxSMGJWa6HL3xgEi3CXxBRQFdr+vipIDejWtjY+7DzvSRHid1rVfwCLdLfTwvA3Pf3b0I5DSJnjzRgKkfiH2j7JNFtCvLz+mM5C/4QJzAgNmdyNuDv0qOy07OABtYs/LE60f6ZZ5YMZAloMtA/9qQjJx+c2jO2nTZkx6vNJ5C421yzm2klQSL0d8pFaDmojqC5pT85MYhf3mESqSw1UjwFPa0xFtysT52oJBcyvwI/wBYbK40sArjSDZaU2Jncw9ptDWML/xUM+sWHF7ZW/mI1V15lqaCBX91xlbppfWDMgNF2c60vC90t0entbGpYLvHjQMdW6iucbsLLN5KAPzYPuufX2vJa8V1gxMxZ7CLcVLx9lmm3uEdrOZLEg4Fg7H7Xqc2JRygbNrTtOeBw1/o73znnnjEv8Vl3xqg= | ||
notifications: | ||
email: | ||
on_success: never | ||
os: | ||
- linux | ||
- osx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
[package] | ||
name = "futures-mio" | ||
name = "tokio-core" | ||
version = "0.1.0" | ||
authors = ["Alex Crichton <[email protected]>"] | ||
license = "MIT/Apache-2.0" | ||
repository = "https://github.com/alexcrichton/futures-rs" | ||
homepage = "https://github.com/alexcrichton/futures-rs" | ||
documentation = "http://alexcrichton.com/futures-rs/futures_mio/" | ||
repository = "https://github.com/tokio-rs/tokio-core" | ||
homepage = "https://github.com/tokio-rs/tokio-core" | ||
documentation = "https://tokio-rs.github.io/tokio-core" | ||
description = """ | ||
Bindings from the `futures` crate to the `mio` crate to get I/O in the form of | ||
futures and streams. | ||
Core I/O and event loop primitives for asynchronous I/O in Rust. Foundation for | ||
the rest of the tokio crates. | ||
""" | ||
|
||
[dependencies] | ||
futures = { path = "..", version = "0.1.0" } | ||
futures-io = { path = "../futures-io", version = "0.1.0" } | ||
futures = { git = "https://github.com/alexcrichton/futures-rs" } | ||
log = "0.3" | ||
mio = { git = "https://github.com/carllerche/mio" } | ||
scoped-tls = "0.1.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::io::{self, Read, Write}; | ||
|
||
use futures::{Future, Poll}; | ||
|
||
/// A future which will copy all data from a reader into a writer. | ||
/// | ||
/// Created by the `copy` function, this future will resolve to the number of | ||
/// bytes copied or an error if one happens. | ||
pub struct Copy<R, W> { | ||
reader: R, | ||
read_done: bool, | ||
writer: W, | ||
pos: usize, | ||
cap: usize, | ||
amt: u64, | ||
buf: Box<[u8]>, | ||
} | ||
|
||
/// Creates a future which represents copying all the bytes from one object to | ||
/// another. | ||
/// | ||
/// The returned future will copy all the bytes read from `reader` into the | ||
/// `writer` specified. This future will only complete once the `reader` has hit | ||
/// EOF and all bytes have been written to and flushed from the `writer` | ||
/// provided. | ||
/// | ||
/// On success the number of bytes is returned and the `reader` and `writer` are | ||
/// consumed. On error the error is returned and the I/O objects are consumed as | ||
/// well. | ||
pub fn copy<R, W>(reader: R, writer: W) -> Copy<R, W> | ||
where R: Read, | ||
W: Write, | ||
{ | ||
Copy { | ||
reader: reader, | ||
read_done: false, | ||
writer: writer, | ||
amt: 0, | ||
pos: 0, | ||
cap: 0, | ||
buf: Box::new([0; 2048]), | ||
} | ||
} | ||
|
||
impl<R, W> Future for Copy<R, W> | ||
where R: Read, | ||
W: Write, | ||
{ | ||
type Item = u64; | ||
type Error = io::Error; | ||
|
||
fn poll(&mut self) -> Poll<u64, io::Error> { | ||
loop { | ||
// If our buffer is empty, then we need to read some data to | ||
// continue. | ||
if self.pos == self.cap && !self.read_done { | ||
let n = try_nb!(self.reader.read(&mut self.buf)); | ||
if n == 0 { | ||
self.read_done = true; | ||
} else { | ||
self.pos = 0; | ||
self.cap = n; | ||
} | ||
} | ||
|
||
// If our buffer has some data, let's write it out! | ||
while self.pos < self.cap { | ||
let i = try_nb!(self.writer.write(&self.buf[self.pos..self.cap])); | ||
self.pos += i; | ||
self.amt += i as u64; | ||
} | ||
|
||
// If we've written al the data and we've seen EOF, flush out the | ||
// data and finish the transfer. | ||
// done with the entire transfer. | ||
if self.pos == self.cap && self.read_done { | ||
try_nb!(self.writer.flush()); | ||
return Poll::Ok(self.amt) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::io::{self, Write}; | ||
|
||
use futures::{Poll, Future}; | ||
|
||
/// A future used to fully flush an I/O object. | ||
/// | ||
/// Resolves to the underlying I/O object once the flush operation is complete. | ||
/// | ||
/// Created by the `flush` function. | ||
pub struct Flush<A> { | ||
a: Option<A>, | ||
} | ||
|
||
/// Creates a future which will entirely flush an I/O object and then yield the | ||
/// object itself. | ||
/// | ||
/// This function will consume the object provided if an error happens, and | ||
/// otherwise it will repeatedly call `flush` until it sees `Ok(())`, scheduling | ||
/// a retry if `WouldBlock` is seen along the way. | ||
pub fn flush<A>(a: A) -> Flush<A> | ||
where A: Write, | ||
{ | ||
Flush { | ||
a: Some(a), | ||
} | ||
} | ||
|
||
impl<A> Future for Flush<A> | ||
where A: Write, | ||
{ | ||
type Item = A; | ||
type Error = io::Error; | ||
|
||
fn poll(&mut self) -> Poll<A, io::Error> { | ||
try_nb!(self.a.as_mut().unwrap().flush()); | ||
Poll::Ok(self.a.take().unwrap()) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! I/O conveniences when working with primitives in `tokio-core` | ||
//! | ||
//! Contains various combinators to work with I/O objects and type definitions | ||
//! as well. | ||
use std::io; | ||
|
||
use futures::BoxFuture; | ||
use futures::stream::BoxStream; | ||
|
||
/// A convenience typedef around a `Future` whose error component is `io::Error` | ||
pub type IoFuture<T> = BoxFuture<T, io::Error>; | ||
|
||
/// A convenience typedef around a `Stream` whose error component is `io::Error` | ||
pub type IoStream<T> = BoxStream<T, io::Error>; | ||
|
||
/// A convenience macro for working with `io::Result<T>` from the `Read` and | ||
/// `Write` traits. | ||
/// | ||
/// This macro takes `io::Result<T>` as input, and returns `T` as the output. If | ||
/// the input type is of the `Err` variant, then `Poll::NotReady` is returned if | ||
/// it indicates `WouldBlock` or otherwise `Err` is returned. | ||
#[macro_export] | ||
macro_rules! try_nb { | ||
($e:expr) => (match $e { | ||
Ok(t) => t, | ||
Err(ref e) if e.kind() == ::std::io::ErrorKind::WouldBlock => { | ||
return ::futures::Poll::NotReady | ||
} | ||
Err(e) => return ::futures::Poll::Err(e.into()), | ||
}) | ||
} | ||
|
||
mod copy; | ||
mod flush; | ||
mod read_exact; | ||
mod read_to_end; | ||
mod task; | ||
mod window; | ||
mod write_all; | ||
pub use self::copy::{copy, Copy}; | ||
pub use self::flush::{flush, Flush}; | ||
pub use self::read_exact::{read_exact, ReadExact}; | ||
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}; |
Oops, something went wrong.