[core] Add net.mamoe.mirai.utils.Closeable for MPP use

This commit is contained in:
Him188 2022-09-23 21:24:19 +08:00
parent b360f58c2b
commit 9122dddfb7
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
7 changed files with 54 additions and 3 deletions

View File

@ -120,7 +120,8 @@ import kotlin.jvm.JvmStatic
*
* @see FileCacheStrategy
*/
public expect interface ExternalResource : Closeable {
@Suppress("RemoveRedundantQualifierName")
public expect interface ExternalResource : net.mamoe.mirai.utils.Closeable {
/**
* 是否在 _使用一次_ 后自动 [close].

View File

@ -0,0 +1,20 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils
import io.ktor.utils.io.errors.*
public expect interface Closeable {
@Throws(IOException::class)
public fun close()
}
public expect fun Closeable.asKtorCloseable(): io.ktor.utils.io.core.Closeable
public expect fun io.ktor.utils.io.core.Closeable.asMiraiCloseable(): io.ktor.utils.io.core.Closeable

View File

@ -0,0 +1,15 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils
public actual typealias Closeable = java.io.Closeable
public actual fun Closeable.asKtorCloseable(): io.ktor.utils.io.core.Closeable = this
public actual fun io.ktor.utils.io.core.Closeable.asMiraiCloseable(): io.ktor.utils.io.core.Closeable = this

View File

@ -0,0 +1,15 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils
public actual typealias Closeable = io.ktor.utils.io.core.Closeable
public actual fun Closeable.asKtorCloseable(): io.ktor.utils.io.core.Closeable = this
public actual fun io.ktor.utils.io.core.Closeable.asMiraiCloseable(): io.ktor.utils.io.core.Closeable = this

View File

@ -9,12 +9,10 @@
package net.mamoe.mirai.internal.pipeline
import io.ktor.utils.io.core.*
import net.mamoe.mirai.internal.message.contextualBugReportException
import net.mamoe.mirai.internal.message.protocol.outgoing.OutgoingMessagePipelineContext
import net.mamoe.mirai.internal.network.components.NoticeProcessor
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.structureToStringAndDesensitizeIfAvailable
import kotlin.jvm.JvmInline
internal interface Processor<C : ProcessorPipelineContext<D, *>, D> : PipelineConsumptionMarker {

View File

@ -11,6 +11,7 @@ package net.mamoe.mirai.internal.network.handler
import io.ktor.utils.io.core.*
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.Closeable
private val debugLogger: MiraiLogger by lazy {
MiraiLogger.Factory.create(

View File

@ -18,6 +18,7 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import net.mamoe.mirai.internal.network.highway.HighwayProtocolChannel
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.Closeable
import platform.posix.close
import platform.posix.errno
import platform.posix.recv