Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/components/core_zmq_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use futures::StreamExt;
#[cfg(target_os = "windows")]
use tokio::runtime::Runtime;
#[cfg(target_os = "windows")]
use tokio::time::timeout;
#[cfg(target_os = "windows")]
use zeromq::{Socket, SocketRecv, SubSocket};

pub struct CoreZMQListener {
Expand Down Expand Up @@ -312,11 +314,10 @@ impl CoreZMQListener {
.expect("Failed to subscribe to rawchainlock");

println!("Subscribed to ZMQ at {}", endpoint);

while !should_stop_clone.load(Ordering::SeqCst) {
// Receive messages
match socket.recv().await {
Ok(msg) => {
match timeout(Duration::from_secs(30), socket.recv()).await {
Ok(Ok(msg)) => {
// Process the message
// Access frames using msg.get(n)
if let Some(topic_frame) = msg.get(0) {
let topic = String::from_utf8_lossy(topic_frame).to_string();
Expand All @@ -330,6 +331,11 @@ impl CoreZMQListener {
let mut cursor = Cursor::new(data_bytes);
match Block::consensus_decode(&mut cursor) {
Ok(block) => {
if let Some(ref tx) = tx_zmq_status {
// ZMQ refresh socket connected status
tx.send(ZMQConnectionEvent::Connected)
.expect("Failed to send connected event");
}
if let Err(e) = sender_clone.send((
ZMQMessage::ChainLockedBlock(block),
network,
Expand All @@ -356,6 +362,11 @@ impl CoreZMQListener {
match InstantLock::consensus_decode(&mut cursor)
{
Ok(islock) => {
if let Some(ref tx) = tx_zmq_status {
// ZMQ refresh socket connected status
tx.send(ZMQConnectionEvent::Connected)
.expect("Failed to send connected event");
}
if let Err(e) = sender_clone.send((
ZMQMessage::ISLockedTransaction(
tx, islock,
Expand Down Expand Up @@ -390,12 +401,20 @@ impl CoreZMQListener {
}
}
}
}
Err(e) => {
},
Ok(Err(e)) => {
// Handle recv error
eprintln!("Error receiving message: {}", e);
// Sleep briefly before retrying
tokio::time::sleep(Duration::from_millis(100)).await;
}
},
Err(_) => {
// Timeout occurred, handle disconnection
if let Some(ref tx) = tx_zmq_status {
tx.send(ZMQConnectionEvent::Disconnected)
.expect("Failed to send connected event");
}
},
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/ui/components/top_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ pub fn add_top_panel(
.exact_height(50.0)
.show(ctx, |ui| {
egui::menu::bar(ui, |ui| {
#[cfg(not(target_os = "windows"))]
{
action |= add_connection_indicator(ui, app_context);
}
action |= add_connection_indicator(ui, app_context);

// Left-aligned content with location view
action |= add_location_view(ui, location);
Expand Down