tokio_core/lib.rs
1//! `Future`-powered I/O at the core of Tokio
2//!
3//! > **Note:** This crate is deprecated in favor of [Tokio](http://github.com/tokio-rs/tokio).
4//!
5//! This crate uses the `futures` crate to provide an event loop ("reactor
6//! core") which can be used to drive I/O like TCP and UDP, spawned future
7//! tasks, and other events like channels/timeouts. All asynchronous I/O is
8//! powered by the `mio` crate.
9//!
10//! The concrete types provided in this crate are relatively bare bones but are
11//! intended to be the essential foundation for further projects needing an
12//! event loop. In this crate you'll find:
13//!
14//! * TCP, both streams and listeners
15//! * UDP sockets
16//! * Timeouts
17//! * An event loop to run futures
18//!
19//! More functionality is likely to be added over time, but otherwise the crate
20//! is intended to be flexible, with the `PollEvented` type accepting any
21//! type that implements `mio::Evented`. For example, the `tokio-uds` crate
22//! uses `PollEvented` to provide support for Unix domain sockets.
23//!
24//! Some other important tasks covered by this crate are:
25//!
26//! * The ability to spawn futures into an event loop. The `Handle` and `Remote`
27//! types have a `spawn` method which allows executing a future on an event
28//! loop. The `Handle::spawn` method crucially does not require the future
29//! itself to be `Send`.
30//!
31//! * The `Io` trait serves as an abstraction for future crates to build on top
32//! of. This packages up `Read` and `Write` functionality as well as the
33//! ability to poll for readiness on both ends.
34//!
35//! * All I/O is futures-aware. If any action in this crate returns "not ready"
36//! or "would block", then the current future task is scheduled to receive a
37//! notification when it would otherwise make progress.
38//!
39//! You can find more extensive documentation in terms of tutorials at
40//! [https://tokio.rs](https://tokio.rs).
41//!
42//! # Examples
43//!
44//! A simple TCP echo server:
45//!
46//! ```no_run
47//! extern crate futures;
48//! extern crate tokio_core;
49//! extern crate tokio_io;
50//!
51//! use futures::{Future, Stream};
52//! use tokio_io::AsyncRead;
53//! use tokio_io::io::copy;
54//! use tokio_core::net::TcpListener;
55//! use tokio_core::reactor::Core;
56//!
57//! fn main() {
58//! // Create the event loop that will drive this server
59//! let mut core = Core::new().unwrap();
60//! let handle = core.handle();
61//!
62//! // Bind the server's socket
63//! let addr = "127.0.0.1:12345".parse().unwrap();
64//! let listener = TcpListener::bind(&addr, &handle).unwrap();
65//!
66//! // Pull out a stream of sockets for incoming connections
67//! let server = listener.incoming().for_each(|(sock, _)| {
68//! // Split up the reading and writing parts of the
69//! // socket
70//! let (reader, writer) = sock.split();
71//!
72//! // A future that echos the data and returns how
73//! // many bytes were copied...
74//! let bytes_copied = copy(reader, writer);
75//!
76//! // ... after which we'll print what happened
77//! let handle_conn = bytes_copied.map(|amt| {
78//! println!("wrote {:?} bytes", amt)
79//! }).map_err(|err| {
80//! println!("IO error {:?}", err)
81//! });
82//!
83//! // Spawn the future as a concurrent task
84//! handle.spawn(handle_conn);
85//!
86//! Ok(())
87//! });
88//!
89//! // Spin up the server on the event loop
90//! core.run(server).unwrap();
91//! }
92//! ```
93
94#![doc(html_root_url = "https://docs.rs/tokio-core/0.1.18")]
95#![deny(missing_docs)]
96#![cfg_attr(test, allow(deprecated))]
97
98extern crate bytes;
99#[macro_use]
100extern crate futures;
101extern crate iovec;
102extern crate mio;
103extern crate tokio;
104extern crate tokio_executor;
105extern crate tokio_io;
106extern crate tokio_reactor;
107extern crate tokio_timer;
108
109#[macro_use]
110extern crate scoped_tls;
111
112#[macro_use]
113extern crate log;
114
115#[macro_use]
116#[doc(hidden)]
117pub mod io;
118
119#[doc(hidden)]
120pub mod channel;
121pub mod net;
122pub mod reactor;