Skip to content

Commit

Permalink
fixes for sending without blocking to zmq monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
ltn-chriskennedy committed Apr 18, 2024
1 parent a10c7ef commit d90d789
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion specs/rscap.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: rscap
Version: 0.5.49
Version: 0.5.49.1
Release: 1%{?dist}
Summary: RsCap and GStreamer with essential dependencies
License: MIT
Expand Down
9 changes: 7 additions & 2 deletions src/bin/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ async fn rscap(running: Arc<AtomicBool>) {
let mut dot_last_sent_ts = Instant::now();

while running_zmq.load(Ordering::SeqCst) {
while let Some(mut batch) = rx.recv().await {
while let Ok(mut batch) = rx.try_recv() {
// Process and send messages
for stream_data in batch.iter() {
// Serialize StreamData to Cap'n Proto message
Expand Down Expand Up @@ -930,6 +930,8 @@ async fn rscap(running: Arc<AtomicBool>) {
}
batch.clear();
}
// Sleep for a short time to avoid busy waiting
tokio::time::sleep(std::time::Duration::from_millis(1)).await;
}
});

Expand Down Expand Up @@ -1272,7 +1274,10 @@ async fn rscap(running: Arc<AtomicBool>) {
if batch.len() >= zmq_batch_size {
//info!("STATUS::BATCH:SEND: {}", batch.len());
// Send the batch to the channel
tx.send(batch).await.unwrap();
if tx.try_send(batch).is_err() {
// If the channel is full, drop the batch
info!("ZeroMQ channel is full. Dropping batch.");
}
// release the packet Arc so it can be reused
batch = Vec::new(); // Create a new Vec for the next batch
} else {
Expand Down

0 comments on commit d90d789

Please sign in to comment.