Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (23 sloc) 668 Bytes
use crate::error::Result;
use signal_hook::{self, SigId, SIGWINCH};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
pub struct SigwinchWatcher {
flag: Arc<AtomicBool>,
signal_id: SigId,
}
impl SigwinchWatcher {
pub fn new() -> Result<Self> {
let flag = Arc::new(AtomicBool::new(false));
let signal_id = signal_hook::flag::register(SIGWINCH, Arc::clone(&flag))?;
Ok(Self { flag, signal_id })
}
pub fn notified(&mut self) -> bool {
self.flag.swap(false, Ordering::Relaxed)
}
}
impl Drop for SigwinchWatcher {
fn drop(&mut self) {
signal_hook::unregister(self.signal_id);
}
}
You can’t perform that action at this time.