summary refs log tree commit diff stats
path: root/lib
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 /lib
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.
Diffstat (limited to 'lib')
-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:
   
t.com> 2009-11-24 00:41:16 +0100 committer hut <hut@lavabit.com> 2009-11-24 00:41:16 +0100 better implementation of directories/files' href='/akspecs/ranger/commit/code/fsobject.py?id=fae694a03ebb52888a747010fcb92fa43b33b4a8'>fae694a0 ^
871c502d ^
3d566884 ^
b4b0eb24 ^
3d566884 ^
20f94973 ^
3d566884 ^
fae694a0 ^
9506fb8e ^
16246965 ^
ae943ecb ^
20f94973 ^
3de15ddd ^
b810fe28 ^



b810fe28 ^

871c502d ^
ddf828fb ^


9506fb8e ^

3de15ddd ^
9506fb8e ^
fae694a0 ^
871c502d ^
3de15ddd ^
871c502d ^



3de15ddd ^
871c502d ^


b810fe28 ^
3de15ddd ^
b810fe28 ^
871c502d ^
b810fe28 ^














3201b163 ^






99e6cf47 ^
b810fe28 ^
fae694a0 ^
ec5dfcb1 ^

b4b0eb24 ^

fae694a0 ^
30b25795 ^
3de15ddd ^
b810fe28 ^


30b25795 ^









9506fb8e ^
fae694a0 ^

556d84cd ^

3d566884 ^
9506fb8e ^
419e4aa5 ^

9506fb8e ^

3d566884 ^
9506fb8e ^

556d84cd ^
3d566884 ^
419e4aa5 ^
5805deca ^
798d06a2 ^
3d566884 ^
798d06a2 ^

9506fb8e ^
30b25795 ^



3d566884 ^
fae694a0 ^
9506fb8e ^
30b25795 ^


cfdbb9d6 ^




30b25795 ^


cfdbb9d6 ^
cfdbb9d6 ^


4fb1670e ^
cfdbb9d6 ^
4fb1670e ^


cfdbb9d6 ^

4fb1670e ^


cfdbb9d6 ^
4fb1670e ^
cfdbb9d6 ^
4fb1670e ^

fae694a0 ^

3de15ddd ^
556d84cd ^



fae694a0 ^
871c502d ^
3de15ddd ^

4c05e43d ^

871c502d ^
fae694a0 ^
ec5dfcb1 ^

b4b0eb24 ^

556d84cd ^
fae694a0 ^
f6f26231 ^
c2a89082 ^
ec5dfcb1 ^
c2a89082 ^
ec5dfcb1 ^




fae694a0 ^



fae694a0 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236