summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-12-12 18:32:50 -0600
committerCarl Lerche <me@carllerche.com>2017-12-12 18:32:50 -0600
commit4ef772b2db9fdf19625e428f1031409994b4c8e6 (patch)
tree35d3bd529eedbab426130edde1c9dbc71ff5d80f /examples
parent849771ecfa1e22fdd4f0bd299d10f0026ce14ed5 (diff)
Remove `Handle` argument from I/O constructors (#61)
This commit removes the `Handle` argument from the following constructors * `TcpListener::bind` * `TcpStream::connect` * `UdpSocket::bind` The `Handle` argument remains on the various `*_std` constructors as they're more low-level, but this otherwise is intended to set forth a precedent of by default not taking `Handle` arguments and instead relying on the global `Handle::default` return value when necesary.
Diffstat (limited to 'examples')
-rw-r--r--examples/chat.rs4
-rw-r--r--examples/compress.rs4
-rw-r--r--examples/connect.rs15
-rw-r--r--examples/echo-threads.rs4
-rw-r--r--examples/echo-udp.rs4
-rw-r--r--examples/echo.rs5
-rw-r--r--examples/hello.rs4
-rw-r--r--examples/proxy.rs7
-rw-r--r--examples/sink.rs4
-rw-r--r--examples/tinydb.rs4
-rw-r--r--examples/udp-codec.rs7
11 files changed, 16 insertions, 46 deletions
diff --git a/examples/chat.rs b/examples/chat.rs
index d7d84669..d141f62b 100644
--- a/examples/chat.rs
+++ b/examples/chat.rs
@@ -33,7 +33,6 @@ use futures::future::Executor;
use futures::stream::{self, Stream};
use futures_cpupool::CpuPool;
use tokio::net::TcpListener;
-use tokio::reactor::Handle;
use tokio_io::io;
use tokio_io::AsyncRead;
@@ -42,8 +41,7 @@ fn main() {
let addr = addr.parse().unwrap();
// Create the TCP listener we'll accept connections on.
- let handle = Handle::default();
- let socket = TcpListener::bind(&addr, &handle).unwrap();
+ let socket = TcpListener::bind(&addr).unwrap();
println!("Listening on: {}", addr);
// This is currently a multi threaded server.
diff --git a/examples/compress.rs b/examples/compress.rs
index 42cbab8e..f53709e5 100644
--- a/examples/compress.rs
+++ b/examples/compress.rs
@@ -32,7 +32,6 @@ use futures::{Future, Stream, Poll};
use futures::future::Executor;
use futures_cpupool::CpuPool;
use tokio::net::{TcpListener, TcpStream};
-use tokio::reactor::Handle;
use tokio_io::{AsyncRead, AsyncWrite};
use flate2::write::GzEncoder;
@@ -41,8 +40,7 @@ fn main() {
// reactor.
let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
let addr = addr.parse::<SocketAddr>().unwrap();
- let handle = Handle::default();
- let socket = TcpListener::bind(&addr, &handle).unwrap();
+ let socket = TcpListener::bind(&addr).unwrap();
println!("Listening on: {}", addr);
// This is where we're going to offload our computationally heavy work
diff --git a/examples/connect.rs b/examples/connect.rs
index 5cedadfb..094cb96b 100644
--- a/examples/connect.rs
+++ b/examples/connect.rs
@@ -28,7 +28,6 @@ use std::thread;
use futures::sync::mpsc;
use futures::{Sink, Future, Stream};
use futures_cpupool::CpuPool;
-use tokio::reactor::Handle;
fn main() {
// Determine if we're going to run in TCP or UDP mode
@@ -47,8 +46,6 @@ fn main() {
});
let addr = addr.parse::<SocketAddr>().unwrap();
- let handle = Handle::default();
-
let pool = CpuPool::new(1);
// Right now Tokio doesn't support a handle to stdin running on the event
@@ -63,9 +60,9 @@ fn main() {
// our UDP connection to get a stream of bytes we're going to emit to
// stdout.
let stdout = if tcp {
- tcp::connect(&addr, &handle, &pool, Box::new(stdin_rx))
+ tcp::connect(&addr, &pool, Box::new(stdin_rx))
} else {
- udp::connect(&addr, &handle, &pool, Box::new(stdin_rx))
+ udp::connect(&addr, &pool, Box::new(stdin_rx))
};
// And now with our stream of bytes to write to stdout, we execute that in
@@ -88,17 +85,15 @@ mod tcp {
use futures::future::Executor;
use futures_cpupool::CpuPool;
use tokio::net::TcpStream;
- use tokio::reactor::Handle;
use tokio_io::AsyncRead;
use tokio_io::codec::{Encoder, Decoder};
pub fn connect(addr: &SocketAddr,
- handle: &Handle,
pool: &CpuPool,
stdin: Box<Stream<Item = Vec<u8>, Error = io::Error> + Send>)
-> Box<Stream<Item = BytesMut, Error = io::Error>>
{
- let tcp = TcpStream::connect(addr, handle);
+ let tcp = TcpStream::connect(addr);
let pool = pool.clone();
// After the TCP connection has been established, we set up our client
@@ -175,10 +170,8 @@ mod udp {
use futures::future::Executor;
use futures_cpupool::CpuPool;
use tokio::net::{UdpCodec, UdpSocket};
- use tokio::reactor::Handle;
pub fn connect(&addr: &SocketAddr,
- handle: &Handle,
pool: &CpuPool,
stdin: Box<Stream<Item = Vec<u8>, Error = io::Error> + Send>)
-> Box<Stream<Item = BytesMut, Error = io::Error>>
@@ -190,7 +183,7 @@ mod udp {
} else {
"[::]:0".parse().unwrap()
};
- let udp = UdpSocket::bind(&addr_to_bind, handle)
+ let udp = UdpSocket::bind(&addr_to_bind)
.expect("failed to bind socket");
// Like above with TCP we use an instance of `UdpCodec` to transform
diff --git a/examples/echo-threads.rs b/examples/echo-threads.rs
index 8d428e49..8ac42d0f 100644
--- a/examples/echo-threads.rs
+++ b/examples/echo-threads.rs
@@ -30,7 +30,6 @@ use futures_cpupool::CpuPool;
use tokio_io::AsyncRead;
use tokio_io::io::copy;
use tokio::net::{TcpStream, TcpListener};
-use tokio::reactor::Handle;
fn main() {
// First argument, the address to bind
@@ -41,8 +40,7 @@ fn main() {
let num_threads = env::args().nth(2).and_then(|s| s.parse().ok())
.unwrap_or(num_cpus::get());
- let handle = Handle::default();
- let listener = TcpListener::bind(&addr, &handle).expect("failed to bind");
+ let listener = TcpListener::bind(&addr).expect("failed to bind");
println!("Listening on: {}", addr);
// Spin up our worker threads, creating a channel routing to each worker
diff --git a/examples/echo-udp.rs b/examples/echo-udp.rs
index 0bcc3807..f7e2bf09 100644
--- a/examples/echo-udp.rs
+++ b/examples/echo-udp.rs
@@ -20,7 +20,6 @@ use std::net::SocketAddr;
use futures::{Future, Poll};
use tokio::net::UdpSocket;
-use tokio::reactor::Handle;
struct Server {
socket: UdpSocket,
@@ -54,8 +53,7 @@ fn main() {
let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
let addr = addr.parse::<SocketAddr>().unwrap();
- let handle = Handle::default();
- let socket = UdpSocket::bind(&addr, &handle).unwrap();
+ let socket = UdpSocket::bind(&addr).unwrap();
println!("Listening on: {}", socket.local_addr().unwrap());
// Next we'll create a future to spawn (the one we defined above) and then
diff --git a/examples/echo.rs b/examples/echo.rs
index ca081f84..f7219113 100644
--- a/examples/echo.rs
+++ b/examples/echo.rs
@@ -32,7 +32,6 @@ use futures_cpupool::CpuPool;
use tokio_io::AsyncRead;
use tokio_io::io::copy;
use tokio::net::TcpListener;
-use tokio::reactor::Handle;
fn main() {
// Allow passing an address to listen on as the first argument of this
@@ -41,14 +40,12 @@ fn main() {
let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
let addr = addr.parse::<SocketAddr>().unwrap();
- let handle = Handle::default();
-
// Next up we create a TCP listener which will listen for incoming
// connections. This TCP listener is bound to the address we determined
// above and must be associated with an event loop, so we pass in a handle
// to our event loop. After the socket's created we inform that we're ready
// to go and start accepting connections.
- let socket = TcpListener::bind(&addr, &handle).unwrap();
+ let socket = TcpListener::bind(&addr).unwrap();
println!("Listening on: {}", addr);
// A CpuPool allows futures to be executed concurrently.
diff --git a/examples/hello.rs b/examples/hello.rs
index 5d1c226e..46b36b5d 100644
--- a/examples/hello.rs
+++ b/examples/hello.rs
@@ -21,15 +21,13 @@ use std::net::SocketAddr;
use futures::prelude::*;
use tokio::net::TcpListener;
-use tokio::reactor::Handle;
fn main() {
env_logger::init().unwrap();
let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
let addr = addr.parse::<SocketAddr>().unwrap();
- let handle = Handle::default();
- let listener = TcpListener::bind(&addr, &handle).unwrap();
+ let listener = TcpListener::bind(&addr).unwrap();
let addr = listener.local_addr().unwrap();
println!("Listening for connections on {}", addr);
diff --git a/examples/proxy.rs b/examples/proxy.rs
index 03a83204..c64ead6f 100644
--- a/examples/proxy.rs
+++ b/examples/proxy.rs
@@ -31,7 +31,6 @@ use futures::{Future, Poll};
use futures::future::Executor;
use futures_cpupool::CpuPool;
use tokio::net::{TcpListener, TcpStream};
-use tokio::reactor::Handle;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_io::io::{copy, shutdown};
@@ -42,17 +41,15 @@ fn main() {
let server_addr = env::args().nth(2).unwrap_or("127.0.0.1:8080".to_string());
let server_addr = server_addr.parse::<SocketAddr>().unwrap();
- let handle = Handle::default();
-
let pool = CpuPool::new(1);
// Create a TCP listener which will listen for incoming connections.
- let socket = TcpListener::bind(&listen_addr, &handle).unwrap();
+ let socket = TcpListener::bind(&listen_addr).unwrap();
println!("Listening on: {}", listen_addr);
println!("Proxying to: {}", server_addr);
let done = socket.incoming().for_each(move |(client, client_addr)| {
- let server = TcpStream::connect(&server_addr, &handle);
+ let server = TcpStream::connect(&server_addr);
let amounts = server.and_then(move |server| {
// Create separate read/write handles for the TCP clients that we're
// proxying data between. Note that typically you'd use
diff --git a/examples/sink.rs b/examples/sink.rs
index 48643e05..82bde294 100644
--- a/examples/sink.rs
+++ b/examples/sink.rs
@@ -31,7 +31,6 @@ use futures::stream::{self, Stream};
use futures_cpupool::CpuPool;
use tokio_io::IoFuture;
use tokio::net::{TcpListener, TcpStream};
-use tokio::reactor::Handle;
fn main() {
env_logger::init().unwrap();
@@ -40,8 +39,7 @@ fn main() {
let pool = CpuPool::new(1);
- let handle = Handle::default();
- let socket = TcpListener::bind(&addr, &handle).unwrap();
+ let socket = TcpListener::bind(&addr).unwrap();
println!("Listening on: {}", addr);
let server = socket.incoming().for_each(|(socket, addr)| {
println!("got a socket: {}", addr);
diff --git a/examples/tinydb.rs b/examples/tinydb.rs
index 7b5c47d1..19a7396d 100644
--- a/examples/tinydb.rs
+++ b/examples/tinydb.rs
@@ -54,7 +54,6 @@ use futures::prelude::*;
use futures::future::Executor;
use futures_cpupool::CpuPool;
use tokio::net::TcpListener;
-use tokio::reactor::Handle;
use tokio_io::AsyncRead;
use tokio_io::io::{lines, write_all};
@@ -84,8 +83,7 @@ fn main() {
// and set up our TCP listener to accept connections.
let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
let addr = addr.parse::<SocketAddr>().unwrap();
- let handle = Handle::default();
- let listener = TcpListener::bind(&addr, &handle).expect("failed to bind");
+ let listener = TcpListener::bind(&addr).expect("failed to bind");
println!("Listening on: {}", addr);
// Create a CpuPool to execute tasks
diff --git a/examples/udp-codec.rs b/examples/udp-codec.rs
index f60fc108..ff9ae553 100644
--- a/examples/udp-codec.rs
+++ b/examples/udp-codec.rs
@@ -18,7 +18,6 @@ use futures::{Future, Stream, Sink};
use futures::future::Executor;
use futures_cpupool::CpuPool;
use tokio::net::{UdpSocket, UdpCodec};
-use tokio::reactor::Handle;
pub struct LineCodec;
@@ -39,15 +38,13 @@ impl UdpCodec for LineCodec {
fn main() {
drop(env_logger::init());
- let handle = Handle::default();
-
let pool = CpuPool::new(1);
let addr: SocketAddr = "127.0.0.1:0".parse().unwrap();
// Bind both our sockets and then figure out what ports we got.
- let a = UdpSocket::bind(&addr, &handle).unwrap();
- let b = UdpSocket::bind(&addr, &handle).unwrap();
+ let a = UdpSocket::bind(&addr).unwrap();
+ let b = UdpSocket::bind(&addr).unwrap();
let b_addr = b.local_addr().unwrap();
// We're parsing each socket with the `LineCodec` defined above, and then we