mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-23 00:00:10 +02:00
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:
committed by
Carl Lerche
parent
849771ecfa
commit
4ef772b2db
+1
-4
@@ -49,16 +49,13 @@
|
||||
//! use tokio_io::AsyncRead;
|
||||
//! use tokio_io::io::copy;
|
||||
//! use tokio::net::TcpListener;
|
||||
//! use tokio::reactor::Handle;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let handle = Handle::default();
|
||||
//!
|
||||
//! let pool = CpuPool::new_num_cpus();
|
||||
//!
|
||||
//! // Bind the server's socket.
|
||||
//! let addr = "127.0.0.1:12345".parse().unwrap();
|
||||
//! let listener = TcpListener::bind(&addr, &handle)
|
||||
//! let listener = TcpListener::bind(&addr)
|
||||
//! .expect("unable to bind TCP listener");
|
||||
//!
|
||||
//! // Pull out a stream of sockets for incoming connections
|
||||
|
||||
+4
-4
@@ -34,9 +34,9 @@ impl TcpListener {
|
||||
///
|
||||
/// The TCP listener will bind to the provided `addr` address, if available.
|
||||
/// If the result is `Ok`, the socket has successfully bound.
|
||||
pub fn bind(addr: &SocketAddr, handle: &Handle) -> io::Result<TcpListener> {
|
||||
pub fn bind(addr: &SocketAddr) -> io::Result<TcpListener> {
|
||||
let l = try!(mio::net::TcpListener::bind(addr));
|
||||
TcpListener::new(l, handle)
|
||||
TcpListener::new(l, &Handle::default())
|
||||
}
|
||||
|
||||
/// Attempt to accept a connection and create a new connected `TcpStream` if
|
||||
@@ -247,9 +247,9 @@ impl TcpStream {
|
||||
/// the `addr` provided. The returned future will be resolved once the
|
||||
/// stream has successfully connected, or it wil return an error if one
|
||||
/// occurs.
|
||||
pub fn connect(addr: &SocketAddr, handle: &Handle) -> TcpStreamNew {
|
||||
pub fn connect(addr: &SocketAddr) -> TcpStreamNew {
|
||||
let inner = match mio::net::TcpStream::connect(addr) {
|
||||
Ok(tcp) => TcpStream::new(tcp, handle),
|
||||
Ok(tcp) => TcpStream::new(tcp, &Handle::default()),
|
||||
Err(e) => TcpStreamNewState::Error(e),
|
||||
};
|
||||
TcpStreamNew { inner: inner }
|
||||
|
||||
+2
-2
@@ -18,9 +18,9 @@ pub use self::frame::{UdpFramed, UdpCodec};
|
||||
impl UdpSocket {
|
||||
/// This function will create a new UDP socket and attempt to bind it to
|
||||
/// the `addr` provided.
|
||||
pub fn bind(addr: &SocketAddr, handle: &Handle) -> io::Result<UdpSocket> {
|
||||
pub fn bind(addr: &SocketAddr) -> io::Result<UdpSocket> {
|
||||
let udp = try!(mio::net::UdpSocket::bind(addr));
|
||||
UdpSocket::new(udp, handle)
|
||||
UdpSocket::new(udp, &Handle::default())
|
||||
}
|
||||
|
||||
fn new(socket: mio::net::UdpSocket, handle: &Handle) -> io::Result<UdpSocket> {
|
||||
|
||||
Reference in New Issue
Block a user