#signal #sigint #flags #interrupt #boolean #signal-handler #set

signalbool

A simple crate to catch signals and set a boolean flag for later use

11 releases

0.2.5 Jun 21, 2022
0.2.4 Jul 9, 2020
0.2.3 Jun 28, 2019
0.2.2 Aug 8, 2018
0.1.3 May 30, 2017

#489 in Unix APIs

Download history 8/week @ 2024-07-20 69/week @ 2024-07-27 23/week @ 2024-08-03 14/week @ 2024-08-10 2/week @ 2024-08-17 3/week @ 2024-08-24 1/week @ 2024-08-31 2/week @ 2024-09-07 11/week @ 2024-09-14 21/week @ 2024-09-21 53/week @ 2024-09-28 28/week @ 2024-10-05 14/week @ 2024-10-12 7/week @ 2024-10-19 2/week @ 2024-10-26

58 downloads per month
Used in soapysdr

BSD-3-Clause

8KB
90 lines

A simple crate to catch signals and set a boolean flag for later use.

This crate doesn't create threads behind the scene.

Crates.io Version GitHub stars

Example

Here is a program that sleeps until it receives three SIGINT signals.

extern crate signalbool;
extern crate nix;

use nix::unistd::sleep;

fn main() {
  let mut sb = signalbool::SignalBool::new(
    &[signalbool::Signal::SIGINT], signalbool::Flag::Interrupt,
  ).unwrap();
  let mut count = 0;
    
  loop {
    sleep(10);
    if sb.caught() {
      println!("Caught SIGINT.");
      count += 1;
      sb.reset();
      if count == 3 {
        break;
      }
    }
  }
}

lib.rs:

A simple crate to catch signals and set a boolean flag for later use.

This crate doesn't create threads behind the scene.

Crates.io Version GitHub stars

Example

Here is a program that sleeps until it receives three SIGINT signals.

use nix::unistd::sleep;

let mut sb = signalbool::SignalBool::new(
  &[signalbool::Signal::SIGINT], signalbool::Flag::Interrupt,
).unwrap();
let mut count = 0;

loop {
  sleep(10);
  if sb.caught() {
    println!("Caught SIGINT.");
    count += 1;
    sb.reset();
    if count == 3 {
      break;
    }
  }
}

Dependencies

~2MB
~36K SLoC