File: sigint.rs

package info (click to toggle)
rust-async-signal 0.2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 168 kB
  • sloc: makefile: 2
file content (32 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use async_signal::{Signal, Signals};
use futures_lite::{future, prelude::*};

/// Send SIGINT to the current process.
#[cfg(unix)]
fn sigint() {
    unsafe {
        libc::raise(libc::SIGINT);
    }
}

/// Send SIGINT to the current process.
#[cfg(windows)]
fn sigint() {
    unsafe {
        windows_sys::Win32::System::Console::GenerateConsoleCtrlEvent(
            windows_sys::Win32::System::Console::CTRL_C_EVENT,
            0,
        );
    }
}

#[test]
fn test_sigint() {
    future::block_on(async {
        let mut signals = Signals::new(Some(Signal::Int)).unwrap();
        let mut next = signals.next();
        assert!(future::poll_once(&mut next).await.is_none());
        sigint();
        assert_eq!(signals.next().await.unwrap().unwrap(), Signal::Int);
    });
}