summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo (C10uD) <c10ud.dev@gmail.com>2011-08-16 21:49:47 +0200
committerRiccardo (C10uD) <c10ud.dev@gmail.com>2011-09-01 14:07:40 +0200
commit0d1ced9ecf5b1990b943a075edaccfd10e318785 (patch)
tree8e0fca53954b8e9f064d9e1963c7bdafca2d458e
parent223c29b706a97c8a3882551b93d10fdf92057039 (diff)
notification: check if PNGs are being answered by the server and disconnect if not
-rw-r--r--papyon/msnp/notification.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/papyon/msnp/notification.py b/papyon/msnp/notification.py
index 0fbfeac..964c566 100644
--- a/papyon/msnp/notification.py
+++ b/papyon/msnp/notification.py
@@ -100,6 +100,7 @@ class NotificationProtocol(BaseProtocol, Timer):
self.__state = ProtocolState.CLOSED
self._protocol_version = version
self._callbacks = {} # tr_id=>(callback, errback)
+ self._time_id = 0
# Properties ------------------------------------------------------------
def __get_state(self):
@@ -316,6 +317,10 @@ class NotificationProtocol(BaseProtocol, Timer):
# Handlers ---------------------------------------------------------------
# --------- Connection ---------------------------------------------------
+ def _check_ping(self, time_id):
+ if self.time_id == time_id:
+ self.emit("connection-lost", "Ping timeout")
+
def _handle_VER(self, command):
self._protocol_version = int(command.arguments[0].lstrip('MSNP'))
self._send_command('CVR',
@@ -396,6 +401,9 @@ class NotificationProtocol(BaseProtocol, Timer):
def _handle_QNG(self, command):
timeout = int(command.arguments[0])
self.start_timeout("ping", timeout)
+ self._time_id = time.time()
+ self.start_timeout("ping-%s" % self._time_id, timeout+5, \
+ (self._check_ping, self._time_id))
def _handle_OUT(self, command):
reason = None