From f1e36823025199461836733e2a1b2e22db35596e Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 2 May 2018 17:16:00 -0400 Subject: [PATCH] socket might not have TCP_KEEPx attributes --- lbrynet/txlbryum/client.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lbrynet/txlbryum/client.py b/lbrynet/txlbryum/client.py index 96a6a08e1..d01b5eeb6 100644 --- a/lbrynet/txlbryum/client.py +++ b/lbrynet/txlbryum/client.py @@ -6,7 +6,7 @@ from twisted.internet import defer, error from twisted.protocols.basic import LineOnlyReceiver from errors import RemoteServiceException, ProtocolException, ServiceException -log = logging.getLogger() +log = logging.getLogger(__name__) class StratumClientProtocol(LineOnlyReceiver): @@ -29,12 +29,22 @@ class StratumClientProtocol(LineOnlyReceiver): try: self.transport.setTcpNoDelay(True) self.transport.setTcpKeepAlive(True) - self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, - 120) # Seconds before sending keepalive probes - self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, - 1) # Interval in seconds between keepalive probes - self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT, - 5) # Failed keepalive probles before declaring other end dead + if hasattr(socket, "TCP_KEEPIDLE"): + self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, + 120) # Seconds before sending keepalive probes + else: + log.debug("TCP_KEEPIDLE not available") + if hasattr(socket, "TCP_KEEPINTVL"): + self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, + 1) # Interval in seconds between keepalive probes + else: + log.debug("TCP_KEEPINTVL not available") + 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: # Supported only by the socket transport, # but there's really no better place in code to trigger this.