Skip to content

Commit

Permalink
add necessary wait function in lib module
Browse files Browse the repository at this point in the history
  • Loading branch information
rep committed Feb 10, 2013
1 parent 6e6a319 commit b34c7f6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions cli/hpfeeds.py
Expand Up @@ -106,13 +106,14 @@ def connect(self):
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)
self.s.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 10)

def run(self, message_callback, error_callback):
while not self.stopped:
while self.connected:
d = self.s.recv(BUFSIZ)
if not d:
logger.info('Disconnected from broker.')
self.connected = False
break

Expand All @@ -129,9 +130,21 @@ def run(self, message_callback, error_callback):

if self.stopped: break

if self.stopped: break
if self.stopped:
logger.info('Stopped, exiting run loop.')
break
self.tryconnect()

def wait(self, timeout=1):
self.s.settimeout(timeout)
try: d = self.s.recv(BUFSIZ)
except socket.timeout: return None
self.unpacker.feed(d)
for opcode, data in self.unpacker:
if opcode == OP_ERROR:
return data
return None

def subscribe(self, chaninfo):
if type(chaninfo) == str:
chaninfo = [chaninfo,]
Expand All @@ -152,4 +165,4 @@ def close(self):


def new(host=None, port=10000, ident=None, secret=None, timeout=3, reconnect=True, sleepwait=20):
return HPC(host, port, ident, secret, timeout, reconnect)
return HPC(host, port, ident, secret, timeout, reconnect)

0 comments on commit b34c7f6

Please sign in to comment.