From 1b6ae1b18c052955e29216d4625c175212314bc9 Mon Sep 17 00:00:00 2001 From: Stanislaw Grams Date: Mon, 16 Mar 2026 23:27:44 +0100 Subject: [PATCH] [feat](trx-client): set server_connected around trx-server TCP session Store server_connected in RemoteClientConfig and set it true when handle_connection begins, false when it returns. Wire the Arc clone from FrontendRuntimeContext into the config at startup. Co-authored-by: Claude Sonnet 4.6 Signed-off-by: Stanislaw Grams --- src/trx-client/src/main.rs | 1 + src/trx-client/src/remote_client.rs | 5 +++++ 2 files changed, 6 insertions(+) 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);