[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:
@@ -279,6 +279,7 @@ async fn async_init() -> DynResult<AppState> {
|
|||||||
known_rigs: frontend_runtime.remote_rigs.clone(),
|
known_rigs: frontend_runtime.remote_rigs.clone(),
|
||||||
poll_interval: Duration::from_millis(poll_interval_ms),
|
poll_interval: Duration::from_millis(poll_interval_ms),
|
||||||
spectrum: frontend_runtime.spectrum.clone(),
|
spectrum: frontend_runtime.spectrum.clone(),
|
||||||
|
server_connected: frontend_runtime.server_connected.clone(),
|
||||||
};
|
};
|
||||||
let remote_shutdown_rx = shutdown_rx.clone();
|
let remote_shutdown_rx = shutdown_rx.clone();
|
||||||
task_handles.push(tokio::spawn(async move {
|
task_handles.push(tokio::spawn(async move {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: BSD-2-Clause
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{sync::Arc, sync::Mutex};
|
use std::{sync::Arc, sync::Mutex};
|
||||||
|
|
||||||
@@ -55,6 +56,8 @@ pub struct RemoteClientConfig {
|
|||||||
pub poll_interval: Duration,
|
pub poll_interval: Duration,
|
||||||
/// Spectrum watch sender; spectrum task publishes here, SSE clients subscribe.
|
/// Spectrum watch sender; spectrum task publishes here, SSE clients subscribe.
|
||||||
pub spectrum: Arc<watch::Sender<SharedSpectrum>>,
|
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(
|
pub async fn run_remote_client(
|
||||||
@@ -90,11 +93,13 @@ pub async fn run_remote_client(
|
|||||||
if let Err(e) = stream.set_nodelay(true) {
|
if let Err(e) = stream.set_nodelay(true) {
|
||||||
warn!("TCP_NODELAY failed: {}", e);
|
warn!("TCP_NODELAY failed: {}", e);
|
||||||
}
|
}
|
||||||
|
config.server_connected.store(true, Ordering::Relaxed);
|
||||||
if let Err(e) =
|
if let Err(e) =
|
||||||
handle_connection(&config, stream, &mut rx, &state_tx, &mut shutdown_rx).await
|
handle_connection(&config, stream, &mut rx, &state_tx, &mut shutdown_rx).await
|
||||||
{
|
{
|
||||||
warn!("Remote connection dropped: {}", e);
|
warn!("Remote connection dropped: {}", e);
|
||||||
}
|
}
|
||||||
|
config.server_connected.store(false, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
Ok(Err(e)) => {
|
Ok(Err(e)) => {
|
||||||
warn!("Remote connect failed: {}", e);
|
warn!("Remote connect failed: {}", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user