File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,9 @@ def decodemsg(buf, source):
8989 of two messages, it will contain the start of the next message,
9090 which is needed for the next run of `decodemsg`.
9191
92+ For an OOP API to `decodemsg` that manages the `ReceiveBuffer`
93+ internally, see `MessageDecoder`.
94+
9295 source: *Message source*: an iterator that yields chunks of data from some
9396 data stream, and raises `StopIteration` when it reaches EOF.
9497
@@ -130,12 +133,14 @@ def decodemsg(buf, source):
130133
131134 buf = ReceiveBuffer()
132135 source = socketsource(sock)
133- while not terminated :
136+ while True :
134137 data = decodemsg(buf, source) # get the next message
138+ if not data:
139+ break
135140 ...
136141
137- See also `MessageDecoder` for an OOP API, abstracting away the
138- `ReceiveBuffer`.
142+ See also `MessageDecoder` for an OOP API in which you don't need to care
143+ about the `ReceiveBuffer`.
139144 """
140145 source = iter (source )
141146
@@ -264,8 +269,10 @@ class MessageDecoder:
264269 # ...open a TCP socket `sock`...
265270
266271 decoder = MessageDecoder(socketsource(sock))
267- while not terminated :
272+ while True :
268273 data = decoder.decode() # get the next message
274+ if not data:
275+ break
269276 ...
270277
271278 A `ReceiveBuffer` is created internally. If you need to access it (e.g.
You can’t perform that action at this time.
0 commit comments