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 twisted.protocols.basic import LineOnlyReceiver
|
||||||
from errors import RemoteServiceException, ProtocolException, ServiceException
|
from errors import RemoteServiceException, ProtocolException, ServiceException
|
||||||
|
|
||||||
log = logging.getLogger()
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class StratumClientProtocol(LineOnlyReceiver):
|
class StratumClientProtocol(LineOnlyReceiver):
|
||||||
|
@ -29,12 +29,22 @@ 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(socket.SOL_TCP, socket.TCP_KEEPIDLE,
|
if hasattr(socket, "TCP_KEEPIDLE"):
|
||||||
120) # Seconds before sending keepalive probes
|
self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE,
|
||||||
self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL,
|
120) # Seconds before sending keepalive probes
|
||||||
1) # Interval in seconds between keepalive probes
|
else:
|
||||||
self.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT,
|
log.debug("TCP_KEEPIDLE not available")
|
||||||
5) # Failed keepalive probles before declaring other end dead
|
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:
|
except Exception as err:
|
||||||
# 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.
|
||||||
|
|
Loading…
Reference in a new issue