1. fixes possible IOxeption crash

This commit is contained in:
vadym 2020-06-13 04:21:35 -07:00
parent fbc59cd863
commit 8890858011

View File

@ -14,10 +14,7 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import mobile.Mobile import mobile.Mobile
import mobile.Yggdrasil import mobile.Yggdrasil
import java.io.FileInputStream import java.io.*
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.nio.ByteBuffer import java.nio.ByteBuffer
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -75,9 +72,12 @@ class YggdrasilTunService : VpnService() {
tunInputStream = FileInputStream(tunInterface!!.fileDescriptor) tunInputStream = FileInputStream(tunInterface!!.fileDescriptor)
tunOutputStream = FileOutputStream(tunInterface!!.fileDescriptor) tunOutputStream = FileOutputStream(tunInterface!!.fileDescriptor)
readCoroutine = GlobalScope.launch { readCoroutine = GlobalScope.launch {
// FIXME it will throw exception (bad file descriptor) when coroutine will be canceled
while (true) { while (true) {
readPacketsFromTun() try{
readPacketsFromTun()
} catch (e: IOException){
e.printStackTrace()
}
} }
} }
writeCoroutine = GlobalScope.launch { writeCoroutine = GlobalScope.launch {