diff options
author | Avery Pennarun <apenwarr@gmail.com> | 2010-10-04 02:45:21 -0700 |
---|---|---|
committer | Avery Pennarun <apenwarr@gmail.com> | 2010-10-04 02:47:43 -0700 |
commit | a32305a275eea70a2df22992eb0f4e7483d8ca98 (patch) | |
tree | 141c60a9edad52dc43d3272de2a499ece0a16653 | |
parent | ae32fe2a59934c39a57b0e06a554033af9c553bb (diff) |
server.py: don't send partial hostwatch lists.
If hostwatch has a lot of stuff to say all at once, it would come in more
than one recv() packet, and server.py would send each packet individually as
a CMD_HOST_LIST message. Unfortunately, client.py (rightly) expects each
CMD_HOST_LIST message to be complete, ie. a correct sequence of rows.
So now server.py makes sure of this. If there's a leftover bit (ie. an
unterminated line), it saves it for later.
Bug reported by user "Duke" on the mailing list.
-rw-r--r-- | server.py | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -133,12 +133,20 @@ def main(): mux.send(0, ssnet.CMD_ROUTES, routepkt) hw = Hostwatch() - + hw.leftover = '' + def hostwatch_ready(): assert(hw.pid) content = hw.sock.recv(4096) if content: - mux.send(0, ssnet.CMD_HOST_LIST, content) + lines = (hw.leftover + content).split('\n') + if lines[-1]: + # no terminating newline: entry isn't complete yet! + hw.leftover = lines.pop() + lines.append('') + else: + hw.leftover = '' + mux.send(0, ssnet.CMD_HOST_LIST, '\n'.join(lines)) else: raise Fatal('hostwatch process died') |