forked from LBRYCommunity/lbry-sdk
socket might not have TCP_KEEPx attributes
This commit is contained in:
parent
28386e8935
commit
f1e3682302
1 changed files with 17 additions and 7 deletions
|
@ -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)
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue