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,6 +624,7 @@ class Connection:
self.myVCardID.append(iq.getID()) self.myVCardID.append(iq.getID())
elif (status == 'offline') and self.connected: elif (status == 'offline') and self.connected:
self.connected = 0 self.connected = 0
if self.connection:
self.connection.send(common.xmpp.Presence(typ = 'unavailable', self.connection.send(common.xmpp.Presence(typ = 'unavailable',
status = msg)) status = msg))
self.connection.disconnect() self.connection.disconnect()

View file

@ -35,6 +35,7 @@ class Dispatcher(PlugIn):
PlugIn.__init__(self) PlugIn.__init__(self)
DBG_LINE='dispatcher' DBG_LINE='dispatcher'
self.handlers={} self.handlers={}
self._lastIncome = time.time()
self._expected={} self._expected={}
self._defaultHandler=None self._defaultHandler=None
self._eventHandler=None self._eventHandler=None
@ -99,10 +100,16 @@ class Dispatcher(PlugIn):
1) length of processed data if some data were processed; 1) length of processed data if some data were processed;
2) '0' string if no data were processed but link is alive; 2) '0' string if no data were processed but link is alive;
3) 0 (zero) if underlying connection is closed.""" 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) for handler in self._cycleHandlers: handler(self)
if self._owner.Connection.pending_data(timeout): if self._owner.Connection.pending_data(timeout):
data=self._owner.Connection.receive() data=self._owner.Connection.receive()
self.Stream.Parse(data) self.Stream.Parse(data)
self._lastIncome = time.time()
return len(data) return len(data)
return '0' # It means that nothing is received but link is alive. return '0' # It means that nothing is received but link is alive.