From b9b6f2de5a56b2eb3193d6804f4c822ba1840413 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Thu, 9 Aug 2018 00:29:30 -0700 Subject: [PATCH] Update tokio-tls to 0.2 and replace fully tokio-core with tokio --- Cargo.toml | 14 ++++++-------- src/connect.rs | 16 +++++++++------- src/lib.rs | 4 ++-- src/stream.rs | 2 +- tests/handshakes.rs | 20 +++++++------------- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 17eaf30..186a875 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,12 +12,13 @@ version = "0.6.0" [features] default = ["connect", "tls"] -connect = ["tokio-dns-unofficial", "tokio", "stream"] +connect = ["tokio-dns-unofficial", "tokio-tcp", "stream"] tls = ["tokio-tls", "native-tls", "stream", "tungstenite/tls"] stream = ["bytes"] [dependencies] futures = "0.1.23" +tokio-io = "0.1.7" [dependencies.tungstenite] version = "0.6.0" @@ -35,17 +36,14 @@ version = "0.2.0" optional = true version = "0.3.1" -[dependencies.tokio] +[dependencies.tokio-tcp] optional = true -version = "0.1.7" +version = "0.1.0" [dependencies.tokio-tls] optional = true -version = "0.1.4" +version = "0.2.0" [dev-dependencies] -tokio-core = "0.1.12" +tokio = "0.1.7" url = "1.6.0" - -[patch.crates-io] -tokio-tls = { git = "https://github.com/aep/tokio-tls.git", rev = "7865734d2167160cabd4422aca76b8478e643b41" } diff --git a/src/connect.rs b/src/connect.rs index aa47a70..7c4d02a 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -1,13 +1,14 @@ //! Connection helper. extern crate tokio_dns; +extern crate tokio_tcp; use std::io::Result as IoResult; -use tokio::net::TcpStream; +use self::tokio_tcp::TcpStream; use futures::{future, Future}; -use tokio::io::{AsyncRead, AsyncWrite}; +use tokio_io::{AsyncRead, AsyncWrite}; use tungstenite::Error; use tungstenite::client::url_mode; @@ -28,12 +29,12 @@ mod encryption { extern crate tokio_tls; use self::native_tls::TlsConnector; - use self::tokio_tls::{TlsConnectorExt, TlsStream}; + use self::tokio_tls::{TlsConnector as TokioTlsConnector, TlsStream}; use std::io::{Read, Write, Result as IoResult}; use futures::{future, Future}; - use tokio::io::{AsyncRead, AsyncWrite}; + use tokio_io::{AsyncRead, AsyncWrite}; use tungstenite::Error; use tungstenite::stream::Mode; @@ -57,8 +58,9 @@ mod encryption { match mode { Mode::Plain => Box::new(future::ok(StreamSwitcher::Plain(socket))), Mode::Tls => { - Box::new(future::result(TlsConnector::builder().build()) - .and_then(move |connector| connector.connect_async(&domain, socket)) + Box::new(future::result(TlsConnector::new()) + .map(TokioTlsConnector::from) + .and_then(move |connector| connector.connect(&domain, socket)) .map(|s| StreamSwitcher::Tls(s)) .map_err(|e| Error::Tls(e))) } @@ -69,7 +71,7 @@ mod encryption { #[cfg(not(feature="tls"))] mod encryption { use futures::{future, Future}; - use tokio::io::{AsyncRead, AsyncWrite}; + use tokio_io::{AsyncRead, AsyncWrite}; use tungstenite::Error; use tungstenite::stream::Mode; diff --git a/src/lib.rs b/src/lib.rs index 6f0993f..05401de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ unused_import_braces)] extern crate futures; -extern crate tokio; +extern crate tokio_io; pub extern crate tungstenite; @@ -29,7 +29,7 @@ pub mod stream; use std::io::ErrorKind; use futures::{Poll, Future, Async, AsyncSink, Stream, Sink, StartSend}; -use tokio::io::{AsyncRead, AsyncWrite}; +use tokio_io::{AsyncRead, AsyncWrite}; use tungstenite::{ error::Error as WsError, diff --git a/src/stream.rs b/src/stream.rs index 29476e5..d06cb1e 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -10,7 +10,7 @@ use std::io::{Read, Write, Result as IoResult, Error as IoError}; use self::bytes::{Buf, BufMut}; use futures::Poll; -use tokio::io::{AsyncRead, AsyncWrite}; +use tokio_io::{AsyncRead, AsyncWrite}; /// Trait to switch TCP_NODELAY. pub trait NoDelay { diff --git a/tests/handshakes.rs b/tests/handshakes.rs index ba280c9..e721994 100644 --- a/tests/handshakes.rs +++ b/tests/handshakes.rs @@ -1,13 +1,12 @@ extern crate futures; -extern crate tokio_core; +extern crate tokio_tcp; extern crate tokio_tungstenite; extern crate url; use std::io; use futures::{Future, Stream}; -use tokio_core::net::{TcpStream, TcpListener}; -use tokio_core::reactor::Core; +use tokio_tcp::{TcpStream, TcpListener}; use tokio_tungstenite::{client_async, accept_async}; #[test] @@ -18,27 +17,23 @@ fn handshakes() { let (tx, rx) = channel(); thread::spawn(move || { - let mut core = Core::new().unwrap(); - let handle = core.handle(); let address = "0.0.0.0:12345".parse().unwrap(); - let listener = TcpListener::bind(&address, &handle).unwrap(); + let listener = TcpListener::bind(&address).unwrap(); let connections = listener.incoming(); tx.send(()).unwrap(); - let handshakes = connections.and_then(|(connection, _)| { + let handshakes = connections.and_then(|connection| { accept_async(connection).map_err(|e| io::Error::new(io::ErrorKind::Other, e)) }); let server = handshakes.for_each(|_| { Ok(()) }); - core.run(server).unwrap(); + server.wait().unwrap(); }); rx.recv().unwrap(); - let mut core = Core::new().unwrap(); - let handle = core.handle(); let address = "0.0.0.0:12345".parse().unwrap(); - let tcp = TcpStream::connect(&address, &handle); + let tcp = TcpStream::connect(&address); let handshake = tcp.and_then(|stream| { let url = url::Url::parse("ws://localhost:12345/").unwrap(); client_async(url, stream).map_err(|e| io::Error::new(io::ErrorKind::Other, e)) @@ -46,6 +41,5 @@ fn handshakes() { let client = handshake.and_then(|_| { Ok(()) }); - core.run(client).unwrap(); + client.wait().unwrap(); } -