mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 16:06:30 +00:00
1. more optimization
This commit is contained in:
parent
b48b39d94c
commit
954608b220
@ -67,9 +67,10 @@ 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 {
|
||||||
|
var buffer = ByteArray(2048)
|
||||||
while (true) {
|
while (true) {
|
||||||
try{
|
try{
|
||||||
readPacketsFromTun()
|
readPacketsFromTun(buffer)
|
||||||
} catch (e: IOException){
|
} catch (e: IOException){
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
@ -118,15 +119,14 @@ class YggdrasilTunService : VpnService() {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readPacketsFromTun() {
|
private fun readPacketsFromTun(buffer: ByteArray) {
|
||||||
if(tunInputStream != null) {
|
if(tunInputStream != null) {
|
||||||
var packet = ByteArray(2048)
|
|
||||||
// Read the outgoing packet from the input stream.
|
// Read the outgoing packet from the input stream.
|
||||||
var length = tunInputStream!!.read(packet)
|
var length = tunInputStream!!.read(buffer)
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
var buffer = ByteBuffer.allocate(length);
|
var byteBuffer = ByteBuffer.allocate(length);
|
||||||
buffer.put(packet, 0, length)
|
byteBuffer.put(buffer, 0, length)
|
||||||
yggConduitEndpoint.send(buffer.array())
|
yggConduitEndpoint.send(byteBuffer.array())
|
||||||
} else {
|
} else {
|
||||||
Thread.sleep(10)
|
Thread.sleep(10)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user