Browse Source

threaded lost-connection

David Rose 16 years ago
parent
commit
6df61edb83
1 changed files with 15 additions and 6 deletions
  1. 15 6
      direct/src/distributed/ConnectionRepository.py

+ 15 - 6
direct/src/distributed/ConnectionRepository.py

@@ -52,14 +52,19 @@ class ConnectionRepository(
         DoCollectionManager.__init__(self)
         DoCollectionManager.__init__(self)
         self.setPythonRepository(self)
         self.setPythonRepository(self)
 
 
-        base.finalExitCallbacks.append(self.shutdown)
-
-        self.config = config
-
         # Create a unique ID number for each ConnectionRepository in
         # Create a unique ID number for each ConnectionRepository in
         # the world, helpful for sending messages specific to each one.
         # the world, helpful for sending messages specific to each one.
         self.uniqueId = hash(self)
         self.uniqueId = hash(self)
 
 
+        base.finalExitCallbacks.append(self.shutdown)
+
+        # Accept this hook so that we can respond to lost-connection
+        # events in the main thread, instead of within the network
+        # thread (if there is one).
+        self.accept(self.uniqueName('lostConnection'), self.lostConnection)
+        
+        self.config = config
+
         if self.config.GetBool('verbose-repository'):
         if self.config.GetBool('verbose-repository'):
             self.setVerbose(1)
             self.setVerbose(1)
 
 
@@ -510,6 +515,7 @@ class ConnectionRepository(
         else:
         else:
             print "uh oh, we aren't using one of the tri-state CM variables"
             print "uh oh, we aren't using one of the tri-state CM variables"
             failureCallback(0, '', *failureArgs)
             failureCallback(0, '', *failureArgs)
+
     def disconnect(self):
     def disconnect(self):
         """
         """
         Closes the previously-established connection.
         Closes the previously-established connection.
@@ -519,6 +525,10 @@ class ConnectionRepository(
         CConnectionRepository.disconnect(self)
         CConnectionRepository.disconnect(self)
         self.stopReaderPollTask()
         self.stopReaderPollTask()
 
 
+    def shutdown(self):
+        self.ignoreAll()
+        CConnectionRepository.shutdown(self)
+
     def httpConnectCallback(self, ch, serverList, serverIndex,
     def httpConnectCallback(self, ch, serverList, serverIndex,
                             successCallback, successArgs,
                             successCallback, successArgs,
                             failureCallback, failureArgs):
                             failureCallback, failureArgs):
@@ -597,7 +607,6 @@ class ConnectionRepository(
     def readerPollUntilEmpty(self, task):
     def readerPollUntilEmpty(self, task):
         while self.readerPollOnce():
         while self.readerPollOnce():
             pass
             pass
-        Thread.forceYield()
         return Task.cont
         return Task.cont
 
 
     def readerPollOnce(self):
     def readerPollOnce(self):
@@ -609,7 +618,7 @@ class ConnectionRepository(
         # Unable to receive a datagram: did we lose the connection?
         # Unable to receive a datagram: did we lose the connection?
         if not self.isConnected():
         if not self.isConnected():
             self.stopReaderPollTask()
             self.stopReaderPollTask()
-            self.lostConnection()
+            messenger.send(self.uniqueName('lostConnection'), taskChain = 'default')
         return 0
         return 0
 
 
     def handleReaderOverflow(self):
     def handleReaderOverflow(self):