3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

Use non-blocking sockets again, since Linux select() doesn't guarantee that recv() won't block

This commit is contained in:
James Lu 2018-04-12 10:51:34 -07:00
parent bbc7a981ba
commit 25d24e9bb2

View File

@ -1446,7 +1446,6 @@ utils._proto_utils_class = PyLinkNetworkCoreWithUtils # Used by compatibility w
class IRCNetwork(PyLinkNetworkCoreWithUtils):
S2S_BUFSIZE = 510
SOCKET_REPOLL_WAIT = 1.0
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -1567,6 +1566,10 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils):
return
self._socket.settimeout(self.pingtimeout)
# Make sure future reads never block, since select doesn't always guarantee this.
self._socket.setblocking(False)
self._selector_key = selectdriver.register(self)
# If SSL was enabled, optionally verify the certificate
@ -1751,9 +1754,8 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils):
try:
data = self._socket.recv(2048)
except (BlockingIOError, ssl.SSLWantReadError, ssl.SSLWantWriteError):
log.debug('(%s) No data to read, trying again later...', self.name)
if self._aborted.wait(self.SOCKET_REPOLL_WAIT):
return
log.debug('(%s) No data to read, trying again later...', self.name, exc_info=True)
return
except OSError:
# Suppress socket read warnings from lingering recv() calls if
# we've been told to shutdown.