]> code.delx.au - pymsnt/blobdiff - src/tlib/msn/msn.py
Added auto-reconnect.
[pymsnt] / src / tlib / msn / msn.py
index 96aa587556950bd6759631827f4eac1ba9a6a1e4..d236c66d649fa80f02b393c9a33877a76af9caee 100644 (file)
@@ -99,7 +99,7 @@ import msnp11chl
 # Twisted imports
 from twisted.internet import reactor, task
 from twisted.internet.defer import Deferred
-from twisted.internet.protocol import ClientFactory
+from twisted.internet.protocol import ReconnectingClientFactory, ClientFactory
 try:
     from twisted.internet.ssl import ClientContextFactory
 except ImportError:
@@ -973,6 +973,7 @@ class NotificationClient(MSNEventBase):
         MSNEventBase.connectionMade(self)
         self._setState('CONNECTED')
         self.sendLine("VER %s %s" % (self._nextTransactionID(), MSN_PROTOCOL_VERSION))
+        self.factory.resetDelay()
 
     def connectionLost(self, reason):
         self._setState('DISCONNECTED')
@@ -1386,6 +1387,7 @@ class NotificationClient(MSNEventBase):
 
     def handle_OUT(self, params):
         checkParamLen(len(params), 1, 'OUT')
+        self.factory.stopTrying()
         if params[0] == "OTH": self.multipleLogin()
         elif params[0] == "SSD": self.serverGoingDown()
         else: raise MSNProtocolError, "Invalid Parameters received for OUT" # debug
@@ -1991,10 +1993,11 @@ class NotificationClient(MSNEventBase):
         if self.pingCheckTask:
             self.pingCheckTask.stop()
             self.pingCheckTask = None
+        self.factory.stopTrying()
         self.sendLine("OUT")
         self.transport.loseConnection()
 
-class NotificationFactory(ClientFactory):
+class NotificationFactory(ReconnectingClientFactory):
     """
     Factory for the NotificationClient protocol.
     This is basically responsible for keeping
@@ -2017,6 +2020,8 @@ class NotificationFactory(ClientFactory):
                           (the whole URL is required)
     @ivar status: The status of the client -- this is generally kept
                   up to date by the default command handlers
+    @ivar maxRetries: The number of times the factory will reconnect
+                      if the connection dies because of a network error.
     """
 
     contacts = None
@@ -2026,6 +2031,7 @@ class NotificationFactory(ClientFactory):
     passportServer = 'https://nexus.passport.com/rdr/pprdr.asp'
     status = 'FLN'
     protocol = NotificationClient
+    maxRetries = 5
 
 
 class SwitchboardClient(MSNEventBase):