Skip to content

Commit

Permalink
Upgrade tokio-tungstenite, add explicit flushes
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvealerts committed Oct 2, 2023
1 parent 3fb36e5 commit 0927830
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/libs/ml2_mods/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tokio = { version = "1.32", features = [
"tracing",
] }
tokio-graceful-shutdown = "0.13"
tokio-tungstenite = { version = "0.19", features = ["native-tls"] }
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
tower = { version = "0.4", features = ["util"] }
tracing = "0.1"
zip = "0.6"
Expand Down
12 changes: 4 additions & 8 deletions src/libs/ml2_mods/src/spelunkyfyi/web_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,8 @@ impl WebSocketClient {
.header(SEC_WEBSOCKET_KEY, generate_key())
.body(())?;

// This is the maximum number of messages that will be queued in Tungstenite. This doesn't
// include pong or close messages. All messages are buffered before they're written. So,
// the smallest functional value is 1. Notably, the size of the messages and the underlying
// TCP send buffer aren't considered.
let config = WebSocketConfig {
max_send_queue: Some(2),
..Default::default()
};
let mut config = WebSocketConfig::default();
config.max_write_buffer_size = 2 * config.write_buffer_size;

let mut stream = tokio_tungstenite::connect_async_with_config(request, Some(config), false)
.await
Expand Down Expand Up @@ -163,6 +157,7 @@ impl WebSocketClient {
stream
.send(Message::Ping(payload))
.await?;
stream.flush().await?;
check_state = Check::Pong();
check_sleep = Box::pin(time::sleep(self.pong_timeout));
}
Expand Down Expand Up @@ -312,6 +307,7 @@ async fn send_message(
) -> Result<(), ConnectionError> {
let reply = serde_json::to_string(&msg)?;
stream.send(Message::Text(reply)).await?;
stream.flush().await?;
Ok(())
}

Expand Down

0 comments on commit 0927830

Please sign in to comment.