diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt index c5f1edb54..d679b0c9d 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt @@ -11,6 +11,7 @@ import net.mamoe.mirai.network.protocol.tim.packet.Packet import net.mamoe.mirai.network.protocol.tim.packet.login.HeartbeatPacket import net.mamoe.mirai.network.protocol.tim.packet.login.LoginResult import net.mamoe.mirai.network.protocol.tim.packet.login.RequestSKeyPacket +import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.io.PlatformDatagramChannel /** @@ -52,6 +53,7 @@ interface BotNetworkHandler : CoroutineScope { * @see [BotSession.sendAndExpectAsync] 发送并期待一个包 * @see [TemporaryPacketHandler] 临时包处理器 */ + @MiraiInternalAPI suspend fun addHandler(temporaryPacketHandler: TemporaryPacketHandler<*, *>) /** @@ -67,7 +69,7 @@ interface BotNetworkHandler : CoroutineScope { /** * 关闭网络接口, 停止所有有关协程和任务 */ - suspend fun close(cause: Throwable? = null) { + fun close(cause: Throwable? = null) { supervisor.cancel(CancellationException("handler closed", cause)) } } \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt index fd03bf8be..9dd501806 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt @@ -101,16 +101,14 @@ internal class TIMBotNetworkHandler internal constructor(coroutineContext: Corou heartbeatJob?.join() } - override suspend fun close(cause: Throwable?) { + override fun close(cause: Throwable?) { super.close(cause) this.heartbeatJob?.cancel(CancellationException("handler closed")) - this.heartbeatJob?.join()//等待 cancel 完成 this.heartbeatJob = null if (!this.loginResult.isCompleted && !this.loginResult.isCancelled) { this.loginResult.cancel(CancellationException("socket closed")) - this.loginResult.join() } this.socket.close()