From 7e1ac6cbbd57bd3e1694edea49711b382079d136 Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Thu, 24 Dec 2020 11:18:32 +0900 Subject: [PATCH 1/5] Upgrade to tokio 1.0 --- Cargo.toml | 8 ++++++-- examples/interval-server.rs | 23 +++++++---------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 61dd1c4a..10904dd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,11 +21,13 @@ stream = [] log = "0.4" futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] } pin-project = "1.0" -tokio = { version = "0.3", default-features = false, features = ["io-util"] } +tokio = { version = "1.0.0", default-features = false, features = ["io-util"] } [dependencies.tungstenite] version = "0.11.1" default-features = false +git = "https://github.com/nickelc/tungstenite-rs.git" +branch = "bytes" [dependencies.native-tls] optional = true @@ -34,9 +36,11 @@ version = "0.2.0" [dependencies.tokio-native-tls] optional = true version = "0.2" +git = "https://github.com/tokio-rs/tls.git" +rev = "44e978cfa6e46294c0e352fad820456dbe94bdaa" [dev-dependencies] futures-channel = "0.3" -tokio = { version = "0.3", default-features = false, features = ["io-std", "macros", "rt-multi-thread", "stream", "time"] } +tokio = { version = "1.0.0", default-features = false, features = ["io-std", "macros", "rt-multi-thread", "time"] } url = "2.0.0" env_logger = "0.7" diff --git a/examples/interval-server.rs b/examples/interval-server.rs index dd985529..87097037 100644 --- a/examples/interval-server.rs +++ b/examples/interval-server.rs @@ -1,7 +1,4 @@ -use futures_util::{ - future::{select, Either}, - SinkExt, StreamExt, -}; +use futures_util::{SinkExt, StreamExt}; use log::*; use std::{net::SocketAddr, time::Duration}; use tokio::net::{TcpListener, TcpStream}; @@ -25,29 +22,23 @@ async fn handle_connection(peer: SocketAddr, stream: TcpStream) -> Result<()> { // Echo incoming WebSocket messages and send a message periodically every second. - let mut msg_fut = ws_receiver.next(); - let mut tick_fut = interval.next(); loop { - match select(msg_fut, tick_fut).await { - Either::Left((msg, tick_fut_continue)) => { + tokio::select! { + msg = ws_receiver.next() => { match msg { Some(msg) => { let msg = msg?; - if msg.is_text() || msg.is_binary() { + if msg.is_text() ||msg.is_binary() { ws_sender.send(msg).await?; } else if msg.is_close() { break; } - tick_fut = tick_fut_continue; // Continue waiting for tick. - msg_fut = ws_receiver.next(); // Receive next WebSocket message. } - None => break, // WebSocket stream terminated. - }; + None => break, + } } - Either::Right((_, msg_fut_continue)) => { + _ = interval.tick() => { ws_sender.send(Message::Text("tick".to_owned())).await?; - msg_fut = msg_fut_continue; // Continue receiving the WebSocket message. - tick_fut = interval.next(); // Wait for next tick. } } } From 9c05f201afd1dbae552e93a38c2817579ada8bb4 Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Thu, 24 Dec 2020 11:24:48 +0900 Subject: [PATCH 2/5] Fix formatting in handshake.rs --- src/handshake.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/handshake.rs b/src/handshake.rs index a0c52dfd..1ff72090 100644 --- a/src/handshake.rs +++ b/src/handshake.rs @@ -92,11 +92,11 @@ pub(crate) async fn client_handshake( ) -> Result<(WebSocketStream, Response), Error>>> where F: FnOnce( - AllowStd, - ) -> Result< - > as HandshakeRole>::FinalResult, - Error>>, - > + Unpin, + AllowStd, + ) -> Result< + > as HandshakeRole>::FinalResult, + Error>>, + > + Unpin, S: AsyncRead + AsyncWrite + Unpin, { let result = handshake(stream, f).await?; @@ -111,11 +111,11 @@ pub(crate) async fn server_handshake( where C: Callback + Unpin, F: FnOnce( - AllowStd, - ) -> Result< - , C> as HandshakeRole>::FinalResult, - Error, C>>, - > + Unpin, + AllowStd, + ) -> Result< + , C> as HandshakeRole>::FinalResult, + Error, C>>, + > + Unpin, S: AsyncRead + AsyncWrite + Unpin, { let s: WebSocket> = handshake(stream, f).await?; From 0f0665b4106c36dd3945616e96089bab14c1d7aa Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Fri, 25 Dec 2020 11:30:25 +0900 Subject: [PATCH 3/5] Update to tokio-native-tls 0.3.0 --- Cargo.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 10904dd8..3fcda83a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,9 +35,7 @@ version = "0.2.0" [dependencies.tokio-native-tls] optional = true -version = "0.2" -git = "https://github.com/tokio-rs/tls.git" -rev = "44e978cfa6e46294c0e352fad820456dbe94bdaa" +version = "0.3.0" [dev-dependencies] futures-channel = "0.3" From 078a227476d90bfd3ef68a70d0b78148a489dc26 Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Thu, 31 Dec 2020 22:09:19 +0900 Subject: [PATCH 4/5] Update tungstenite dependency to main repo --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3fcda83a..4e497b80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,8 +26,8 @@ tokio = { version = "1.0.0", default-features = false, features = ["io-util"] } [dependencies.tungstenite] version = "0.11.1" default-features = false -git = "https://github.com/nickelc/tungstenite-rs.git" -branch = "bytes" +git = "https://github.com/snapview/tungstenite-rs.git" +rev = "208061ba284eaf95a54c1b9b6968f570004c90de" [dependencies.native-tls] optional = true From c0e49797b0c7ccd40dcb2cce3e30ab458c521635 Mon Sep 17 00:00:00 2001 From: Daniel Abramov Date: Fri, 8 Jan 2021 13:27:04 +0100 Subject: [PATCH 5/5] Update to upstream version of tungstenite --- Cargo.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4e497b80..f9df670f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,10 +24,8 @@ pin-project = "1.0" tokio = { version = "1.0.0", default-features = false, features = ["io-util"] } [dependencies.tungstenite] -version = "0.11.1" +version = "0.12.0" default-features = false -git = "https://github.com/snapview/tungstenite-rs.git" -rev = "208061ba284eaf95a54c1b9b6968f570004c90de" [dependencies.native-tls] optional = true