Atomic packet parser

This commit is contained in:
Him188 2020-02-02 16:43:03 +08:00
parent 63a4d5f3b9
commit 26e9f893d7

View File

@ -176,8 +176,9 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
* *
* @param input 一个完整的包的内容, 去掉开头的 int 包长度 * @param input 一个完整的包的内容, 去掉开头的 int 包长度
*/ */
@UseExperimental(ExperimentalCoroutinesApi::class)
fun parsePacketAsync(input: Input): Job { fun parsePacketAsync(input: Input): Job {
return this.launch { return this.launch(start = CoroutineStart.ATOMIC) {
input.use { parsePacket(it) } input.use { parsePacket(it) }
} }
} }
@ -340,13 +341,11 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
bot.tryReinitializeNetworkHandler(e) bot.tryReinitializeNetworkHandler(e)
return return
} }
launch(CoroutineName("Incoming Packet handler"), start = CoroutineStart.ATOMIC) {
packetReceiveLock.withLock { packetReceiveLock.withLock {
processPacket(rawInput) processPacket(rawInput)
} }
} }
} }
}
private val packetReceiveLock: Mutex = Mutex() private val packetReceiveLock: Mutex = Mutex()