Skip to content

Commit f63f242

Browse files
authored
Update tokio-tungstenite to version 0.26.1 (#28)
* update tokio-tungstenite to version 0.26.1 and improve binary message handling * fmt code
1 parent b46cf22 commit f63f242

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ freenet-macros = { path = "../rust-macros", version = "0.1.0-rc1" }
3232

3333
[target.'cfg(any(unix, windows))'.dependencies]
3434
tokio = { version = "1", optional = true, features = ["macros", "parking_lot", "rt-multi-thread", "sync", "time"] }
35-
tokio-tungstenite = { version = "0.24", optional = true }
35+
tokio-tungstenite = { version = "0.26.1", optional = true }
3636
serde_with = { version = "3" }
3737

3838
[target.'cfg(target_family = "wasm")'.dependencies]

rust/src/client_api/regular.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use std::{borrow::Cow, task::Poll};
22

3+
use super::{
4+
client_events::{ClientError, ClientRequest, ErrorKind},
5+
Error, HostResult,
6+
};
37
use futures::{pin_mut, FutureExt, Sink, SinkExt, Stream, StreamExt};
48
use tokio::{
59
net::TcpStream,
610
sync::mpsc::{self, Receiver, Sender},
711
};
812
use tokio_tungstenite::{tungstenite::Message, MaybeTlsStream, WebSocketStream};
913

10-
use super::{
11-
client_events::{ClientError, ClientRequest, ErrorKind},
12-
Error, HostResult,
13-
};
14-
1514
type Connection = WebSocketStream<MaybeTlsStream<TcpStream>>;
1615

1716
pub struct WebApi {
@@ -163,7 +162,7 @@ async fn process_request(
163162
let msg = bincode::serialize(&req)
164163
.map_err(Into::into)
165164
.map_err(Error::OtherError)?;
166-
conn.send(Message::Binary(msg)).await?;
165+
conn.send(Message::Binary(msg.into())).await?;
167166
Ok(())
168167
}
169168

@@ -183,7 +182,7 @@ async fn process_response(
183182
.map_err(|_| Error::ChannelClosed)?;
184183
}
185184
Message::Binary(binary) => {
186-
let response: HostResult = bincode::deserialize(binary.as_slice())?;
185+
let response: HostResult = bincode::deserialize(&binary)?;
187186
response_tx
188187
.send(response)
189188
.await
@@ -233,7 +232,7 @@ mod test {
233232
if !self.recv {
234233
let res: HostResult = Ok(HostResponse::Ok);
235234
let req = bincode::serialize(&res)?;
236-
stream.send(Message::Binary(req)).await?;
235+
stream.send(Message::Binary(req.into())).await?;
237236
}
238237

239238
let Message::Binary(msg) = stream.next().await.ok_or_else(|| "no msg".to_owned())??

0 commit comments

Comments
 (0)