diff options
author | Araq <rumpf_a@web.de> | 2013-06-27 01:05:19 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-06-27 01:05:19 +0200 |
commit | 3ff572ffcd9ec38bc4e7ba08f97a60053f59d838 (patch) | |
tree | 96ff24139e5cf8872a01d93505be12a121c4a423 /lib/pure/asyncio.nim | |
parent | a674c039fb959166681f13f809670807b89e0b41 (diff) | |
parent | 9686d92bfc47cf9f2cf33e982c0f8f8113981faa (diff) | |
download | Nim-3ff572ffcd9ec38bc4e7ba08f97a60053f59d838.tar.gz |
Merge branch 'master' of github.com:Araq/Nimrod
Diffstat (limited to 'lib/pure/asyncio.nim')
-rw-r--r-- | lib/pure/asyncio.nim | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/pure/asyncio.nim b/lib/pure/asyncio.nim index 403401ff1..4ff6e0ced 100644 --- a/lib/pure/asyncio.nim +++ b/lib/pure/asyncio.nim @@ -167,7 +167,7 @@ proc AsyncSocket*(domain: TDomain = AF_INET, typ: TType = SOCK_STREAM, result = newAsyncSocket() result.socket = socket(domain, typ, protocol, buffered) result.proto = protocol - if result.socket == InvalidSocket: OSError() + if result.socket == InvalidSocket: OSError(OSLastError()) result.socket.setBlocking(false) proc toAsyncSocket*(sock: TSocket, state: TInfo = SockConnected): PAsyncSocket = @@ -349,7 +349,7 @@ proc acceptAddr*(server: PAsyncSocket, client: var PAsyncSocket, client.sslNeedAccept = false client.info = SockConnected - if c == InvalidSocket: OSError() + if c == InvalidSocket: SocketError(server.socket) c.setBlocking(false) # TODO: Needs to be tested. # deleg.open is set in ``toDelegate``. @@ -423,6 +423,10 @@ proc isConnecting*(s: PAsyncSocket): bool = proc isClosed*(s: PAsyncSocket): bool = ## Determines whether ``s`` has been closed. return s.info == SockClosed +proc isSendDataBuffered*(s: PAsyncSocket): bool = + ## Determines whether ``s`` has data waiting to be sent, i.e. whether this + ## socket's sendBuffer contains data. + return s.sendBuffer.len != 0 proc setHandleWrite*(s: PAsyncSocket, handleWrite: proc (s: PAsyncSocket) {.closure.}) = @@ -638,8 +642,7 @@ when isMainModule: proc testRead(s: PAsyncSocket, no: int) = echo("Reading! " & $no) var data = "" - if not s.readLine(data): - OSError() + if not s.readLine(data): return if data == "": echo("Closing connection. " & $no) s.close() |