Touch up some docs in tokio-core

This commit is contained in:
Alex Crichton
2017-01-10 10:02:15 -08:00
parent c61d3bc71e
commit 9294b1345c
+29 -35
View File
@@ -11,8 +11,8 @@
//! //!
//! * TCP, both streams and listeners //! * TCP, both streams and listeners
//! * UDP sockets //! * UDP sockets
//! * Message queues
//! * Timeouts //! * Timeouts
//! * An event loop to run futures
//! //!
//! More functionality is likely to be added over time, but otherwise the crate //! More functionality is likely to be added over time, but otherwise the crate
//! is intended to be flexible, with the `PollEvented` type accepting any //! is intended to be flexible, with the `PollEvented` type accepting any
@@ -21,9 +21,9 @@
//! //!
//! Some other important tasks covered by this crate are: //! Some other important tasks covered by this crate are:
//! //!
//! * The ability to spawn futures into an event loop. The `Handle` and `Pinned` //! * The ability to spawn futures into an event loop. The `Handle` and `Remote`
//! types have a `spawn` method which allows executing a future on an event //! types have a `spawn` method which allows executing a future on an event
//! loop. The `Pinned::spawn` method crucially does not require the future //! loop. The `Handle::spawn` method crucially does not require the future
//! itself to be `Send`. //! itself to be `Send`.
//! //!
//! * The `Io` trait serves as an abstraction for future crates to build on top //! * The `Io` trait serves as an abstraction for future crates to build on top
@@ -42,52 +42,45 @@
//! extern crate futures; //! extern crate futures;
//! extern crate tokio_core; //! extern crate tokio_core;
//! //!
//! use std::env; //! use futures::{Future, Stream};
//! use std::net::SocketAddr;
//!
//! use futures::Future;
//! use futures::stream::Stream;
//! use tokio_core::io::{copy, Io}; //! use tokio_core::io::{copy, Io};
//! use tokio_core::net::TcpListener; //! use tokio_core::net::TcpListener;
//! use tokio_core::reactor::Core; //! use tokio_core::reactor::Core;
//! //!
//! fn main() { //! fn main() {
//! let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
//! let addr = addr.parse::<SocketAddr>().unwrap();
//!
//! // Create the event loop that will drive this server //! // Create the event loop that will drive this server
//! let mut l = Core::new().unwrap(); //! let mut core = Core::new().unwrap();
//! let handle = l.handle(); //! let handle = core.handle();
//! //!
//! // Create a TCP listener which will listen for incoming connections //! // Bind the server's socket
//! let socket = TcpListener::bind(&addr, &handle).unwrap(); //! let addr = "127.0.0.1:12345".parse().unwrap();
//! let sock = TcpListener::bind(&addr, &handle).unwrap();
//! //!
//! // Once we've got the TCP listener, inform that we have it //! // Pull out a stream of sockets for incoming connections
//! println!("Listening on: {}", addr); //! let server = sock.incoming().for_each(|(sock, _)| {
//! // Split up the reading and writing parts of the
//! // socket
//! let (reader, writer) = sock.split();
//! //!
//! // Pull out the stream of incoming connections and then for each new //! // A future that echos the data and returns how
//! // one spin up a new task copying data. //! // many bytes were copied...
//! // //! let bytes_copied = copy(reader, writer);
//! // We use the `io::copy` future to copy all data from the
//! // reading half onto the writing half.
//! let done = socket.incoming().for_each(|(socket, addr)| {
//! let pair = futures::lazy(|| Ok(socket.split()));
//! let amt = pair.and_then(|(reader, writer)| copy(reader, writer));
//! //!
//! // Once all that is done we print out how much we wrote, and then //! // ... after which we'll print what happened
//! // critically we *spawn* this future which allows it to run //! let handle_conn = bytes_copied.map(|amt| {
//! // concurrently with other connections. //! println!("wrote {} bytes", amt)
//! handle.spawn(amt.then(move |result| { //! }).map_err(|err| {
//! println!("wrote {:?} bytes to {}", result, addr); //! println!("IO error {:?}", err)
//! Ok(()) //! });
//! })); //!
//! // Spawn the future as a concurrent task
//! handle.spawn(handle_conn);
//! //!
//! Ok(()) //! Ok(())
//! }); //! });
//! //!
//! // Execute our server (modeled as a future) and wait for it to //! // Spin up the server on the event loop
//! // complete. //! core.run(server).unwrap();
//! l.run(done).unwrap();
//! } //! }
//! ``` //! ```
@@ -110,6 +103,7 @@ pub mod io;
mod mpsc_queue; mod mpsc_queue;
mod heap; mod heap;
#[doc(hidden)]
pub mod channel; pub mod channel;
pub mod net; pub mod net;
pub mod reactor; pub mod reactor;