in ktor-io/jvm/src/io/ktor/utils/io/ByteBufferChannel.kt [1754:1777]
override suspend fun read(min: Int, consumer: (ByteBuffer) -> Unit) {
require(min >= 0) { "min should be positive or zero" }
val read = reading {
val av = it.availableForRead
if (av > 0 && av >= min) {
val position = this.position()
val l = this.limit()
consumer(this)
if (l != this.limit()) throw IllegalStateException("buffer limit modified")
val delta = position() - position
if (delta < 0) throw IllegalStateException("position has been moved backward: pushback is not supported")
if (!it.tryReadExact(delta)) throw IllegalStateException()
bytesRead(it, delta)
true
} else false
}
if (!read) {
if (isClosedForRead) return
return readBlockSuspend(min, consumer)
}
}