netty: ignore disconnect state when sending packets

This commit is contained in:
Bixilon 2022-05-05 16:56:13 +02:00
parent eb1caf4e2a
commit 44d073e7ad
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -150,7 +150,7 @@ class NettyClient(
}
fun send(packet: C2SPacket) {
val channel = requireChannel()
val channel = getChannel() ?: return
if (sendingPaused) {
packetQueue += packet
return
@ -205,6 +205,14 @@ class NettyClient(
return channel
}
private fun getChannel(): Channel? {
val channel = this.channel
if (!connected || channel == null) {
return null
}
return channel
}
companion object {
private val NIO_THREAD_POOL by lazy { NioEventLoopGroup(NamedThreadFactory("Nio#%d")) }
private val EPOLL_THREAD_POOL by lazy { EpollEventLoopGroup(NamedThreadFactory("Epoll#%d")) }