mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-12 05:02:33 +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):
|
class IRCNetwork(PyLinkNetworkCoreWithUtils):
|
||||||
S2S_BUFSIZE = 510
|
S2S_BUFSIZE = 510
|
||||||
SOCKET_REPOLL_WAIT = 1.0
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@ -1567,6 +1566,10 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self._socket.settimeout(self.pingtimeout)
|
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)
|
self._selector_key = selectdriver.register(self)
|
||||||
|
|
||||||
# If SSL was enabled, optionally verify the certificate
|
# If SSL was enabled, optionally verify the certificate
|
||||||
@ -1751,8 +1754,7 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils):
|
|||||||
try:
|
try:
|
||||||
data = self._socket.recv(2048)
|
data = self._socket.recv(2048)
|
||||||
except (BlockingIOError, ssl.SSLWantReadError, ssl.SSLWantWriteError):
|
except (BlockingIOError, ssl.SSLWantReadError, ssl.SSLWantWriteError):
|
||||||
log.debug('(%s) No data to read, trying again later...', self.name)
|
log.debug('(%s) No data to read, trying again later...', self.name, exc_info=True)
|
||||||
if self._aborted.wait(self.SOCKET_REPOLL_WAIT):
|
|
||||||
return
|
return
|
||||||
except OSError:
|
except OSError:
|
||||||
# Suppress socket read warnings from lingering recv() calls if
|
# Suppress socket read warnings from lingering recv() calls if
|
||||||
|
Loading…
Reference in New Issue
Block a user