diff --git a/sjrpc/core/rpcconnection.py b/sjrpc/core/rpcconnection.py index 0c6a6a1498aa90bb1e8bbae12a01b30d52645180..ccb178c31de3cadf7d7f10dc5cccbdda001d7cf9 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): '''