Skip to content

Commit f861ba2

Browse files
authored
update ktor (fix linux curl engine issue) (#15)
* update ktor (fix linux curl engine issue) * update test case * update version code
1 parent 897ce2d commit f861ba2

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object Consts {
22
const val releaseGroup = "com.piasy"
33
const val releaseName = "kmp-socketio"
4-
const val releaseVersion = "1.3.0"
4+
const val releaseVersion = "1.3.1"
55

66
val androidNS = "$releaseGroup.${releaseName.replace('-', '.')}"
77
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ targetSdk = "35"
77
agp = "8.7.3"
88
kotlin = "2.1.10"
99
mockk = "1.13.16"
10-
ktor = "3.1.0"
10+
ktor = "3.2.2"
1111
coroutine = "1.10.1"
1212
compose = "1.7.8"
1313

kmp-socketio/src/commonMain/kotlin/com/piasy/kmp/socketio/engineio/transports/transport.kt

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,8 @@ class DefaultHttpClientFactory(
7979
}
8080
// Linux curl engine doesn't work for simultaneous websocket and http request.
8181
// see https://youtrack.jetbrains.com/issue/KTOR-8259/
82-
// Use two http client could work around it.
83-
private val httpClient: HttpClient = if (!Platform.isLinux) wsClient else httpClient(
84-
trustAllCerts = trustAllCerts,
85-
) {
86-
install(Logging) {
87-
logger = object : Logger {
88-
override fun log(message: String) {
89-
com.piasy.kmp.xlog.Logging.info("Net", message)
90-
}
91-
}
92-
level = LogLevel.ALL
93-
}
94-
install(WebSockets) {
95-
pingIntervalMillis = 20_000
96-
}
97-
}
82+
// But it's fixed in 3.2.0.
83+
private val httpClient: HttpClient = wsClient
9884

9985
override suspend fun createWs(
10086
url: String,

kmp-socketio/src/linuxTest/kotlin/com/piasy/kmp/socketio/socketio/ConnectionTestLinux.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ConnectionTestLinux : ConnectionTest() {
9292
}
9393

9494
@Test
95-
fun `simultaneous ws and http request with a single http client will hang`() = doTest {
95+
fun `simultaneous ws and http request with a single http client will also work`() = doTest {
9696
val config: HttpClientConfig<*>.() -> Unit = {
9797
install(io.ktor.client.plugins.logging.Logging) {
9898
logger = object : Logger {
@@ -110,7 +110,9 @@ class ConnectionTestLinux : ConnectionTest() {
110110
config(this)
111111
}
112112

113-
assertFailsWith<TimeoutCancellationException> {
113+
var pollRes = ""
114+
// ktor 3.2.0 fix the problem
115+
//assertFailsWith<TimeoutCancellationException> {
114116
withContext(Dispatchers.Default) {
115117
withTimeout(5000) {
116118
client.webSocket("ws://localhost:3000/socket.io/?EIO=4&transport=websocket", {}) {
@@ -126,8 +128,8 @@ class ConnectionTestLinux : ConnectionTest() {
126128
}
127129
Logging.info(TAG, "http response status: ${resp.status}")
128130
if (resp.status.isSuccess()) {
129-
val body = resp.bodyAsText()
130-
Logging.info(TAG, "http response body: $body")
131+
pollRes = resp.bodyAsText()
132+
Logging.info(TAG, "http response body: $pollRes")
131133
break
132134
}
133135
} catch (e: Exception) {
@@ -138,6 +140,9 @@ class ConnectionTestLinux : ConnectionTest() {
138140
}
139141
}
140142
}
141-
}
143+
//}
144+
145+
val pkt = EngineIO.decodeHttpBatch(pollRes, SocketIO::decode)[0]
146+
assertTrue(pkt is EngineIOPacket.Open)
142147
}
143148
}

0 commit comments

Comments
 (0)