From 3ccd307be3d259363b477e8513efa7b30f9fdba3 Mon Sep 17 00:00:00 2001 From: Danny Browning Date: Fri, 15 Nov 2019 10:25:58 -0700 Subject: [PATCH] Update to work on stable --- Cargo.toml | 2 +- examples/autobahn-server.rs | 6 ++---- examples/server.rs | 6 ++---- tests/communication.rs | 8 ++------ tests/handshakes.rs | 5 +---- 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7b3f14..33e57e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ stream = ["bytes"] [dependencies] log = "0.4" -futures = { version = "0.3", features = ["async-await"] } +futures = "0.3" pin-project = "0.4" [dependencies.tungstenite] diff --git a/examples/autobahn-server.rs b/examples/autobahn-server.rs index bda50b7..e2f2169 100644 --- a/examples/autobahn-server.rs +++ b/examples/autobahn-server.rs @@ -25,12 +25,10 @@ async fn run() { .expect("Not a valid address") .next() .expect("Not a socket address"); - let socket = TcpListener::bind(&addr).await.unwrap(); - let mut incoming = socket.incoming(); + let listener = TcpListener::bind(&addr).await.unwrap(); info!("Listening on: {}", addr); - while let Some(stream) = incoming.next().await { - let stream = stream.expect("Failed to get stream"); + while let Ok((stream, _)) = listener.accept().await { let peer = stream .peer_addr() .expect("connected streams should have a peer address"); diff --git a/examples/server.rs b/examples/server.rs index 35d03e2..983c648 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -92,12 +92,10 @@ async fn run() -> Result<(), Error> { // Create the event loop and TCP listener we'll accept connections on. let try_socket = TcpListener::bind(&addr).await; - let socket = try_socket.expect("Failed to bind"); - let mut incoming = socket.incoming(); + let listener = try_socket.expect("Failed to bind"); info!("Listening on: {}", addr); - while let Some(stream) = incoming.next().await { - let stream = stream.expect("Failed to accept stream"); + while let Ok((stream, _)) = listener.accept().await { task::spawn(accept_connection(stream)); } diff --git a/tests/communication.rs b/tests/communication.rs index ded9c8b..5708438 100644 --- a/tests/communication.rs +++ b/tests/communication.rs @@ -37,12 +37,10 @@ async fn communication() { .next() .expect("No address resolved"); let listener = TcpListener::bind(&address).await.unwrap(); - let mut connections = listener.incoming(); info!("Server ready"); con_tx.send(()).unwrap(); info!("Waiting on next connection"); - let connection = connections.next().await.expect("No connections to accept"); - let connection = connection.expect("Failed to accept connection"); + let (connection, _) = listener.accept().await.expect("No connections to accept"); let stream = accept_async(connection).await; let stream = stream.expect("Failed to handshake with connection"); run_connection(stream, msg_tx).await; @@ -94,12 +92,10 @@ async fn split_communication() { .next() .expect("No address resolved"); let listener = TcpListener::bind(&address).await.unwrap(); - let mut connections = listener.incoming(); info!("Server ready"); con_tx.send(()).unwrap(); info!("Waiting on next connection"); - let connection = connections.next().await.expect("No connections to accept"); - let connection = connection.expect("Failed to accept connection"); + let (connection, _) = listener.accept().await.expect("No connections to accept"); let stream = accept_async(connection).await; let stream = stream.expect("Failed to handshake with connection"); run_connection(stream, msg_tx).await; diff --git a/tests/handshakes.rs b/tests/handshakes.rs index 09b16aa..a06b789 100644 --- a/tests/handshakes.rs +++ b/tests/handshakes.rs @@ -1,4 +1,3 @@ -use futures::StreamExt; use async_std::task; use async_std::net::{TcpListener, TcpStream, ToSocketAddrs}; use async_tungstenite::{accept_async, client_async}; @@ -15,10 +14,8 @@ async fn handshakes() { .next() .expect("No address resolved"); let listener = TcpListener::bind(&address).await.unwrap(); - let mut connections = listener.incoming(); tx.send(()).unwrap(); - while let Some(connection) = connections.next().await { - let connection = connection.expect("Failed to accept connection"); + while let Ok((connection, _)) = listener.accept().await { let stream = accept_async(connection).await; stream.expect("Failed to handshake with connection"); }