Skip to content

Commit e4fc1c5

Browse files
committed
refactor(glueball): use SynthesisStream trait everywhere
1 parent 46d8dbb commit e4fc1c5

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

glueball/src/connection.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
error_global, info_global,
77
messaging::{handle_client_message, wait_for_initialization},
88
model::ServerToClientMessage,
9-
prefixed::{ConnectionStatus, into_prefixed_or_respond},
9+
prefixed::{ConnectionStatus, SynthesisStream, into_prefixed_or_respond},
1010
room::ClientId,
1111
state::State,
1212
util::{server_sent_msg, trim_uuid},
@@ -15,18 +15,14 @@ use crate::{
1515
use anyhow::{Result, bail};
1616
use futures_util::{SinkExt, StreamExt};
1717
use std::{net::SocketAddr, sync::Arc, time::Duration};
18-
use tokio::{
19-
io::{AsyncRead, AsyncWrite},
20-
sync::mpsc,
21-
time::timeout,
22-
};
18+
use tokio::{sync::mpsc, time::timeout};
2319
use tokio_tungstenite::tungstenite::Message;
2420

2521
pub const TIMEOUT: Duration = Duration::from_secs(30);
2622

2723
pub async fn handle_connection<S>(state: Arc<State>, raw_stream: S, addr: SocketAddr)
2824
where
29-
S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
25+
S: SynthesisStream,
3026
{
3127
let ConnectionStatus::Ws(stream) = into_prefixed_or_respond(raw_stream, addr).await else {
3228
return;

glueball/src/prefixed.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ impl<S: AsyncRead + Unpin> AsyncRead for Prefixed<S> {
3333

3434
if pos < data.len() {
3535
let n = (data.len() - pos).min(buf.remaining());
36+
3637
buf.put_slice(&data[pos..pos + n]);
3738
self.prefix.set_position((pos + n) as u64);
39+
3840
return Poll::Ready(Ok(()));
3941
}
4042

@@ -72,7 +74,7 @@ pub enum ConnectionStatus<S> {
7274

7375
pub async fn into_prefixed_or_respond<S>(mut raw_stream: S, addr: SocketAddr) -> ConnectionStatus<S>
7476
where
75-
S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
77+
S: SynthesisStream,
7678
{
7779
// "Peek" at the request: read the first chunk, then replay it in front of
7880
// the stream. `peek()` is an inherent method on `TcpStream` (not a trait),

0 commit comments

Comments
 (0)