From 17093a84588b939665989ed15ee165cbe39d2361 Mon Sep 17 00:00:00 2001 From: lisonge Date: Wed, 22 Nov 2023 17:14:02 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BD=BF=E7=94=A8=20cio=20=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=20netty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/li/songe/gkd/debug/HttpService.kt | 10 +++++----- settings.gradle.kts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/li/songe/gkd/debug/HttpService.kt b/app/src/main/java/li/songe/gkd/debug/HttpService.kt index a7878a7..911654d 100644 --- a/app/src/main/java/li/songe/gkd/debug/HttpService.kt +++ b/app/src/main/java/li/songe/gkd/debug/HttpService.kt @@ -8,9 +8,9 @@ import io.ktor.http.CacheControl import io.ktor.serialization.kotlinx.json.json import io.ktor.server.application.call import io.ktor.server.application.install +import io.ktor.server.cio.CIO +import io.ktor.server.cio.CIOApplicationEngine import io.ktor.server.engine.embeddedServer -import io.ktor.server.netty.Netty -import io.ktor.server.netty.NettyApplicationEngine import io.ktor.server.plugins.contentnegotiation.ContentNegotiation import io.ktor.server.request.receive import io.ktor.server.request.receiveText @@ -63,8 +63,8 @@ class HttpService : CompositionService({ ) val httpSubsRawFlow = MutableStateFlow(null) - fun createServer(port: Int): NettyApplicationEngine { - return embeddedServer(Netty, port, configure = { tcpKeepAlive = true }) { + fun createServer(port: Int): CIOApplicationEngine { + return embeddedServer(CIO, port) { install(KtorCorsPlugin) install(KtorErrorPlugin) install(ContentNegotiation) { json(keepNullJson) } @@ -129,7 +129,7 @@ class HttpService : CompositionService({ } } - var server: NettyApplicationEngine? = null + var server: CIOApplicationEngine? = null scope.launchTry(Dispatchers.IO) { storeFlow.map(scope) { s -> s.httpServerPort }.collect { port -> server?.stop() diff --git a/settings.gradle.kts b/settings.gradle.kts index c7d545d..02d408a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -136,10 +136,10 @@ dependencyResolutionManagement { library("junit", "junit:junit:4.13.2") - val ktorVersion = "2.3.5" + val ktorVersion = "2.3.6" // 请注意,当 client 和 server 版本不一致时, 会报错 socket hang up library("ktor.server.core", "io.ktor:ktor-server-core:$ktorVersion") - library("ktor.server.netty", "io.ktor:ktor-server-netty:$ktorVersion") + library("ktor.server.cio", "io.ktor:ktor-server-cio:$ktorVersion") library("ktor.server.cors", "io.ktor:ktor-server-cors:$ktorVersion") library( "ktor.server.content.negotiation", "io.ktor:ktor-server-content-negotiation:$ktorVersion"