mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-15 13:00:12 +08:00
Atomic packet parser
This commit is contained in:
parent
63a4d5f3b9
commit
26e9f893d7
@ -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()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user