Replace flushRequests() with channelReadComplete()

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent 6023569ce0
commit 29ac56fe1e
  1. 25
      archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt

@ -56,6 +56,17 @@ public class Js5ChannelHandler(
} }
} }
override fun channelReadComplete(ctx: ChannelHandlerContext) {
while (inFlightRequests.size < maxInFlightRequests) {
val request = pendingRequests.removeFirstOrNull() ?: break
inFlightRequests += request
ctx.write(request, ctx.voidPromise())
}
ctx.flush()
ctx.read()
}
override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) { override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {
releaseGroups() releaseGroups()
ctx.close() ctx.close()
@ -75,7 +86,6 @@ public class Js5ChannelHandler(
val request = Js5Request.Group(false, Js5Archive.ARCHIVESET, Js5Archive.ARCHIVESET) val request = Js5Request.Group(false, Js5Archive.ARCHIVESET, Js5Archive.ARCHIVESET)
pendingRequests += request pendingRequests += request
flushRequests(ctx)
} }
private fun handleClientOutOfDate(ctx: ChannelHandlerContext) { private fun handleClientOutOfDate(ctx: ChannelHandlerContext) {
@ -118,8 +128,6 @@ public class Js5ChannelHandler(
if (complete) { if (complete) {
ctx.close() ctx.close()
continuation.resume(Unit) continuation.resume(Unit)
} else {
flushRequests(ctx)
} }
} }
@ -158,17 +166,6 @@ public class Js5ChannelHandler(
} }
} }
private fun flushRequests(ctx: ChannelHandlerContext) {
while (inFlightRequests.size < maxInFlightRequests) {
val request = pendingRequests.removeFirstOrNull() ?: break
inFlightRequests += request
ctx.write(request, ctx.voidPromise())
}
ctx.flush()
ctx.read()
}
private fun releaseGroups() { private fun releaseGroups() {
groups.forEach(CacheImporter.Group::release) groups.forEach(CacheImporter.Group::release)
groups.clear() groups.clear()

Loading…
Cancel
Save