Drop connection and not crash if websocket handshake fails
This commit is contained in:
parent
1da12cab48
commit
eda7b087a9
1 changed files with 10 additions and 2 deletions
12
src/main.rs
12
src/main.rs
|
@ -64,8 +64,16 @@ async fn accept_conn(peer: SocketAddr, stream: TcpStream, redis_client: Client,
|
|||
|
||||
async fn handle_conn(peer: SocketAddr, stream: TcpStream, redis_client: Client, shared_secret: String) -> tokio_tungstenite::tungstenite::Result<()> {
|
||||
let ws_stream = tokio_tungstenite::accept_async(stream)
|
||||
.await
|
||||
.expect("Failed to complete the websocket handshake!");
|
||||
.await;
|
||||
|
||||
if ws_stream.is_err() {
|
||||
println!("Failed to complete the websocket handshake! Dropping {}!", peer);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let ws_stream = ws_stream.unwrap();
|
||||
|
||||
println!("Connected to peer: {}!", &peer);
|
||||
|
||||
let (mut ws_sender, mut ws_receiver) = ws_stream.split();
|
||||
|
|
Loading…
Add table
Reference in a new issue