From 3320fe8e55cd8ab4e5aaadd5c0c32d7f76745e76 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Tue, 1 Feb 2011 12:02:23 +0100 Subject: [PATCH] Fixed bug when recving on an "empty" socket. --- sjrpc/core/rpcconnection.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sjrpc/core/rpcconnection.py b/sjrpc/core/rpcconnection.py index 02e6c3a..0c6a6a1 100644 --- a/sjrpc/core/rpcconnection.py +++ b/sjrpc/core/rpcconnection.py @@ -112,11 +112,20 @@ class RpcConnection(object): Receive data from socket into the inbound buffer. If data can be decoded, do it and pass result to :meth:`dispatch` method. ''' - - buf = self._sock.recv(RpcConnection.RECV_BUF_SIZE) + + try: + buf = self._sock.recv(RpcConnection.RECV_BUF_SIZE) + except socket.error as err: + if err.errno == 11: + # Errno 11 -> retry again + logging.warning('Non critical error while reading a socket:' + ' %r', err) + return + if not buf: + # Empty buffer = closed socket. raise socket.error() - + self._inbound_buffer.push(buf) # Read the message length: if self._cur_msg_size is None and len(self._inbound_buffer) >= 4: -- GitLab