From 614a5068fa4cd73a162c457985666a7ba77e0335 Mon Sep 17 00:00:00 2001 From: Danny Browning Date: Tue, 10 Sep 2019 09:42:30 -0600 Subject: [PATCH] Tokio-Tungstenite Async Changes Changes required for tokio-tungstenite async implementation. --- src/client.rs | 4 ++-- src/handshake/client.rs | 4 ++-- src/handshake/mod.rs | 12 +++++++++++- src/handshake/server.rs | 4 ++-- src/server.rs | 8 ++++---- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/client.rs b/src/client.rs index cea3086..f5f34b4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -179,7 +179,7 @@ pub fn client_with_config<'t, Stream, Req>( config: Option, ) -> StdResult<(WebSocket, Response), HandshakeError>> where - Stream: Read + Write, + Stream: Read + Write + Unpin, Req: Into>, { ClientHandshake::start(stream, request.into(), config).handshake() @@ -195,7 +195,7 @@ pub fn client<'t, Stream, Req>( stream: Stream, ) -> StdResult<(WebSocket, Response), HandshakeError>> where - Stream: Read + Write, + Stream: Read + Write + Unpin, Req: Into>, { client_with_config(request, stream, None) diff --git a/src/handshake/client.rs b/src/handshake/client.rs index 8203ee5..5491fbf 100644 --- a/src/handshake/client.rs +++ b/src/handshake/client.rs @@ -73,7 +73,7 @@ pub struct ClientHandshake { _marker: PhantomData, } -impl ClientHandshake { +impl ClientHandshake { /// Initiate a client handshake. pub fn start( stream: S, @@ -124,7 +124,7 @@ impl ClientHandshake { } } -impl HandshakeRole for ClientHandshake { +impl HandshakeRole for ClientHandshake { type IncomingData = Response; type InternalStream = S; type FinalResult = (WebSocket, Response); diff --git a/src/handshake/mod.rs b/src/handshake/mod.rs index ce862d9..90bfd4d 100644 --- a/src/handshake/mod.rs +++ b/src/handshake/mod.rs @@ -24,6 +24,16 @@ pub struct MidHandshake { } impl MidHandshake { + /// Allow access to machine + pub fn get_ref(&self) -> &HandshakeMachine { + &self.machine + } + + /// Allow mutable access to machine + pub fn get_mut(&mut self) -> &mut HandshakeMachine { + &mut self.machine + } + /// Restarts the handshake process. pub fn handshake(mut self) -> Result> { let mut mach = self.machine; @@ -91,7 +101,7 @@ pub trait HandshakeRole { #[doc(hidden)] type IncomingData: TryParse; #[doc(hidden)] - type InternalStream: Read + Write; + type InternalStream: Read + Write + Unpin; #[doc(hidden)] type FinalResult; #[doc(hidden)] diff --git a/src/handshake/server.rs b/src/handshake/server.rs index 615a755..696f97e 100644 --- a/src/handshake/server.rs +++ b/src/handshake/server.rs @@ -153,7 +153,7 @@ pub struct ServerHandshake { _marker: PhantomData, } -impl ServerHandshake { +impl ServerHandshake { /// Start server handshake. `callback` specifies a custom callback which the user can pass to /// the handshake, this callback will be called when the a websocket client connnects to the /// server, you can specify the callback if you want to add additional header to the client @@ -172,7 +172,7 @@ impl ServerHandshake { } } -impl HandshakeRole for ServerHandshake { +impl HandshakeRole for ServerHandshake { type IncomingData = Request; type InternalStream = S; type FinalResult = WebSocket; diff --git a/src/server.rs b/src/server.rs index 725d892..d4c12fd 100644 --- a/src/server.rs +++ b/src/server.rs @@ -18,7 +18,7 @@ use std::io::{Read, Write}; /// If you want TLS support, use `native_tls::TlsStream` or `openssl::ssl::SslStream` /// for the stream here. Any `Read + Write` streams are supported, including /// those from `Mio` and others. -pub fn accept_with_config( +pub fn accept_with_config( stream: S, config: Option, ) -> Result, HandshakeError>> { @@ -31,7 +31,7 @@ pub fn accept_with_config( /// If you want TLS support, use `native_tls::TlsStream` or `openssl::ssl::SslStream` /// for the stream here. Any `Read + Write` streams are supported, including /// those from `Mio` and others. -pub fn accept( +pub fn accept( stream: S, ) -> Result, HandshakeError>> { accept_with_config(stream, None) @@ -45,7 +45,7 @@ pub fn accept( /// This function does the same as `accept()` but accepts an extra callback /// for header processing. The callback receives headers of the incoming /// requests and is able to add extra headers to the reply. -pub fn accept_hdr_with_config( +pub fn accept_hdr_with_config( stream: S, callback: C, config: Option, @@ -58,7 +58,7 @@ pub fn accept_hdr_with_config( /// This function does the same as `accept()` but accepts an extra callback /// for header processing. The callback receives headers of the incoming /// requests and is able to add extra headers to the reply. -pub fn accept_hdr( +pub fn accept_hdr( stream: S, callback: C, ) -> Result, HandshakeError>> {