diff options
author | Alex Crichton <alex@alexcrichton.com> | 2017-12-12 18:32:50 -0600 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2017-12-12 18:32:50 -0600 |
commit | 4ef772b2db9fdf19625e428f1031409994b4c8e6 (patch) | |
tree | 35d3bd529eedbab426130edde1c9dbc71ff5d80f /examples/connect.rs | |
parent | 849771ecfa1e22fdd4f0bd299d10f0026ce14ed5 (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/connect.rs')
-rw-r--r-- | examples/connect.rs | 15 |
1 files changed, 4 insertions, 11 deletions
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 |