mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-22 14:59:09 +00:00
refine TUN_QUIT
This commit is contained in:
parent
a317a3fc9e
commit
5514da71f9
1 changed files with 8 additions and 9 deletions
17
src/api.rs
17
src/api.rs
|
@ -7,16 +7,15 @@ use tokio_util::sync::CancellationToken;
|
||||||
static TUN_QUIT: Mutex<Option<CancellationToken>> = Mutex::new(None);
|
static TUN_QUIT: Mutex<Option<CancellationToken>> = Mutex::new(None);
|
||||||
|
|
||||||
pub(crate) fn tun2proxy_internal_run(args: Args, tun_mtu: u16) -> c_int {
|
pub(crate) fn tun2proxy_internal_run(args: Args, tun_mtu: u16) -> c_int {
|
||||||
let mut lock = TUN_QUIT.lock().unwrap();
|
|
||||||
if lock.is_some() {
|
|
||||||
log::error!("tun2proxy already started");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let shutdown_token = CancellationToken::new();
|
let shutdown_token = CancellationToken::new();
|
||||||
*lock = Some(shutdown_token.clone());
|
{
|
||||||
// explicit drop to avoid holding mutex lock while running proxy.
|
let mut lock = TUN_QUIT.lock().unwrap();
|
||||||
drop(lock);
|
if lock.is_some() {
|
||||||
|
log::error!("tun2proxy already started");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*lock = Some(shutdown_token.clone());
|
||||||
|
}
|
||||||
|
|
||||||
let block = async move {
|
let block = async move {
|
||||||
log::info!("Proxy {} server: {}", args.proxy.proxy_type, args.proxy.addr);
|
log::info!("Proxy {} server: {}", args.proxy.proxy_type, args.proxy.addr);
|
||||||
|
|
Loading…
Add table
Reference in a new issue