From 3e43e296c75e85f31d1a60a997496f155cfbbd38 Mon Sep 17 00:00:00 2001 From: Matthew Nelson Date: Mon, 8 Apr 2024 10:23:08 -0400 Subject: [PATCH] Ignore non-connection errors --- .../io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt | 10 +++------- .../kmp/tor/runtime/ctrl/internal/JsPlatform.kt | 10 ++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt b/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt index 3de8d922a..490f430b2 100644 --- a/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt +++ b/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt @@ -164,13 +164,8 @@ public actual interface TorCtrl : Destroyable, TorEvent.Processor, TorCmd.Privil } fun callback(nread: Int, buf: dynamic) { - val readBuf = try { - val jsBuf = Buffer.wrap(buf) - ReadBuffer.of(jsBuf) - } catch (_: Throwable) { - return - } - + val jsBuf = Buffer.wrap(buf) + val readBuf = ReadBuffer.of(jsBuf) feed.onData(readBuf, nread) } @@ -216,6 +211,7 @@ public actual interface TorCtrl : Destroyable, TorEvent.Processor, TorCmd.Privil threw?.let { throw it } + socket.onError { /* ignore */ } errorDisposable.invoke() socket } diff --git a/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/internal/JsPlatform.kt b/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/internal/JsPlatform.kt index aa9d804ec..0138fb94b 100644 --- a/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/internal/JsPlatform.kt +++ b/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/internal/JsPlatform.kt @@ -18,6 +18,16 @@ package io.matthewnelson.kmp.tor.runtime.ctrl.internal import io.matthewnelson.kmp.process.InternalProcessApi import io.matthewnelson.kmp.tor.runtime.core.Disposable +@OptIn(InternalProcessApi::class) +internal inline fun net_Socket.onError( + noinline listener: (error: dynamic) -> Unit +): Disposable { + on("error", listener) + return Disposable { + removeListener("error", listener) + } +} + @OptIn(InternalProcessApi::class) internal inline fun net_Socket.onceError( noinline listener: (error: dynamic) -> Unit