mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-09 20:11:01 +00:00
1. moved to blocking IO mode
This commit is contained in:
parent
0719c674b8
commit
f7c4e70dd6
@ -70,6 +70,7 @@ class YggdrasilTunService : VpnService() {
|
||||
.addAddress(address, 7)
|
||||
.allowFamily(OsConstants.AF_INET)
|
||||
.setMtu(MAX_PACKET_SIZE)
|
||||
.setBlocking(true)
|
||||
if (dns.size > 0) {
|
||||
builder.addDnsServer(address)
|
||||
for (d in dns) {
|
||||
@ -159,17 +160,12 @@ class YggdrasilTunService : VpnService() {
|
||||
}
|
||||
|
||||
private fun readPacketsFromTun(yggConduitEndpoint: ConduitEndpoint, buffer: ByteArray) {
|
||||
if (tunInputStream == null) return
|
||||
try {
|
||||
// Read the outgoing packet from the input stream.
|
||||
try{
|
||||
val length = tunInputStream!!.read(buffer)
|
||||
if (length > 0) {
|
||||
val byteBuffer = ByteBuffer.allocate(length)
|
||||
byteBuffer.put(buffer, 0, length)
|
||||
yggConduitEndpoint.send(byteBuffer.array())
|
||||
} else {
|
||||
Thread.sleep(10)
|
||||
}
|
||||
}catch(e: IOException){
|
||||
val length = tunInputStream?.read(buffer) ?: 1
|
||||
yggConduitEndpoint.send(buffer.sliceArray(IntRange(0, length - 1)))
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user