|
|
@ -3,6 +3,7 @@ |
|
|
|
extern crate tokio_dns; |
|
|
|
extern crate tokio_dns; |
|
|
|
extern crate tokio_tcp; |
|
|
|
extern crate tokio_tcp; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::net::SocketAddr; |
|
|
|
use std::io::Result as IoResult; |
|
|
|
use std::io::Result as IoResult; |
|
|
|
|
|
|
|
|
|
|
|
use self::tokio_tcp::TcpStream; |
|
|
|
use self::tokio_tcp::TcpStream; |
|
|
@ -14,7 +15,7 @@ use tungstenite::Error; |
|
|
|
use tungstenite::client::url_mode; |
|
|
|
use tungstenite::client::url_mode; |
|
|
|
use tungstenite::handshake::client::Response; |
|
|
|
use tungstenite::handshake::client::Response; |
|
|
|
|
|
|
|
|
|
|
|
use stream::NoDelay; |
|
|
|
use stream::{NoDelay, PeerAddr}; |
|
|
|
use super::{WebSocketStream, Request, client_async}; |
|
|
|
use super::{WebSocketStream, Request, client_async}; |
|
|
|
|
|
|
|
|
|
|
|
impl NoDelay for TcpStream { |
|
|
|
impl NoDelay for TcpStream { |
|
|
@ -23,6 +24,12 @@ impl NoDelay for TcpStream { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl PeerAddr for TcpStream { |
|
|
|
|
|
|
|
fn peer_addr(&self) -> IoResult<SocketAddr> { |
|
|
|
|
|
|
|
self.peer_addr() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature="tls")] |
|
|
|
#[cfg(feature="tls")] |
|
|
|
mod encryption { |
|
|
|
mod encryption { |
|
|
|
extern crate native_tls; |
|
|
|
extern crate native_tls; |
|
|
@ -31,6 +38,7 @@ mod encryption { |
|
|
|
use self::native_tls::TlsConnector; |
|
|
|
use self::native_tls::TlsConnector; |
|
|
|
use self::tokio_tls::{TlsConnector as TokioTlsConnector, TlsStream}; |
|
|
|
use self::tokio_tls::{TlsConnector as TokioTlsConnector, TlsStream}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::net::SocketAddr; |
|
|
|
use std::io::{Read, Write, Result as IoResult}; |
|
|
|
use std::io::{Read, Write, Result as IoResult}; |
|
|
|
|
|
|
|
|
|
|
|
use futures::{future, Future}; |
|
|
|
use futures::{future, Future}; |
|
|
@ -39,7 +47,7 @@ mod encryption { |
|
|
|
use tungstenite::Error; |
|
|
|
use tungstenite::Error; |
|
|
|
use tungstenite::stream::Mode; |
|
|
|
use tungstenite::stream::Mode; |
|
|
|
|
|
|
|
|
|
|
|
use stream::{NoDelay, Stream as StreamSwitcher}; |
|
|
|
use stream::{NoDelay, PeerAddr, Stream as StreamSwitcher}; |
|
|
|
|
|
|
|
|
|
|
|
/// A stream that might be protected with TLS.
|
|
|
|
/// A stream that might be protected with TLS.
|
|
|
|
pub type MaybeTlsStream<S> = StreamSwitcher<S, TlsStream<S>>; |
|
|
|
pub type MaybeTlsStream<S> = StreamSwitcher<S, TlsStream<S>>; |
|
|
@ -52,6 +60,12 @@ mod encryption { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl<S: Read + Write + PeerAddr> PeerAddr for TlsStream<S> { |
|
|
|
|
|
|
|
fn peer_addr(&self) -> IoResult<SocketAddr> { |
|
|
|
|
|
|
|
self.get_ref().get_ref().peer_addr() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn wrap_stream<S>(socket: S, domain: String, mode: Mode) |
|
|
|
pub fn wrap_stream<S>(socket: S, domain: String, mode: Mode) |
|
|
|
-> Box<Future<Item=AutoStream<S>, Error=Error> + Send> |
|
|
|
-> Box<Future<Item=AutoStream<S>, Error=Error> + Send> |
|
|
|
where |
|
|
|
where |
|
|
|