mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-24 19:52:53 +01:00
Use non-blocking sockets again, since Linux select() doesn't guarantee that recv() won't block
This commit is contained in:
parent
bbc7a981ba
commit
25d24e9bb2
@ -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,8 +1754,7 @@ 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):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user