summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorebroto <ebroto@tutanota.com>2019-12-23 08:46:17 +0100
committerAram Drevekenin <aram@poor.dev>2019-12-23 08:46:17 +0100
commit6ba0d2c0ba38cab433c8a98735eeaf841fcedbaf (patch)
treed7b34c8c17358fea45f5a3be718a89319ef23596
parenta944cbd9d35b7b35be82cff89c5dfbdab17fc3dc (diff)
fix(interfaces): Fix invalid bandwith rate (#27)
Use one thread per interface. It seems that we were missing packets with the previous approach.
-rw-r--r--src/main.rs46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs
index 26d4e14..66a3361 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -105,13 +105,6 @@ where
let raw_mode = opts.raw;
- let mut sniffers = os_input
- .network_interfaces
- .into_iter()
- .zip(os_input.network_frames.into_iter())
- .map(|(iface, frames)| Sniffer::new(iface, frames))
- .collect::<Vec<Sniffer>>();
-
let network_utilization = Arc::new(Mutex::new(Utilization::new()));
let ui = Arc::new(Mutex::new(Ui::new(terminal_backend)));
@@ -199,22 +192,31 @@ where
);
active_threads.push(display_handler);
- active_threads.push(
- thread::Builder::new()
- .name("sniffing_handler".to_string())
- .spawn(move || 'sniffing: loop {
- for sniffer in sniffers.iter_mut() {
- if let Some(segment) = sniffer.next() {
- network_utilization.lock().unwrap().update(segment);
- }
- if !running.load(Ordering::Acquire) {
- // Break from the outer loop and finish the thread
- break 'sniffing;
+ let sniffer_threads = os_input
+ .network_interfaces
+ .into_iter()
+ .zip(os_input.network_frames.into_iter())
+ .map(|(iface, frames)| {
+ let name = format!("sniffing_handler_{}", iface.name);
+ let running = running.clone();
+ let network_utilization = network_utilization.clone();
+
+ thread::Builder::new()
+ .name(name)
+ .spawn(move || {
+ let mut sniffer = Sniffer::new(iface, frames);
+
+ while running.load(Ordering::Acquire) {
+ if let Some(segment) = sniffer.next() {
+ network_utilization.lock().unwrap().update(segment);
+ }
}
- }
- })
- .unwrap(),
- );
+ })
+ .unwrap()
+ })
+ .collect::<Vec<_>>();
+ active_threads.extend(sniffer_threads);
+
for thread_handler in active_threads {
thread_handler.join().unwrap()
}