Update tokio-tls to 0.2 and replace fully tokio-core with tokio

pull/1/head
Ryan Leckey 6 years ago
parent 9f3b559555
commit b9b6f2de5a
  1. 14
      Cargo.toml
  2. 16
      src/connect.rs
  3. 4
      src/lib.rs
  4. 2
      src/stream.rs
  5. 20
      tests/handshakes.rs

@ -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" }

@ -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;

@ -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,

@ -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 {

@ -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();
}

Loading…
Cancel
Save