Skip to content

Commit ff0729f

Browse files
Start gcdWebServer in background mode, fixing ui tests
1 parent 5a45485 commit ff0729f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

library/src/iOSMain/kotlin/actual.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,27 @@ actual fun Data.asString(): String {
2121
@Suppress("UNCHECKED_CAST")
2222
actual class HttpServer actual constructor() {
2323
private val httpServer = GCDWebServer()
24+
2425
actual fun start(port: Int) {
25-
httpServer.startWithPort(port.toULong(), null)
26+
memScoped {
27+
val errorRef = alloc<ObjCObjectVar<NSError?>>()
28+
val started = httpServer.startWithOptions(
29+
mapOf(
30+
GCDWebServerOption_BindToLocalhost to true,
31+
GCDWebServerOption_AutomaticallySuspendInBackground to false,
32+
GCDWebServerOption_Port to port.toULong()
33+
),
34+
errorRef.ptr
35+
)
36+
37+
if (errorRef.value != null) {
38+
throw RuntimeException("Failed to start GCDWebServer on port $port, reason:" +
39+
errorRef.value!!.localizedDescription)
40+
}
41+
if (!started) {
42+
throw RuntimeException("Failed to start GCDWebServer on port $port")
43+
}
44+
}
2645
}
2746

2847
actual fun stop() {
@@ -55,7 +74,6 @@ actual class HttpServer actual constructor() {
5574
} else {
5675
gcdResponse = GCDWebServerResponse()
5776
gcdResponse.statusCode = response.status.toLong()
58-
gcdResponse
5977
}
6078

6179
response.headers.forEach {

0 commit comments

Comments
 (0)