Commit 9cfa4e80 authored by Antoine Millet's avatar Antoine Millet

Fixed bug with processing small messages.

parent 3320fe8e
......@@ -109,8 +109,7 @@ class RpcConnection(object):
def receive(self):
'''
Receive data from socket into the inbound buffer. If data can be
decoded, do it and pass result to :meth:`dispatch` method.
Receive data from socket into the inbound buffer.
'''
try:
......@@ -127,10 +126,22 @@ class RpcConnection(object):
raise socket.error()
self._inbound_buffer.push(buf)
while self._process_inbound():
pass
def _process_inbound(self):
'''
Process the inbound buffer and :meth:`dispatch` messages.
:return: False if nothing happened or True
'''
# Read the message length:
if self._cur_msg_size is None and len(self._inbound_buffer) >= 4:
length = struct.unpack('!L', self._inbound_buffer.pull(4))[0]
self._cur_msg_size = length
return True
# Read the message payload:
if (self._cur_msg_size is not None
......@@ -140,6 +151,9 @@ class RpcConnection(object):
message = json.loads(payload)
logging.debug('Received: %s' % message)
self.dispatch(message)
return True
return False
def _send(self, message):
'''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment