From 9cfa4e80eee2ecac384a5baf9abad77a01570f18 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Tue, 1 Feb 2011 12:19:19 +0100 Subject: [PATCH] Fixed bug with processing small messages. --- sjrpc/core/rpcconnection.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sjrpc/core/rpcconnection.py b/sjrpc/core/rpcconnection.py index 0c6a6a1..ccb178c 100644 --- a/sjrpc/core/rpcconnection.py +++ b/sjrpc/core/rpcconnection.py @@ -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): ''' -- GitLab