Skip to content

Commit

Permalink
Temporary fix ktor TCP implementation because of bug?
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg committed Dec 1, 2024
1 parent 20e9834 commit a2feb99
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,21 @@ private class KtorTcpConnection(
}
}

@OptIn(InternalAPI::class) // TODO?
@OptIn(InternalAPI::class)
private fun ByteWriteChannel.writeFrame(frame: Buffer) {
writeBuffer.writeInt24(frame.size.toInt())
writeBuffer.transferFrom(frame)
}

@OptIn(InternalAPI::class) // TODO?
@OptIn(InternalAPI::class)
private suspend fun ByteReadChannel.readFrame(): Buffer? {
while (availableForRead < 3 && awaitContent(3)) yield()
if (availableForRead == 0) return null

val length = readBuffer.readInt24()
// TODO: replace after ktor 3.0.2: https://youtrack.jetbrains.com/issue/KTOR-7746
val length = readBuffer(3).also {
if (it.exhausted()) return null
}.readInt24()
// while (availableForRead < 3 && awaitContent(3)) yield()
// if (availableForRead == 0) return null
// val length = readBuffer.readInt24()
return readBuffer(length).also {
it.require(length.toLong())
}
Expand Down

0 comments on commit a2feb99

Please sign in to comment.