diff --git a/src/trx-client/src/main.rs b/src/trx-client/src/main.rs index 38119a9..67c11ff 100644 --- a/src/trx-client/src/main.rs +++ b/src/trx-client/src/main.rs @@ -279,6 +279,7 @@ async fn async_init() -> DynResult { known_rigs: frontend_runtime.remote_rigs.clone(), poll_interval: Duration::from_millis(poll_interval_ms), spectrum: frontend_runtime.spectrum.clone(), + server_connected: frontend_runtime.server_connected.clone(), }; let remote_shutdown_rx = shutdown_rx.clone(); task_handles.push(tokio::spawn(async move { diff --git a/src/trx-client/src/remote_client.rs b/src/trx-client/src/remote_client.rs index 9f4b890..a0742e3 100644 --- a/src/trx-client/src/remote_client.rs +++ b/src/trx-client/src/remote_client.rs @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: BSD-2-Clause +use std::sync::atomic::{AtomicBool, Ordering}; use std::time::Duration; use std::{sync::Arc, sync::Mutex}; @@ -55,6 +56,8 @@ pub struct RemoteClientConfig { pub poll_interval: Duration, /// Spectrum watch sender; spectrum task publishes here, SSE clients subscribe. pub spectrum: Arc>, + /// Shared flag: `true` while a TCP connection to trx-server is active. + pub server_connected: Arc, } pub async fn run_remote_client( @@ -90,11 +93,13 @@ pub async fn run_remote_client( if let Err(e) = stream.set_nodelay(true) { warn!("TCP_NODELAY failed: {}", e); } + config.server_connected.store(true, Ordering::Relaxed); if let Err(e) = handle_connection(&config, stream, &mut rx, &state_tx, &mut shutdown_rx).await { warn!("Remote connection dropped: {}", e); } + config.server_connected.store(false, Ordering::Relaxed); } Ok(Err(e)) => { warn!("Remote connect failed: {}", e);