mirror of
https://github.com/mamoe/mirai.git
synced 2024-12-29 10:00:13 +08:00
[core] Add net.mamoe.mirai.utils.Closeable
for MPP use
This commit is contained in:
parent
b360f58c2b
commit
9122dddfb7
@ -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].
|
||||
|
20
mirai-core-utils/src/commonMain/kotlin/Closeable.kt
Normal file
20
mirai-core-utils/src/commonMain/kotlin/Closeable.kt
Normal 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
|
15
mirai-core-utils/src/jvmBaseMain/kotlin/Closeable.kt
Normal file
15
mirai-core-utils/src/jvmBaseMain/kotlin/Closeable.kt
Normal 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
|
15
mirai-core-utils/src/nativeMain/kotlin/Closeable.kt
Normal file
15
mirai-core-utils/src/nativeMain/kotlin/Closeable.kt
Normal 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
|
@ -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 {
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user