Still working on timeouts

This commit is contained in:
Ricardo Zuasti
2026-01-13 19:26:28 -05:00
parent a034481ca5
commit e08d257687
3 changed files with 9 additions and 7 deletions
+7 -3
View File
@@ -7,7 +7,7 @@ use pnet::{
ipnetwork::IpNetwork, ipnetwork::IpNetwork,
}; };
use tokio::task; use tokio::task;
use tokio::time::{Duration, sleep, timeout}; use tokio::time::{Duration, Instant, sleep, timeout};
mod packet_send_receive; mod packet_send_receive;
@@ -55,17 +55,21 @@ pub async fn find(interface: &str) -> Vec<Device> {
let send_interface = network_interface.clone(); let send_interface = network_interface.clone();
println!("Starting sender"); println!("Starting sender");
let start = Instant::now();
let send_result = timeout( let send_result = timeout(
Duration::from_secs(2), Duration::from_millis(10),
send_packet(sender, send_interface, ipv4_net, mac), send_packet(sender, send_interface, ipv4_net, mac),
// test_timeout(),
) )
.await; .await;
match send_result { match send_result {
Ok(_) => println!("Sender done"), Ok(_) => println!("Sender done"),
Err(_) => println!("Sender timed out"), Err(_) => println!("Sender timed out"),
}; };
println!(
"Sender took {} millisecs",
(Instant::now() - start).as_millis()
);
// let receive_result = timeout( // let receive_result = timeout(
// Duration::from_secs(5), // Duration::from_secs(5),
@@ -45,10 +45,8 @@ pub async fn send_packet(
&ethernet_packet.to_immutable().packet(), &ethernet_packet.to_immutable().packet(),
Some(interface.clone()), Some(interface.clone()),
); );
// thread::sleep(Duration::from_millis(2));
} }
sleep(Duration::from_secs(5)).await; // sleep(Duration::from_millis(1)).await;
// thread::sleep(Duration::from_millis(2));
} }
} }
+1 -1
View File
@@ -2,7 +2,7 @@ mod device_finders;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let devices = device_finders::arp::find("eno1").await; let devices = device_finders::arp::find("wlp1s0").await;
for device in devices.iter() { for device in devices.iter() {
println!("{}", device); println!("{}", device);