Calculate TCP flight time in current thread

This commit is contained in:
Jackson Coxson
2025-03-22 10:57:59 -06:00
parent 873240c4aa
commit b2c91c09be

View File

@@ -15,22 +15,13 @@ pub(crate) async fn log_packet(file: &Arc<tokio::sync::Mutex<tokio::fs::File>>,
debug!("Logging {} byte packet", packet.len()); debug!("Logging {} byte packet", packet.len());
let packet = packet.to_vec(); let packet = packet.to_vec();
let file = file.to_owned(); let file = file.to_owned();
let now = SystemTime::now();
tokio::task::spawn(async move { tokio::task::spawn(async move {
let mut file = file.lock().await; let mut file = file.lock().await;
file.write_all( file.write_all(&(now.duration_since(UNIX_EPOCH).unwrap().as_secs() as u32).to_le_bytes())
&(SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as u32)
.to_le_bytes(),
)
.await .await
.unwrap(); .unwrap();
let micros = SystemTime::now() let micros = now.duration_since(UNIX_EPOCH).unwrap().as_micros() % 1_000_000_000;
.duration_since(UNIX_EPOCH)
.unwrap()
.as_micros()
% 1_000_000_000;
file.write_all(&(micros as u32).to_le_bytes()) file.write_all(&(micros as u32).to_le_bytes())
.await .await
.unwrap(); .unwrap();