Skip to content

Commit

Permalink
feat(smol): use async_signal instead of signal_hook_async_std
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed Jul 3, 2024
1 parent 21ce66d commit 31e6749
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion smol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trillium-server-common = { path = "../server-common", version = "0.5.2" }

[target.'cfg(unix)'.dependencies]
signal-hook = "0.3.17"
signal-hook-async-std = "0.2.2"
async-signal = "0.2.8"

[dev-dependencies]
env_logger = "0.11.0"
Expand Down
14 changes: 6 additions & 8 deletions smol/src/server/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ impl Server for SmolServer {

fn handle_signals(stop: Stopper) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> {
Box::pin(async move {
use signal_hook::consts::signal::*;
use signal_hook_async_std::Signals;

let signals = Signals::new([SIGINT, SIGTERM, SIGQUIT]).unwrap();
let mut signals = signals.fuse();
while signals.next().await.is_some() {
use async_signal::{Signal, Signals};
let mut signals = Signals::new([Signal::Int, Signal::Term, Signal::Quit]).unwrap();
while let Some(signal) = signals.next().await {
if stop.is_stopped() {
eprintln!("\nSecond interrupt, shutting down harshly");
std::process::exit(1);
eprintln!("\nSecond signal ({signal:?}), shutting down harshly");
signal_hook::low_level::emulate_default_handler(signal.unwrap() as i32)
.unwrap();
} else {
println!("\nShutting down gracefully.\nControl-C again to force.");
stop.stop();
Expand Down

0 comments on commit 31e6749

Please sign in to comment.