summary refs log tree commit diff stats
path: root/lib/pure/scgi.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/scgi.nim')
-rw-r--r--lib/pure/scgi.nim10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/pure/scgi.nim b/lib/pure/scgi.nim
index 04b77fafe..45f837833 100644
--- a/lib/pure/scgi.nim
+++ b/lib/pure/scgi.nim
@@ -26,6 +26,8 @@
 ## **Warning:** The API of this module is unstable, and therefore is subject
 ## to change.
 
+include "system/inclrtl"
+
 import sockets, strutils, os, strtabs, asyncio
 
 type
@@ -82,7 +84,7 @@ type
   
   TAsyncScgiState = object
     handleRequest: proc (client: PAsyncSocket, 
-                         input: string, headers: PStringTable) {.closure.}
+                         input: string, headers: PStringTable) {.closure,gcsafe.}
     asyncServer: PAsyncSocket
     disp: PDispatcher
   PAsyncScgiState* = ref TAsyncScgiState
@@ -102,6 +104,7 @@ proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1",
   s.input = newString(s.buflen) # will be reused
   
   s.server = socket()
+  if s.server == InvalidSocket: osError(osLastError())
   new(s.client) # Initialise s.client for `next`
   if s.server == InvalidSocket: scgiError("could not open socket")
   #s.server.connect(connectionName, port)
@@ -149,7 +152,7 @@ proc writeStatusOkTextContent*(c: TSocket, contentType = "text/html") =
          "Content-Type: $1\r\L\r\L" % contentType)
 
 proc run*(handleRequest: proc (client: TSocket, input: string, 
-                               headers: PStringTable): bool {.nimcall.},
+                               headers: PStringTable): bool {.nimcall,gcsafe.},
           port = TPort(4000)) = 
   ## encapsulates the SCGI object and main loop.
   var s: TScgiState
@@ -245,7 +248,8 @@ proc handleAccept(sock: PAsyncSocket, s: PAsyncScgiState) =
   s.disp.register(client)
 
 proc open*(handleRequest: proc (client: PAsyncSocket, 
-                                input: string, headers: PStringTable) {.closure.},
+                                input: string, headers: PStringTable) {.
+                                closure, gcsafe.},
            port = TPort(4000), address = "127.0.0.1",
            reuseAddr = false): PAsyncScgiState =
   ## Creates an ``PAsyncScgiState`` object which serves as a SCGI server.