send keepalive every minute

This commit is contained in:
Yann Leboulanger 2005-05-04 19:20:02 +00:00
parent cb4d4bc233
commit e8965ae8b4
2 changed files with 11 additions and 3 deletions

View file

@ -624,9 +624,10 @@ class Connection:
self.myVCardID.append(iq.getID())
elif (status == 'offline') and self.connected:
self.connected = 0
self.connection.send(common.xmpp.Presence(typ = 'unavailable',
status = msg))
self.connection.disconnect()
if self.connection:
self.connection.send(common.xmpp.Presence(typ = 'unavailable',
status = msg))
self.connection.disconnect()
self.dispatch('STATUS', 'offline')
self.connection = None
elif status != 'offline' and self.connected:

View file

@ -35,6 +35,7 @@ class Dispatcher(PlugIn):
PlugIn.__init__(self)
DBG_LINE='dispatcher'
self.handlers={}
self._lastIncome = time.time()
self._expected={}
self._defaultHandler=None
self._eventHandler=None
@ -99,10 +100,16 @@ class Dispatcher(PlugIn):
1) length of processed data if some data were processed;
2) '0' string if no data were processed but link is alive;
3) 0 (zero) if underlying connection is closed."""
if time.time() > self._lastIncome + 60: #1 min
iq = Iq('get', NS_LAST, to=self._owner.Server)
self.send(iq)
if time.time() > self._lastIncome + 90: #1 min + 30 sec pr rep
self.disconnected()
for handler in self._cycleHandlers: handler(self)
if self._owner.Connection.pending_data(timeout):
data=self._owner.Connection.receive()
self.Stream.Parse(data)
self._lastIncome = time.time()
return len(data)
return '0' # It means that nothing is received but link is alive.