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
+6 -10
View File
@@ -8,7 +8,6 @@ use std::net::SocketAddr;
use futures::{Future, Poll, Stream, Sink};
use tokio::net::{UdpSocket, UdpCodec};
use tokio::reactor::Handle;
macro_rules! t {
($e:expr) => (match $e {
@@ -18,9 +17,8 @@ macro_rules! t {
}
fn send_messages<S: SendFn + Clone, R: RecvFn + Clone>(send: S, recv: R) {
let handle = Handle::default();
let mut a = t!(UdpSocket::bind(&([127, 0, 0, 1], 0).into(), &handle));
let mut b = t!(UdpSocket::bind(&([127, 0, 0, 1], 0).into(), &handle));
let mut a = t!(UdpSocket::bind(&([127, 0, 0, 1], 0).into()));
let mut b = t!(UdpSocket::bind(&([127, 0, 0, 1], 0).into()));
let a_addr = t!(a.local_addr());
let b_addr = t!(b.local_addr());
@@ -166,9 +164,8 @@ impl<R: RecvFn> Future for RecvMessage<R> {
#[test]
fn send_dgrams() {
let handle = Handle::default();
let mut a = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse()), &handle));
let mut b = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse()), &handle));
let mut a = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse())));
let mut b = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse())));
let mut buf = [0u8; 50];
let b_addr = t!(b.local_addr());
@@ -216,9 +213,8 @@ impl UdpCodec for Codec {
#[test]
fn send_framed() {
let handle = Handle::default();
let mut a_soc = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse()), &handle));
let mut b_soc = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse()), &handle));
let mut a_soc = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse())));
let mut b_soc = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse())));
let a_addr = t!(a_soc.local_addr());
let b_addr = t!(b_soc.local_addr());