diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2012-09-28 18:45:31 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2012-09-28 18:45:31 +0100 |
commit | e314da76b907f58d050dae1365053ceaa976db7f (patch) | |
tree | c71c0ccf252bc172b0ba5761ecda2c3beeea5d84 /lib/pure/scgi.nim | |
parent | 2aabae702d558acfb95003fe6a2aa7ae300f6ed4 (diff) | |
download | Nim-e314da76b907f58d050dae1365053ceaa976db7f.tar.gz |
Fixes async scgi.
Diffstat (limited to 'lib/pure/scgi.nim')
-rwxr-xr-x | lib/pure/scgi.nim | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/lib/pure/scgi.nim b/lib/pure/scgi.nim index 3ee6198d6..825fbd833 100755 --- a/lib/pure/scgi.nim +++ b/lib/pure/scgi.nim @@ -142,22 +142,7 @@ proc run*(handleRequest: proc (client: TSocket, input: string, s.close() # -- AsyncIO start - -proc open*(handleRequest: proc (server: var TAsyncScgiState, client: TSocket, - input: string, headers: PStringTable) {.closure.}, - port = TPort(4000), address = "127.0.0.1"): PAsyncScgiState = - ## Alternative of ``open`` for asyncio compatible SCGI. - new(result) - result.bufLen = 4000 - result.input = newString(result.buflen) # will be reused - - result.asyncServer = AsyncSocket() - bindAddr(result.asyncServer, port, address) - listen(result.asyncServer) - result.handleRequest = handleRequest - -proc handleAccept(h: PObject) = - var s = PAsyncScgiState(h) +proc handleAccept(sock: PAsyncSocket, s: PAsyncScgiState) = accept(getSocket(s.asyncServer), s.client) var L = 0 @@ -179,6 +164,22 @@ proc handleAccept(h: PObject) = s.handleRequest(s[], s.client, s.input, s.headers) +proc open*(handleRequest: proc (server: var TAsyncScgiState, client: TSocket, + input: string, headers: PStringTable) {.closure.}, + port = TPort(4000), address = "127.0.0.1"): PAsyncScgiState = + ## Alternative of ``open`` for asyncio compatible SCGI. + var cres: PAsyncScgiState + new(cres) + cres.bufLen = 4000 + cres.input = newString(cres.buflen) # will be reused + + cres.asyncServer = AsyncSocket() + cres.asyncServer.handleAccept = proc (s: PAsyncSocket) = handleAccept(s, cres) + bindAddr(cres.asyncServer, port, address) + listen(cres.asyncServer) + cres.handleRequest = handleRequest + result = cres + proc register*(d: PDispatcher, s: PAsyncScgiState): PDelegate {.discardable.} = ## Registers ``s`` with dispatcher ``d``. result = d.register(s.asyncServer) |