From 685b2a7fb974e824d3498601bdbe16224b9337fc Mon Sep 17 00:00:00 2001 From: alterdekim Date: Sun, 13 Oct 2024 20:56:28 +0300 Subject: [PATCH] modified: src/client.rs --- src/client.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index 8492f02..f2ee3d4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -27,6 +27,8 @@ use crate::jni::FridaLib; pub async fn client_mode(client_config: ClientConfiguration, fd: i32, close_token: CancellationToken) { info!("Starting client..."); + let subtasks_quit: std::sync::Mutex = std::sync::Mutex::new(tokio_util::sync::CancellationToken::new()); + let sock = UdpSocket::bind("0.0.0.0:25565").await.unwrap(); sock.connect(&client_config.server.endpoint).await.unwrap(); @@ -49,7 +51,7 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, close_toke let mut buf = vec![0; 1400]; // mtu loop { tokio::select! { - _ = cancel_dr.cancelled() => { + _ = subtasks_quit.lock().cancelled() => { info!("Cancellation token has been thrown dev_read_task"); return; } @@ -72,7 +74,7 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, close_toke loop { tokio::select! { - _ = cancel_sr.cancelled() => { + _ = subtasks_quit.lock().cancelled() => { info!("Cancellation token has been thrown sock_read_task"); return; } @@ -136,6 +138,9 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, close_toke tokio::select! { _ = close_token.cancelled() => { info!("Cancellation token has been thrown"); + if let Ok(mut l) = subtasks_quit.lock() { + l.cancel(); + } dev_read_task.await; sock_read_task.await; return;