avoid panic in CaptureContext::consume

This commit is contained in:
GyulyVGC
2025-12-19 14:52:16 +01:00
parent 7bd2b18c33
commit 5a251caeef
3 changed files with 13 additions and 7 deletions

View File

@@ -49,7 +49,9 @@ pub fn parse_packets(
let (mut freeze_rx, mut freeze_rx_2) = freeze_rxs;
let my_link_type = capture_context.my_link_type();
let (cap, mut savefile) = capture_context.consume();
let (Some(cap), mut savefile) = capture_context.consume() else {
return;
};
let mut info_traffic_msg = InfoTraffic::default();
let resolutions_state = Arc::new(Mutex::new(AddressesResolutionState::default()));

View File

@@ -74,7 +74,9 @@ fn handle_devices_and_previews(
name: dev_name,
my_link_type,
};
let (cap, _) = capture_context.consume();
let (Some(cap), _) = capture_context.consume() else {
continue;
};
let _ = thread::Builder::new()
.name("thread_device_traffic_preview".to_string())
.spawn(move || {

View File

@@ -69,12 +69,14 @@ pub fn error(&self) -> Option<&str> {
}
}
pub fn consume(self) -> (CaptureType, Option<Savefile>) {
pub fn consume(self) -> (Option<CaptureType>, Option<Savefile>) {
match self {
Self::Live(on) => (CaptureType::Live(on.cap), None),
Self::LiveWithSavefile(onws) => (CaptureType::Live(onws.live.cap), Some(onws.savefile)),
Self::Offline(off) => (CaptureType::Offline(off.cap), None),
Self::Error(_) => panic!(),
Self::Live(on) => (Some(CaptureType::Live(on.cap)), None),
Self::LiveWithSavefile(onws) => {
(Some(CaptureType::Live(onws.live.cap)), Some(onws.savefile))
}
Self::Offline(off) => (Some(CaptureType::Offline(off.cap)), None),
Self::Error(_) => (None, None),
}
}