[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 <noreply@anthropic.com>
Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
2026-03-16 23:27:44 +01:00
parent 1f4c3e0384
commit 1b6ae1b18c
2 changed files with 6 additions and 0 deletions
+1
View File
@@ -279,6 +279,7 @@ async fn async_init() -> DynResult<AppState> {
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 {
+5
View File
@@ -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<watch::Sender<SharedSpectrum>>,
/// Shared flag: `true` while a TCP connection to trx-server is active.
pub server_connected: Arc<AtomicBool>,
}
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);