Update to work on stable

pull/1/head
Danny Browning 5 years ago committed by Sebastian Dröge
parent 1764a42b19
commit 3ccd307be3
  1. 2
      Cargo.toml
  2. 6
      examples/autobahn-server.rs
  3. 6
      examples/server.rs
  4. 8
      tests/communication.rs
  5. 5
      tests/handshakes.rs

@ -19,7 +19,7 @@ stream = ["bytes"]
[dependencies] [dependencies]
log = "0.4" log = "0.4"
futures = { version = "0.3", features = ["async-await"] } futures = "0.3"
pin-project = "0.4" pin-project = "0.4"
[dependencies.tungstenite] [dependencies.tungstenite]

@ -25,12 +25,10 @@ async fn run() {
.expect("Not a valid address") .expect("Not a valid address")
.next() .next()
.expect("Not a socket address"); .expect("Not a socket address");
let socket = TcpListener::bind(&addr).await.unwrap(); let listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = socket.incoming();
info!("Listening on: {}", addr); info!("Listening on: {}", addr);
while let Some(stream) = incoming.next().await { while let Ok((stream, _)) = listener.accept().await {
let stream = stream.expect("Failed to get stream");
let peer = stream let peer = stream
.peer_addr() .peer_addr()
.expect("connected streams should have a peer address"); .expect("connected streams should have a peer address");

@ -92,12 +92,10 @@ async fn run() -> Result<(), Error> {
// Create the event loop and TCP listener we'll accept connections on. // Create the event loop and TCP listener we'll accept connections on.
let try_socket = TcpListener::bind(&addr).await; let try_socket = TcpListener::bind(&addr).await;
let socket = try_socket.expect("Failed to bind"); let listener = try_socket.expect("Failed to bind");
let mut incoming = socket.incoming();
info!("Listening on: {}", addr); info!("Listening on: {}", addr);
while let Some(stream) = incoming.next().await { while let Ok((stream, _)) = listener.accept().await {
let stream = stream.expect("Failed to accept stream");
task::spawn(accept_connection(stream)); task::spawn(accept_connection(stream));
} }

@ -37,12 +37,10 @@ async fn communication() {
.next() .next()
.expect("No address resolved"); .expect("No address resolved");
let listener = TcpListener::bind(&address).await.unwrap(); let listener = TcpListener::bind(&address).await.unwrap();
let mut connections = listener.incoming();
info!("Server ready"); info!("Server ready");
con_tx.send(()).unwrap(); con_tx.send(()).unwrap();
info!("Waiting on next connection"); info!("Waiting on next connection");
let connection = connections.next().await.expect("No connections to accept"); let (connection, _) = listener.accept().await.expect("No connections to accept");
let connection = connection.expect("Failed to accept connection");
let stream = accept_async(connection).await; let stream = accept_async(connection).await;
let stream = stream.expect("Failed to handshake with connection"); let stream = stream.expect("Failed to handshake with connection");
run_connection(stream, msg_tx).await; run_connection(stream, msg_tx).await;
@ -94,12 +92,10 @@ async fn split_communication() {
.next() .next()
.expect("No address resolved"); .expect("No address resolved");
let listener = TcpListener::bind(&address).await.unwrap(); let listener = TcpListener::bind(&address).await.unwrap();
let mut connections = listener.incoming();
info!("Server ready"); info!("Server ready");
con_tx.send(()).unwrap(); con_tx.send(()).unwrap();
info!("Waiting on next connection"); info!("Waiting on next connection");
let connection = connections.next().await.expect("No connections to accept"); let (connection, _) = listener.accept().await.expect("No connections to accept");
let connection = connection.expect("Failed to accept connection");
let stream = accept_async(connection).await; let stream = accept_async(connection).await;
let stream = stream.expect("Failed to handshake with connection"); let stream = stream.expect("Failed to handshake with connection");
run_connection(stream, msg_tx).await; run_connection(stream, msg_tx).await;

@ -1,4 +1,3 @@
use futures::StreamExt;
use async_std::task; use async_std::task;
use async_std::net::{TcpListener, TcpStream, ToSocketAddrs}; use async_std::net::{TcpListener, TcpStream, ToSocketAddrs};
use async_tungstenite::{accept_async, client_async}; use async_tungstenite::{accept_async, client_async};
@ -15,10 +14,8 @@ async fn handshakes() {
.next() .next()
.expect("No address resolved"); .expect("No address resolved");
let listener = TcpListener::bind(&address).await.unwrap(); let listener = TcpListener::bind(&address).await.unwrap();
let mut connections = listener.incoming();
tx.send(()).unwrap(); tx.send(()).unwrap();
while let Some(connection) = connections.next().await { while let Ok((connection, _)) = listener.accept().await {
let connection = connection.expect("Failed to accept connection");
let stream = accept_async(connection).await; let stream = accept_async(connection).await;
stream.expect("Failed to handshake with connection"); stream.expect("Failed to handshake with connection");
} }

Loading…
Cancel
Save