Skip to content
Browse files

Set TCP Keep-Alive idle period on Linux platforms

  • Loading branch information...
1 parent d3b023a commit 32734c9023082597493d1cfbe48a474355314515 @buffer buffer committed Jun 19, 2012
Showing with 10 additions and 3 deletions.
  1. +5 −0 cli/hpfeeds.py
  2. +5 −3 cli/thugfiles.py
View
5 cli/hpfeeds.py
@@ -1,4 +1,5 @@
+import sys
import struct
import socket
import hashlib
@@ -93,6 +94,10 @@ def connect(self):
raise FeedException('Expected info message at this point.')
self.s.settimeout(None)
+ self.s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
+
+ if sys.platform in ('linux2', ):
+ self.s.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 60)
def _run(self, message_callback, error_callback):
while not self.stopped:
View
8 cli/thugfiles.py
@@ -59,9 +59,11 @@ def on_error(payload):
except hpfeeds.FeedException:
break
- self.hpc.run(on_message, on_error)
- self.hpc.close()
- time.sleep(20)
+ try:
+ self.hpc.run(on_message, on_error)
+ except:
+ self.hpc.close()
+ time.sleep(20)
if __name__ == '__main__':
try:

0 comments on commit 32734c9

Please sign in to comment.
Something went wrong with that request. Please try again.