From b2c91c09bea3e86e14ee875d2295753eddc759c5 Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Sat, 22 Mar 2025 10:57:59 -0600 Subject: [PATCH] Calculate TCP flight time in current thread --- idevice/src/tcp/mod.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/idevice/src/tcp/mod.rs b/idevice/src/tcp/mod.rs index 14ac081..b1da728 100644 --- a/idevice/src/tcp/mod.rs +++ b/idevice/src/tcp/mod.rs @@ -15,22 +15,13 @@ pub(crate) async fn log_packet(file: &Arc>, debug!("Logging {} byte packet", packet.len()); let packet = packet.to_vec(); let file = file.to_owned(); + let now = SystemTime::now(); tokio::task::spawn(async move { let mut file = file.lock().await; - file.write_all( - &(SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_secs() as u32) - .to_le_bytes(), - ) - .await - .unwrap(); - let micros = SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_micros() - % 1_000_000_000; + file.write_all(&(now.duration_since(UNIX_EPOCH).unwrap().as_secs() as u32).to_le_bytes()) + .await + .unwrap(); + let micros = now.duration_since(UNIX_EPOCH).unwrap().as_micros() % 1_000_000_000; file.write_all(&(micros as u32).to_le_bytes()) .await .unwrap();