rocksock: skip shutdown on never-connected sockets
Track connection state with _connected flag. Only call socket.shutdown() on successfully connected sockets. Saves ~39s/session on workers (974k disconnect calls).
This commit is contained in:
12
rocksock.py
12
rocksock.py
@@ -242,6 +242,7 @@ class Rocksock():
|
||||
target = RocksockProxy(host, port, RS_PT_NONE)
|
||||
self.proxychain.append(target)
|
||||
self.sock = None
|
||||
self._connected = False
|
||||
self.timeout = timeout
|
||||
|
||||
def _translate_socket_error(self, e, pnum):
|
||||
@@ -302,15 +303,18 @@ class Rocksock():
|
||||
select.select([], [self.sock], [])
|
||||
"""
|
||||
|
||||
self._connected = True
|
||||
|
||||
def disconnect(self):
|
||||
if self.sock is None: return
|
||||
try:
|
||||
self.sock.shutdown(socket.SHUT_RDWR)
|
||||
except socket.error:
|
||||
pass
|
||||
if self._connected:
|
||||
try:
|
||||
self.sock.shutdown(socket.SHUT_RDWR)
|
||||
except socket.error:
|
||||
pass
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
self._connected = False
|
||||
|
||||
def canread(self):
|
||||
return select.select([self.sock], [], [], 0)[0]
|
||||
|
||||
Reference in New Issue
Block a user