Proper ctrl+c handling in Windows (fix #508)

This commit is contained in:
Roey Darwish Dror
2020-08-26 22:30:19 +03:00
parent 4657160f80
commit 1317e51096
7 changed files with 53 additions and 35 deletions

View File

@@ -1,9 +1,21 @@
//! A stub for Ctrl + C handling.
use crate::ctrlc::interrupted::set_interrupted;
use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE};
use winapi::um::consoleapi::SetConsoleCtrlHandler;
use winapi::um::wincon::CTRL_C_EVENT;
pub fn interrupted() -> bool {
false
extern "system" fn handler(ctrl_type: DWORD) -> BOOL {
match ctrl_type {
CTRL_C_EVENT => {
set_interrupted();
TRUE
}
_ => FALSE,
}
}
pub fn unset_interrupted() {}
pub fn set_handler() {}
pub fn set_handler() {
if 0 == unsafe { SetConsoleCtrlHandler(Some(handler), TRUE) } {
log::error!("Cannot set a control C handler")
}
}