Skip to content

Commit ce50b01

Browse files
authored
Fixed the writer thread. (#42)
* Fixed the writer thread. * Version increment. * Added todo and info.
1 parent 05de180 commit ce50b01

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
applicationId "eu.neilalexander.yggdrasil"
1212
minSdkVersion 21
1313
targetSdkVersion 29
14-
versionCode 12
15-
versionName "0.1-012"
14+
versionCode 13
15+
versionName "0.1-013"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}

app/src/main/java/eu/neilalexander/yggdrasil/PacketTunnelProvider.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@ open class PacketTunnelProvider: VpnService() {
282282
val writerStream = writerStream
283283
val writerThread = writerThread
284284
if (writerThread == null || writerStream == null) {
285+
Log.i(TAG, "Write thread or stream is null")
285286
break@writes
286287
}
287288
if (Thread.currentThread().isInterrupted || !writerStream.fd.valid()) {
289+
Log.i(TAG, "Write thread interrupted or file descriptor is invalid")
288290
break@writes
289291
}
290292
try {
@@ -293,6 +295,12 @@ open class PacketTunnelProvider: VpnService() {
293295
writerStream.write(buf, 0, len.toInt())
294296
}
295297
} catch (e: Exception) {
298+
Log.i(TAG, "Error in write: $e")
299+
if (e.toString().contains("ENOBUFS")) {
300+
//TODO Check this by some error code
301+
//More info about this: https://github.com/AdguardTeam/AdguardForAndroid/issues/724
302+
continue
303+
}
296304
break@writes
297305
}
298306
}
@@ -308,15 +316,18 @@ open class PacketTunnelProvider: VpnService() {
308316
val readerStream = readerStream
309317
val readerThread = readerThread
310318
if (readerThread == null || readerStream == null) {
319+
Log.i(TAG, "Read thread or stream is null")
311320
break@reads
312321
}
313322
if (Thread.currentThread().isInterrupted ||!readerStream.fd.valid()) {
323+
Log.i(TAG, "Read thread interrupted or file descriptor is invalid")
314324
break@reads
315325
}
316326
try {
317327
val n = readerStream.read(b)
318328
yggdrasil.sendBuffer(b, n.toLong())
319329
} catch (e: Exception) {
330+
Log.i(TAG, "Error in sendBuffer: $e")
320331
break@reads
321332
}
322333
}

0 commit comments

Comments
 (0)