Skip to main content

netscli_core/pcap/
cancel.rs

1use std::sync::{
2    atomic::{AtomicBool, Ordering},
3    Arc,
4};
5
6/// Cooperative cancellation token for long-running PCAP capture loops.
7///
8/// This is intentionally very small and dependency-free so it can be used across
9/// CLI/TUI/MCP/Tauri surfaces without pulling in additional async utilities.
10#[derive(Debug, Clone, Default)]
11pub struct PcapCancelToken {
12    cancelled: Arc<AtomicBool>,
13}
14
15impl PcapCancelToken {
16    pub fn new() -> Self {
17        Self {
18            cancelled: Arc::new(AtomicBool::new(false)),
19        }
20    }
21
22    pub fn cancel(&self) {
23        self.cancelled.store(true, Ordering::SeqCst);
24    }
25
26    pub fn is_cancelled(&self) -> bool {
27        self.cancelled.load(Ordering::SeqCst)
28    }
29}