mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-05 05:47:40 +03:00
Fix windows signals support (#325)
This commit is contained in:
parent
0e21f46210
commit
18d3516343
3 changed files with 48 additions and 15 deletions
|
@ -1,5 +1,9 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [1.0.3] - 2024-03-29
|
||||||
|
|
||||||
|
* Fix windows signals support
|
||||||
|
|
||||||
## [1.0.2] - 2024-03-25
|
## [1.0.2] - 2024-03-25
|
||||||
|
|
||||||
* Add basic signals support
|
* Add basic signals support
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ntex-server"
|
name = "ntex-server"
|
||||||
version = "1.0.2"
|
version = "1.0.3"
|
||||||
authors = ["ntex contributors <team@ntex.rs>"]
|
authors = ["ntex contributors <team@ntex.rs>"]
|
||||||
description = "Server for ntex framework"
|
description = "Server for ntex framework"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
|
|
|
@ -85,20 +85,49 @@ pub(crate) fn start<T: Send + 'static>(srv: Server<T>) {
|
||||||
/// Signals are handled by oneshots, you have to re-register
|
/// Signals are handled by oneshots, you have to re-register
|
||||||
/// after each signal.
|
/// after each signal.
|
||||||
pub(crate) fn start<T: Send + 'static>(srv: Server<T>) {
|
pub(crate) fn start<T: Send + 'static>(srv: Server<T>) {
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use ntex_rt::spawn;
|
||||||
|
|
||||||
|
static CUR_SYS: Mutex<RefCell<Option<System>>> = Mutex::new(RefCell::new(None));
|
||||||
|
|
||||||
|
let guard = match CUR_SYS.lock() {
|
||||||
|
Ok(guard) => guard,
|
||||||
|
Err(_) => {
|
||||||
|
log::error!("Cannot lock mutex");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut sys = guard.borrow_mut();
|
||||||
|
let started = sys.is_some();
|
||||||
|
*sys = Some(System::current());
|
||||||
|
|
||||||
|
let rx = signal();
|
||||||
|
let _ = spawn(async move {
|
||||||
|
if let Ok(sig) = rx.await {
|
||||||
|
srv.signal(sig);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if !started {
|
||||||
let _ = thread::Builder::new()
|
let _ = thread::Builder::new()
|
||||||
.name("ntex-server signals".to_string())
|
.name("ntex-server signals".to_string())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
ctrlc::set_handler(move || {
|
ctrlc::set_handler(move || {
|
||||||
srv.signal(Signal::Int);
|
if let Ok(guard) = CUR_SYS.lock() {
|
||||||
|
if let Some(sys) = &*guard.borrow() {
|
||||||
System::current().arbiter().exec_fn(|| {
|
sys.arbiter().exec_fn(|| {
|
||||||
HANDLERS.with(|handlers| {
|
HANDLERS.with(|handlers| {
|
||||||
for tx in handlers.borrow_mut().drain(..) {
|
for tx in handlers.borrow_mut().drain(..) {
|
||||||
let _ = tx.send(Signal::Int);
|
let _ = tx.send(Signal::Int);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.expect("Error setting Ctrl-C handler");
|
.expect("Error setting Ctrl-C handler");
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue