]> code.delx.au - pymsnt/blobdiff - src/tlib/msn/msnw.py
Hopeful fix for NotificationClient.connectionLost problem
[pymsnt] / src / tlib / msn / msnw.py
index b9e3028115a25c4ca21afa6bfd2bc5d1d03b71ff..7b2c22cd7af1eed67ab0211c114255356682e8a0 100644 (file)
@@ -360,6 +360,10 @@ class DispatchClient(msn.DispatchClient):
 
 
 class NotificationClient(msn.NotificationClient):
+       def doDisconnect(self, *args):
+               if hasattr(self, "transport") and self.transport:
+                       self.transport.loseConnection()
+
        def loginFailure(self, message):
                self.factory.msncon.loginFailed(message)
        
@@ -373,14 +377,18 @@ class NotificationClient(msn.NotificationClient):
        
        def logOut(self):
                msn.NotificationClient.logOut(self)
+               # If we explicitly log out, then all of these events
+               # are now redundant
+               self.loginFailure = self.doDisconnect
+               self.loggedIn = self.doDisconnect
+               self.connectionLost = self.doDisconnect
        
        def connectionLost(self, reason):
-               print "NotificationClient.connectionLost!!!"
-               if not self.factory.msncon: return # If we called logOut
                def wait():
                        LogEvent(INFO, self.factory.msncon.ident)
                        msn.NotificationClient.connectionLost(self, reason)
-                       if self.factory.maxRetries >= self.factory.retries:
+                       if self.factory.maxRetries > self.factory.retries:
+                               self.factory.stopTrying()
                                self.factory.msncon.connectionLost(reason)
                # Make sure this event is handled after any others
                reactor.callLater(0, wait)
@@ -461,10 +469,13 @@ class SwitchboardSessionBase(msn.SwitchboardClient):
                self.funcBuffer = []
                self.ready = False
 
-       def __del__(self):
+       def connectionLost(self, reason):
+               msn.SwitchboardClient.connectionLost(self, reason)
                LogEvent(INFO, self.ident)
-               del self.msncon
-               self.transport.disconnect()
+               self.ready = False
+               self.msncon = None
+               self.msnobj = None
+               self.ident = (self.ident[0], self.ident[1], "Disconnected!")
 
        def loggedIn(self):
                LogEvent(INFO, self.ident)
@@ -576,7 +587,7 @@ class MultiSwitchboardSession(SwitchboardSessionBase):
        def __init__(self, msncon):
                """ Automatically creates a new switchboard connection to the server """
                SwitchboardSessionBase.__init__(self, msncon)
-               self.ident = (self.msncon.ident, self)
+               self.ident = (self.msncon.ident, repr(self))
                self.contactCount = 0
                self.groupchat = None
                self.connect()
@@ -627,13 +638,14 @@ class OneSwitchboardSession(SwitchboardSessionBase):
                self.chattingUsers = []
                self.timeout = None
        
-       def __del__(self):
+       def connectionLost(self, reason):
                if self.timeout:
                        self.timeout.cancel()
                self.timeout = None
                for message, noerror in self.messageBuffer:
                        if not noerror:
                                self.failedMessage(message)
+               SwitchboardSessionBase.connectionLost(self, reason)
 
        def _ready(self):
                LogEvent(INFO, self.ident)
@@ -667,6 +679,7 @@ class OneSwitchboardSession(SwitchboardSessionBase):
                                LogEvent(INFO, self.ident, "User has not joined after 30 seconds.")
                                del self.msncon.switchboardSessions[self.remoteUser]
                                self.timeout = None
+                               self.transport.loseConnection()
                        d = self.inviteUser(self.remoteUser)
                        d.addErrback(failCB)
                        self.timeout = reactor.callLater(30.0, failCB)