diff --git a/Doc/library/asyncore.rst b/Doc/library/asyncore.rst --- a/Doc/library/asyncore.rst +++ b/Doc/library/asyncore.rst @@ -209,7 +209,11 @@ Read at most *buffer_size* bytes from the socket's remote end-point. An empty string implies that the channel has been closed from the other end. + None can be returned in case the socket was not ready to be read in which + case the application should just 'pass'. + .. versionchanged:: 3.4 + None can be returned .. method:: listen(backlog) diff --git a/Lib/asynchat.py b/Lib/asynchat.py --- a/Lib/asynchat.py +++ b/Lib/asynchat.py @@ -118,6 +118,8 @@ self.handle_error() return + if data is None: + return if isinstance(data, str) and self.use_encoding: data = bytes(str, self.encoding) self.ac_in_buffer = self.ac_in_buffer + data diff --git a/Lib/asyncore.py b/Lib/asyncore.py --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -59,6 +59,8 @@ _DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, EBADF)) +_RETRY = frozenset((EWOULDBLOCK, EAGAIN)) + try: socket_map @@ -389,6 +391,8 @@ if why.args[0] in _DISCONNECTED: self.handle_close() return b'' + elif why.args[0] in _RETRY: + return None else: raise