use std::collections::HashSet;
use std::sync::Mutex;
#[derive(Default)]
pub struct NetlinkState {
cookies: Mutex<HashSet<(i32, i32)>>,
}
impl NetlinkState {
pub fn new() -> Self {
Self { cookies: Mutex::new(HashSet::new()) }
}
pub fn register(&self, pid: i32, fd: i32) {
self.cookies.lock().unwrap().insert((pid, fd));
}
pub fn unregister(&self, pid: i32, fd: i32) {
self.cookies.lock().unwrap().remove(&(pid, fd));
}
pub fn is_cookie(&self, pid: i32, fd: i32) -> bool {
self.cookies.lock().unwrap().contains(&(pid, fd))
}
}