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.
This commit is contained in:
Alex Crichton
2017-12-12 18:32:50 -06:00
committed by Carl Lerche
parent 849771ecfa
commit 4ef772b2db
24 changed files with 48 additions and 98 deletions
+4 -11
View File
@@ -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