mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-18 15:15:22 +00:00
use ctrlc2 async feature
Some checks failed
Push or PR / build_n_test (macos-latest) (push) Has been cancelled
Push or PR / build_n_test (ubuntu-latest) (push) Has been cancelled
Push or PR / build_n_test (windows-latest) (push) Has been cancelled
Push or PR / build_n_test_android (push) Has been cancelled
Push or PR / build_n_test_ios (push) Has been cancelled
Push or PR / Check semver (push) Has been cancelled
Integration Tests / Proxy Tests (push) Has been cancelled
Some checks failed
Push or PR / build_n_test (macos-latest) (push) Has been cancelled
Push or PR / build_n_test (ubuntu-latest) (push) Has been cancelled
Push or PR / build_n_test (windows-latest) (push) Has been cancelled
Push or PR / build_n_test_android (push) Has been cancelled
Push or PR / build_n_test_ios (push) Has been cancelled
Push or PR / Check semver (push) Has been cancelled
Integration Tests / Proxy Tests (push) Has been cancelled
This commit is contained in:
parent
8b4ecabd8f
commit
1880396822
3 changed files with 9 additions and 9 deletions
|
@ -31,7 +31,7 @@ async-trait = "0.1"
|
|||
base64easy = "0.1"
|
||||
chrono = "0.4"
|
||||
clap = { version = "4", features = ["derive", "wrap_help", "color"] }
|
||||
ctrlc2 = { version = "3", features = ["tokio", "termination"] }
|
||||
ctrlc2 = { version = "3.6.5", features = ["async", "termination"] }
|
||||
digest_auth = "0.3"
|
||||
dotenvy = "0.15"
|
||||
env_logger = "0.11"
|
||||
|
|
|
@ -64,18 +64,18 @@ async fn main_async(args: Args) -> Result<(), BoxError> {
|
|||
|
||||
let ctrlc_fired = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
let ctrlc_fired_clone = ctrlc_fired.clone();
|
||||
let ctrlc_handel = ctrlc2::set_async_handler(async move {
|
||||
let ctrlc_handel = ctrlc2::AsyncCtrlC::new(move || {
|
||||
log::info!("Ctrl-C received, exiting...");
|
||||
ctrlc_fired_clone.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
shutdown_token.cancel();
|
||||
})
|
||||
.await;
|
||||
true
|
||||
})?;
|
||||
|
||||
let tasks = main_loop_handle.await??;
|
||||
|
||||
if ctrlc_fired.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
log::info!("Ctrl-C fired, waiting the handler to finish...");
|
||||
ctrlc_handel.await.map_err(|err| err.to_string())?;
|
||||
ctrlc_handel.await?;
|
||||
}
|
||||
|
||||
if args.exit_on_fatal_error && tasks >= args.max_sessions {
|
||||
|
|
|
@ -205,18 +205,18 @@ async fn main_async(args: UdpGwArgs) -> Result<(), BoxError> {
|
|||
|
||||
let ctrlc_fired = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
let ctrlc_fired_clone = ctrlc_fired.clone();
|
||||
let ctrlc_handel = ctrlc2::set_async_handler(async move {
|
||||
let ctrlc_handel = ctrlc2::AsyncCtrlC::new(move || {
|
||||
log::info!("Ctrl-C received, exiting...");
|
||||
ctrlc_fired_clone.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
shutdown_token.cancel();
|
||||
})
|
||||
.await;
|
||||
true
|
||||
})?;
|
||||
|
||||
let _ = main_loop_handle.await?;
|
||||
|
||||
if ctrlc_fired.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
log::info!("Ctrl-C fired, waiting the handler to finish...");
|
||||
ctrlc_handel.await.map_err(|err| err.to_string())?;
|
||||
ctrlc_handel.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue