From 445683b87ee7aa33e8a5af29c35280ebdbb45a39 Mon Sep 17 00:00:00 2001 From: vadym Date: Wed, 5 Aug 2020 14:25:14 -0700 Subject: [PATCH] 1. buffered read fix --- .../io/github/chronosx88/yggdrasil/YggdrasilTunService.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt index 60af9df..97adb9e 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt @@ -215,8 +215,10 @@ class YggdrasilTunService : VpnService() { private fun readPacketsFromTun(yggConduitEndpoint: ConduitEndpoint, buffer: ByteArray) { try { // Read the outgoing packet from the input stream. - val length = tunInputStream.read(buffer) - yggConduitEndpoint.send(buffer.sliceArray(IntRange(0, length - 1))) + val length = tunInputStream.buffered().read(buffer) + if(length>0) { + yggConduitEndpoint.send(buffer.sliceArray(IntRange(0, length - 1))) + } } catch (e: IOException) { e.printStackTrace() }