diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-09-16 16:37:53 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-09-16 16:37:53 +0100 |
commit | efca06c71c47eb636aacefe97e5816dc2e1082ff (patch) | |
tree | a9df66d692ba9edeb4253b6178a9eefec6de6d83 | |
parent | 33b9ab47d9903b9dcbb6c9886cd0646f53e88b62 (diff) | |
download | Nim-efca06c71c47eb636aacefe97e5816dc2e1082ff.tar.gz |
Add bool to determine if socket has been closed.
-rw-r--r-- | lib/pure/asynchttpserver.nim | 2 | ||||
-rw-r--r-- | lib/pure/asyncnet.nim | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/pure/asynchttpserver.nim b/lib/pure/asynchttpserver.nim index 9de0a6268..257fbaeb5 100644 --- a/lib/pure/asynchttpserver.nim +++ b/lib/pure/asynchttpserver.nim @@ -116,7 +116,7 @@ proc sendStatus(client: PAsyncSocket, status: string): Future[void] = proc processClient(client: PAsyncSocket, address: string, callback: proc (request: TRequest): Future[void] {.closure, gcsafe.}) {.async.} = - while true: + while not client.closed: # GET /path HTTP/1.1 # Header: val # \n diff --git a/lib/pure/asyncnet.nim b/lib/pure/asyncnet.nim index a16111349..c6918517e 100644 --- a/lib/pure/asyncnet.nim +++ b/lib/pure/asyncnet.nim @@ -67,7 +67,8 @@ type # PAsyncSocket* {.borrow: `.`.} = distinct PSocket. But that doesn't work. AsyncSocketDesc = object fd*: SocketHandle - case isBuffered*: bool # determines whether this socket is buffered. + closed*: bool ## determines whether this socket has been closed + case isBuffered*: bool ## determines whether this socket is buffered. of true: buffer*: array[0..BufferSize, char] currPos*: int # current index in buffer @@ -400,6 +401,7 @@ proc close*(socket: PAsyncSocket) = raiseSslError() elif res != 1: raiseSslError() + socket.closed = true # TODO: Add extra debugging checks for this. when defined(ssl): proc wrapSocket*(ctx: SslContext, socket: AsyncSocket) = |