Skip to content

Commit 3b930b7

Browse files
committed
refacto(server): allow client connect without frame
1 parent 67ce5b3 commit 3b930b7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

puffin_http/src/server.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::Context as _;
2+
use crossbeam_channel::TryRecvError;
23
use puffin::{FrameSinkId, GlobalProfiler, ScopeCollection};
34
use std::{
45
io::Write as _,
@@ -7,6 +8,7 @@ use std::{
78
Arc,
89
atomic::{AtomicUsize, Ordering},
910
},
11+
time::Duration,
1012
};
1113

1214
/// Maximum size of the backlog of packets to send to a client if they aren't reading fast enough.
@@ -261,13 +263,22 @@ impl Server {
261263
scope_collection: Default::default(),
262264
};
263265

264-
while let Ok(frame) = rx.recv() {
266+
loop {
265267
if let Err(err) = server_impl.accept_new_clients() {
266268
log::warn!("puffin server failure: {err}");
267269
}
268-
269-
if let Err(err) = server_impl.send(&frame) {
270-
log::warn!("puffin server failure: {err}");
270+
match rx.try_recv() {
271+
Ok(frame) => {
272+
if let Err(err) = server_impl.send(&frame) {
273+
log::warn!("puffin server failure: {err}");
274+
}
275+
}
276+
Err(TryRecvError::Empty) => {
277+
std::thread::sleep(Duration::from_millis(1));
278+
}
279+
Err(TryRecvError::Disconnected) => {
280+
break;
281+
}
271282
}
272283
}
273284
})

0 commit comments

Comments
 (0)