// They should be called in sequence because packet is lock-free
// They should be called in sequence because packet is lock-free
...
@@ -267,11 +277,12 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
...
@@ -267,11 +277,12 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
return@withContext
return@withContext
}
}
packet.packet.use{build->
packet.buildAndUse{build->
valbuffer=IoBuffer.Pool.borrow()
valbuffer=IoBuffer.Pool.borrow()
try{
try{
build.readAvailable(buffer)
build.readAvailable(buffer)
channel.send(buffer)//JVM: withContext(IO)
valshouldBeSent=buffer.readRemaining
check(channel.send(buffer)==shouldBeSent){"Buffer is not entirely sent. Required sent length=$shouldBeSent, but after channel.send, buffer remains ${buffer.readBytes().toUHexString()}"}//JVM: withContext(IO)