From 057b77b067c84aaacde8ba0911015315e967ba48 Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Fri, 7 Jun 2024 18:47:15 +0800 Subject: [PATCH] TrafficStatus improvement --- src/traffic_status.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/traffic_status.rs b/src/traffic_status.rs index 859fcbf..7548ed0 100644 --- a/src/traffic_status.rs +++ b/src/traffic_status.rs @@ -51,6 +51,15 @@ lazy_static::lazy_static! { } pub(crate) fn traffic_status_update(delta_tx: usize, delta_rx: usize) -> Result<()> { + { + let is_none_or_error = TRAFFIC_STATUS_CALLBACK.lock().map(|guard| guard.is_none()).unwrap_or_else(|e| { + log::error!("Failed to acquire lock: {}", e); + true + }); + if is_none_or_error { + return Ok(()); + } + } { let mut traffic_status = TRAFFIC_STATUS.write().map_err(|e| Error::from(e.to_string()))?; traffic_status.tx += delta_tx as u64;