Skip flush/read calls if no writes are made

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent e0a9bc3ca6
commit 0f939935cd
  1. 6
      archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt

@ -57,15 +57,21 @@ public class Js5ChannelHandler(
} }
override fun channelReadComplete(ctx: ChannelHandlerContext) { override fun channelReadComplete(ctx: ChannelHandlerContext) {
var flush = false
while (inFlightRequests.size < maxInFlightRequests) { while (inFlightRequests.size < maxInFlightRequests) {
val request = pendingRequests.removeFirstOrNull() ?: break val request = pendingRequests.removeFirstOrNull() ?: break
inFlightRequests += request inFlightRequests += request
ctx.write(request, ctx.voidPromise()) ctx.write(request, ctx.voidPromise())
flush = true
} }
if (flush) {
ctx.flush() ctx.flush()
ctx.read() ctx.read()
} }
}
override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) { override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {
releaseGroups() releaseGroups()

Loading…
Cancel
Save