Kotlin/Native 无法导入 io.ktor.network.selector.ActorSelectorManager

Kotlin/Native can't import io.ktor.network.selector.ActorSelectorManager

我想使用 KTOR 在 Kotlin/Native 中使用 TCP 套接字,我遵循了相应的 tutorial。但不知何故我无法从 io.ktor.network.selector 导入 ActorSelectorManager 并获得 Unresolved reference: ActorSelectorManager

我的 build.gradle.kts 看起来像这样:

plugins {
    kotlin("multiplatform") version "1.4.32"
    kotlin("plugin.serialization") version "1.4.32"
}
repositories {
    mavenCentral()
    jcenter()
    maven { url = uri("https://plugins.gradle.org/m2/") }
    maven { url = uri("http://dl.bintray.com/kotlin/kotlin-dev") }
    maven { url = uri("https://kotlin.bintray.com/kotlinx") }
}

kotlin {
    val hostOs = System.getProperty("os.name")
    val isMingwX64 = hostOs.startsWith("Windows")
    val target = when {
        hostOs == "Mac OS X" -> macosX64("SocketStuff")
        hostOs == "Linux" -> linuxX64("SocketStuff")
        isMingwX64 -> mingwX64("SocketStuff")
        else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
    }

    target.apply {
        binaries {
            executable {
                entryPoint = "main"
            }
        }
    }

    sourceSets {
        val Main by getting
        val Test by getting
        commonMain {
            sourceSets["commonMain"].dependencies {
                implementation("io.ktor:ktor-network:1.5.3")
            }
        }
    }
}

有谁知道我是不是忘了添加依赖什么的?

在 JVM 上有 ActorSelectorManager,在本机目标上有 WorkerSelectorManager。您可以使用构造函数 SelectorManager() 来实例化适当的选择器管理器实例:

import io.ktor.network.selector.*

fun main() {
    val manager = SelectorManager()
}