Skip to content

Commit

Permalink
Use fallback read buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm committed Apr 8, 2024
1 parent 3e43e29 commit 22497f8
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,22 @@ public actual interface TorCtrl : Destroyable, TorEvent.Processor, TorCmd.Privil
}
}

val rBuf = ReadBuffer.allocate()

fun callback(nread: Int, buf: dynamic) {
val jsBuf = Buffer.wrap(buf)
val readBuf = ReadBuffer.of(jsBuf)
val readBuf = try {
val jsBuf = Buffer.wrap(buf)
ReadBuffer.of(jsBuf)
} catch (_: Throwable) {
rBuf
}

feed.onData(readBuf, nread)
}

val buf = ReadBuffer.allocate()

run {
val onReadOptions = js("{}")
onReadOptions["buffer"] = buf.buf.unwrap()
onReadOptions["buffer"] = rBuf.buf.unwrap()
onReadOptions["callback"] = ::callback

options["onread"] = onReadOptions
Expand All @@ -192,7 +197,7 @@ public actual interface TorCtrl : Destroyable, TorEvent.Processor, TorCmd.Privil
threw = IOException("$error")
}

socket.onceClose { feed.close(); buf.buf.fill() }
socket.onceClose { feed.close(); rBuf.buf.fill() }

withContext(NonCancellable) {
val mark = TimeSource.Monotonic.markNow()
Expand Down

0 comments on commit 22497f8

Please sign in to comment.