Skip to content

Commit

Permalink
Ignore non-connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm committed Apr 8, 2024
1 parent 24f328e commit 3e43e29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -216,6 +211,7 @@ public actual interface TorCtrl : Destroyable, TorEvent.Processor, TorCmd.Privil

threw?.let { throw it }

socket.onError { /* ignore */ }
errorDisposable.invoke()
socket
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e43e29

Please sign in to comment.