diff --git a/src/common/connection.py b/src/common/connection.py index 7665d8561..d51982ee9 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -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: diff --git a/src/common/xmpp/dispatcher.py b/src/common/xmpp/dispatcher.py index 6e3c0376b..2a0c4b4eb 100644 --- a/src/common/xmpp/dispatcher.py +++ b/src/common/xmpp/dispatcher.py @@ -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.