From 818b7cdff418040afe52c157ee1e46d7c1bff451 Mon Sep 17 00:00:00 2001 From: Tamim Hossain <132823494+CodeWithTamim@users.noreply.github.com> Date: Sat, 10 Aug 2024 17:48:53 +0600 Subject: [PATCH] Replace global scope with CoroutineScope for socket operations (#3454) Replaced the use of global scope with CoroutineScope(Dispatchers.IO) in the socket operation function. This change improves coroutine management and ensures proper use of dispatchers for background tasks. The code now properly handles retries with exponential backoff and logs attempts and errors. --- .../src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt index 1f97c2ac..d3f675a6 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt @@ -17,6 +17,7 @@ import com.v2ray.ang.dto.ERoutingMode import com.v2ray.ang.util.MmkvManager import com.v2ray.ang.util.MyContextWrapper import com.v2ray.ang.util.Utils +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -244,7 +245,7 @@ class V2RayVpnService : VpnService(), ServiceControl { val path = File(applicationContext.filesDir, "sock_path").absolutePath Log.d(packageName, path) - GlobalScope.launch(Dispatchers.IO) { + CoroutineScope(Dispatchers.IO).launch { var tries = 0 while (true) try { Thread.sleep(50L shl tries)