Commit 1b9e9926 authored by Antoine Millet's avatar Antoine Millet

Enhanced socket read error handling

parent f4b653ff
......@@ -7,6 +7,7 @@ class are located in it docstring.
from __future__ import absolute_import
import ssl
import errno
import struct
import socket
import logging
......@@ -52,6 +53,9 @@ class RpcConnection(object):
automatically registered on label 0.
'''
NONBLOCKING_ERRORS = (errno.EAGAIN, errno.EWOULDBLOCK)
NONBLOCKING_SSL_ERRORS = (ssl.SSL_ERROR_WANT_READ)
MESSAGE_HEADER = '!HL'
MESSAGE_HEADER_FALLBACK = '!L'
MAX_LABEL = 2 ** 16
......@@ -189,8 +193,18 @@ class RpcConnection(object):
handler.
'''
# Try to received remaining data from the socket:
buf = self._sock.recv(self._remains)
if buf == '':
try:
buf = self._sock.recv(self._remains)
except socket.error as err:
if (isinstance(err, socket.error) and err.errno
in RpcConnection.NONBLOCKING_ERRORS):
return
elif (isinstance(err, ssl.SSLError) and err.errno
in RpcConnection.NONBLOCKING_SSL_ERRORS):
return
else:
raise
self.shutdown()
self._remains -= len(buf)
......
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