socks5-client: graceful shutdown

This commit is contained in:
Jon Häggblad
2022-09-06 12:46:24 +02:00
parent 634818a988
commit 10be112279
38 changed files with 580 additions and 187 deletions
+1 -29
View File
@@ -26,7 +26,7 @@ use rand::thread_rng;
use std::net::SocketAddr;
use std::process;
use std::sync::Arc;
use task::{ShutdownListener, ShutdownNotifier};
use task::{wait_for_signal, ShutdownListener, ShutdownNotifier};
use version_checker::parse_version;
mod http;
@@ -334,31 +334,3 @@ impl MixNode {
self.wait_for_interrupt(shutdown).await
}
}
#[cfg(unix)]
async fn wait_for_signal() {
use tokio::signal::unix::{signal, SignalKind};
let mut sigterm = signal(SignalKind::terminate()).expect("Failed to setup SIGTERM channel");
let mut sigquit = signal(SignalKind::quit()).expect("Failed to setup SIGQUIT channel");
tokio::select! {
_ = tokio::signal::ctrl_c() => {
log::info!("Received SIGINT");
},
_ = sigterm.recv() => {
log::info!("Received SIGTERM");
}
_ = sigquit.recv() => {
log::info!("Received SIGQUIT");
}
}
}
#[cfg(not(unix))]
async fn wait_for_signal() {
tokio::select! {
_ = tokio::signal::ctrl_c() => {
log::info!("Received SIGINT");
},
}
}