summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2014-03-15 14:11:29 +0000
committerDominik Picheta <dominikpicheta@googlemail.com>2014-03-22 22:33:51 +0000
commitca6b4bf0f9a8fc99247fc3147dd9760a1bde6f47 (patch)
treea704b7a2eae5daeb12aaecad4e62a409a183427a
parenta4f30c36822511ce4460a5d23b2ec82e36f5e796 (diff)
downloadNim-ca6b4bf0f9a8fc99247fc3147dd9760a1bde6f47.tar.gz
Asyncio2 doc improvements. Changed recvLine's behaviour.
recvLine had an edge case where it would return a partial line if the
socket were to be disconnected in the middle of a line being read. The
behaviour now is that the data is simply lost as it likely will be
unparsable by the protocol anyway.
-rw-r--r--lib/pure/asyncio2.nim20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/pure/asyncio2.nim b/lib/pure/asyncio2.nim
index eb31eca13..c5371adf0 100644
--- a/lib/pure/asyncio2.nim
+++ b/lib/pure/asyncio2.nim
@@ -93,18 +93,15 @@ proc read*[T](future: PFuture[T]): T =
 proc finished*[T](future: PFuture[T]): bool =
   ## Determines whether ``future`` has completed.
   ##
-  ## ``True`` may indicate an error or a value. Use ``hasError`` to distinguish.
+  ## ``True`` may indicate an error or a value. Use ``failed`` to distinguish.
   future.finished
 
 proc failed*[T](future: PFuture[T]): bool =
   ## Determines whether ``future`` completed with an error.
   future.error != nil
 
-# TODO: Get rid of register. Do it implicitly.
-
 when defined(windows) or defined(nimdoc):
   import winlean, sets, hashes
-  #from hashes import THash
   type
     TCompletionKey = dword
 
@@ -794,6 +791,9 @@ proc getName(node: PNimrodNode): string {.compileTime.} =
     assert false
 
 macro async*(prc: stmt): stmt {.immediate.} =
+  ## Macro which processes async procedures into the appropriate
+  ## iterators and yield statements.
+
   expectKind(prc, nnkProcDef)
 
   hint("Processing " & prc[0].getName & " as an async proc.")
@@ -893,6 +893,10 @@ proc recvLine*(p: PDispatcher, socket: TSocketHandle): PFuture[string] {.async.}
   ## will be set to it.
   ## 
   ## If the socket is disconnected, ``line`` will be set to ``""``.
+  ##
+  ## If the socket is disconnected in the middle of a line (before ``\r\L``
+  ## is read) then line will be set to ``""``.
+  ## The partial line **will be lost**.
   
   template addNLIfEmpty(): stmt =
     if result.len == 0:
@@ -901,13 +905,9 @@ proc recvLine*(p: PDispatcher, socket: TSocketHandle): PFuture[string] {.async.}
   result = ""
   var c = ""
   while true:
-    #echo("1")
     c = await p.recv(socket, 1)
-    #echo("Received ", c.len)
     if c.len == 0:
-      #echo("returning")
-      return
-    #echo("2")
+      return ""
     if c == "\r":
       c = await p.recv(socket, 1, MSG_PEEK)
       if c.len > 0 and c == "\L":
@@ -917,9 +917,7 @@ proc recvLine*(p: PDispatcher, socket: TSocketHandle): PFuture[string] {.async.}
     elif c == "\L":
       addNLIfEmpty()
       return
-    #echo("3")
     add(result.string, c)
-  #echo("4")
 
 when isMainModule: