mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-10 04:00:08 +08:00
Add writeAndFlushOrCloseAsync to handle exception on send properly
This commit is contained in:
parent
d755ebf7ee
commit
060004644e
@ -244,7 +244,7 @@ internal open class NettyNetworkHandler(
|
||||
|
||||
override suspend fun sendPacketImpl(packet: OutgoingPacket): Boolean {
|
||||
connection.await() // split line number
|
||||
.writeAndFlush(packet)
|
||||
.writeAndFlushOrCloseAsync(packet)
|
||||
return true
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ internal open class NettyNetworkHandler(
|
||||
}
|
||||
|
||||
override suspend fun sendPacketImpl(packet: OutgoingPacket): Boolean {
|
||||
connection.writeAndFlush(packet)
|
||||
connection.writeAndFlushOrCloseAsync(packet)
|
||||
return true
|
||||
}
|
||||
|
||||
@ -357,7 +357,7 @@ internal open class NettyNetworkHandler(
|
||||
}
|
||||
|
||||
override suspend fun sendPacketImpl(packet: OutgoingPacket): Boolean {
|
||||
connection.writeAndFlush(packet)
|
||||
connection.writeAndFlushOrCloseAsync(packet)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@ package net.mamoe.mirai.internal.network.impl.netty
|
||||
import io.netty.buffer.ByteBuf
|
||||
import io.netty.buffer.ByteBufInputStream
|
||||
import io.netty.channel.ChannelFuture
|
||||
import io.netty.channel.ChannelFutureListener
|
||||
import io.netty.channel.ChannelOutboundInvoker
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.Job
|
||||
@ -57,6 +59,12 @@ internal fun MiraiLogger.asCoroutineExceptionHandler(
|
||||
}
|
||||
}
|
||||
|
||||
internal fun ChannelOutboundInvoker.writeAndFlushOrCloseAsync(msg: Any?): ChannelFuture? {
|
||||
return writeAndFlush(msg)
|
||||
.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
.addListener(ChannelFutureListener.CLOSE_ON_FAILURE)
|
||||
}
|
||||
|
||||
|
||||
internal suspend inline fun joinCompleted(job: Job) {
|
||||
if (job.isCompleted) job.join()
|
||||
|
Loading…
Reference in New Issue
Block a user