summary refs log tree commit diff stats
path: root/lib/pure/asyncio.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/asyncio.nim')
-rw-r--r--lib/pure/asyncio.nim11
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()