File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
library/src/iOSMain/kotlin Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,27 @@ actual fun Data.asString(): String {
21
21
@Suppress(" UNCHECKED_CAST" )
22
22
actual class HttpServer actual constructor() {
23
23
private val httpServer = GCDWebServer ()
24
+
24
25
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
+ }
26
45
}
27
46
28
47
actual fun stop () {
@@ -55,7 +74,6 @@ actual class HttpServer actual constructor() {
55
74
} else {
56
75
gcdResponse = GCDWebServerResponse ()
57
76
gcdResponse.statusCode = response.status.toLong()
58
- gcdResponse
59
77
}
60
78
61
79
response.headers.forEach {
You can’t perform that action at this time.
0 commit comments