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)
|
.addAddress(address, 7)
|
||||||
.allowFamily(OsConstants.AF_INET)
|
.allowFamily(OsConstants.AF_INET)
|
||||||
.setMtu(MAX_PACKET_SIZE)
|
.setMtu(MAX_PACKET_SIZE)
|
||||||
|
.setBlocking(true)
|
||||||
if (dns.size > 0) {
|
if (dns.size > 0) {
|
||||||
builder.addDnsServer(address)
|
builder.addDnsServer(address)
|
||||||
for (d in dns) {
|
for (d in dns) {
|
||||||
@ -159,17 +160,12 @@ class YggdrasilTunService : VpnService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun readPacketsFromTun(yggConduitEndpoint: ConduitEndpoint, buffer: ByteArray) {
|
private fun readPacketsFromTun(yggConduitEndpoint: ConduitEndpoint, buffer: ByteArray) {
|
||||||
// Read the outgoing packet from the input stream.
|
if (tunInputStream == null) return
|
||||||
try{
|
try {
|
||||||
val length = tunInputStream!!.read(buffer)
|
// Read the outgoing packet from the input stream.
|
||||||
if (length > 0) {
|
val length = tunInputStream?.read(buffer) ?: 1
|
||||||
val byteBuffer = ByteBuffer.allocate(length)
|
yggConduitEndpoint.send(buffer.sliceArray(IntRange(0, length - 1)))
|
||||||
byteBuffer.put(buffer, 0, length)
|
} catch (e: IOException) {
|
||||||
yggConduitEndpoint.send(byteBuffer.array())
|
|
||||||
} else {
|
|
||||||
Thread.sleep(10)
|
|
||||||
}
|
|
||||||
}catch(e: IOException){
|
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user