From 6df61edb83373ffae04a50a7040306244171d4a5 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 5 Dec 2009 22:58:01 +0000 Subject: [PATCH] threaded lost-connection --- .../src/distributed/ConnectionRepository.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/direct/src/distributed/ConnectionRepository.py b/direct/src/distributed/ConnectionRepository.py index 0d664f41bf..a1f3e5dbb1 100644 --- a/direct/src/distributed/ConnectionRepository.py +++ b/direct/src/distributed/ConnectionRepository.py @@ -52,14 +52,19 @@ class ConnectionRepository( DoCollectionManager.__init__(self) self.setPythonRepository(self) - base.finalExitCallbacks.append(self.shutdown) - - self.config = config - # Create a unique ID number for each ConnectionRepository in # the world, helpful for sending messages specific to each one. 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'): self.setVerbose(1) @@ -510,6 +515,7 @@ class ConnectionRepository( else: print "uh oh, we aren't using one of the tri-state CM variables" failureCallback(0, '', *failureArgs) + def disconnect(self): """ Closes the previously-established connection. @@ -519,6 +525,10 @@ class ConnectionRepository( CConnectionRepository.disconnect(self) self.stopReaderPollTask() + def shutdown(self): + self.ignoreAll() + CConnectionRepository.shutdown(self) + def httpConnectCallback(self, ch, serverList, serverIndex, successCallback, successArgs, failureCallback, failureArgs): @@ -597,7 +607,6 @@ class ConnectionRepository( def readerPollUntilEmpty(self, task): while self.readerPollOnce(): pass - Thread.forceYield() return Task.cont def readerPollOnce(self): @@ -609,7 +618,7 @@ class ConnectionRepository( # Unable to receive a datagram: did we lose the connection? if not self.isConnected(): self.stopReaderPollTask() - self.lostConnection() + messenger.send(self.uniqueName('lostConnection'), taskChain = 'default') return 0 def handleReaderOverflow(self):