diff --git a/src/bin/main.rs b/src/bin/main.rs index 9f1b415..17f13a0 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,4 +1,4 @@ -use tun2proxy::{desktop_run_async, Args, BoxError}; +use tun2proxy::{Args, BoxError}; #[tokio::main] async fn main() -> Result<(), BoxError> { @@ -13,8 +13,8 @@ async fn main() -> Result<(), BoxError> { let join_handle = tokio::spawn({ let shutdown_token = shutdown_token.clone(); async move { - if let Err(err) = desktop_run_async(args, shutdown_token).await { - log::error!("desktop_run_async error: {}", err); + if let Err(err) = tun2proxy::desktop_run_async(args, shutdown_token).await { + log::error!("main loop error: {}", err); } } }); diff --git a/src/desktop_api.rs b/src/desktop_api.rs index 5eda1ee..2756d95 100644 --- a/src/desktop_api.rs +++ b/src/desktop_api.rs @@ -51,9 +51,17 @@ pub unsafe extern "C" fn tun2proxy_run_with_name( args.bypass(bypass.parse().unwrap()); } + let main_loop = async move { + if let Err(err) = desktop_run_async(args, shutdown_token).await { + log::error!("main loop error: {}", err); + return Err(err); + } + Ok(()) + }; + let exit_code = match tokio::runtime::Builder::new_multi_thread().enable_all().build() { Err(_e) => -3, - Ok(rt) => match rt.block_on(desktop_run_async(args, shutdown_token)) { + Ok(rt) => match rt.block_on(main_loop) { Ok(_) => 0, Err(_e) => -4, },