Update omikron_connection.rs
This commit is contained in:
parent
b6ec165558
commit
4b6ca2e0e7
2 changed files with 1 additions and 141 deletions
|
|
@ -6,23 +6,14 @@ use std::time::Instant;
|
|||
use tokio::time::Duration;
|
||||
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
|
||||
|
||||
// Dedicated lightweight ping tracking
|
||||
static PING_TIMES: LazyLock<DashMap<u32, Instant>> = LazyLock::new(|| DashMap::new());
|
||||
|
||||
impl OmikronConnection {
|
||||
pub async fn send_ping(&self) {
|
||||
let id = rand_u32();
|
||||
|
||||
log!(
|
||||
"OmikronConnection::send_ping [id={}, ptr={:p}, ping_id={}]",
|
||||
self.connection_id,
|
||||
self,
|
||||
id
|
||||
);
|
||||
|
||||
PING_TIMES.insert(id, Instant::now());
|
||||
|
||||
// Auto-cleanup old pings (optional)
|
||||
PING_TIMES.retain(|_, v| v.elapsed() < Duration::from_secs(30));
|
||||
|
||||
let ping_message = CommunicationValue::new(CommunicationType::ping)
|
||||
|
|
@ -38,13 +29,6 @@ impl OmikronConnection {
|
|||
pub async fn handle_pong(&self, cv: &CommunicationValue) {
|
||||
let id = cv.get_id();
|
||||
|
||||
log!(
|
||||
"OmikronConnection::handle_pong [id={}, ptr={:p}, ping_id={}]",
|
||||
self.connection_id,
|
||||
self,
|
||||
id
|
||||
);
|
||||
|
||||
if let Some((_, send_time)) = PING_TIMES.remove(&id) {
|
||||
let ping_ms = Instant::now().duration_since(send_time).as_millis() as i64;
|
||||
*self.last_ping.lock().await = ping_ms;
|
||||
|
|
|
|||
Loading…
Reference in a new issue