am I doing this right?

Copied from f1e3682302, looks like it could work, but didn't test locally.
This commit is contained in:
Thomas Zarebczan 2018-09-19 00:49:35 -04:00 committed by Lex Berezhny
parent 18629c93a2
commit d76758bd1d

View file

@ -41,23 +41,37 @@ class StratumClientProtocol(LineOnlyReceiver):
try: try:
self.transport.setTcpNoDelay(True) self.transport.setTcpNoDelay(True)
self.transport.setTcpKeepAlive(True) self.transport.setTcpKeepAlive(True)
self.transport.socket.setsockopt( if hasattr(socket, "TCP_KEEPIDLE"):
socket.SOL_TCP, socket.TCP_KEEPIDLE, 120 self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE,
# Seconds before sending keepalive probes 120) # Seconds before sending keepalive probes
) else:
self.transport.socket.setsockopt( log.debug("TCP_KEEPIDLE not available")
socket.SOL_TCP, socket.TCP_KEEPINTVL, 1 if hasattr(socket, "TCP_KEEPINTVL"):
# Interval in seconds between keepalive probes self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL,
) 1) # Interval in seconds between keepalive probes
self.transport.socket.setsockopt( else:
socket.SOL_TCP, socket.TCP_KEEPCNT, 5 log.debug("TCP_KEEPINTVL not available")
# Failed keepalive probles before declaring other end dead if hasattr(socket, "TCP_KEEPCNT"):
) self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT,
5) # Failed keepalive probles before declaring other end dead
else:
log.debug("TCP_KEEPCNT not available")
except Exception as err: # pylint: disable=broad-except except Exception as err: # pylint: disable=broad-except
# Supported only by the socket transport, # Supported only by the socket transport,
# but there's really no better place in code to trigger this. # but there's really no better place in code to trigger this.
log.warning("Error setting up socket: %s", err) log.warning("Error setting up socket: %s", err)
self.request_id = 0
self.lookup_table = {}
self._connected.callback(True)
# Initiate connection session
self.session = {}
log.debug("Connected %s" % self.transport.getPeer().host)
def connectionLost(self, reason=None): def connectionLost(self, reason=None):
self.on_disconnected_controller.add(True) self.on_disconnected_controller.add(True)