[Zodb-checkins] CVS: Packages/ZEO - zrpc.py:1.14

Jim Fulton jim@digicool.com
Sun, 1 Apr 2001 14:41:15 -0400 (EDT)


Update of /cvs-repository/Packages/ZEO
In directory korak:/tmp/cvs-serv19452

Modified Files:
	zrpc.py 
Log Message:
- Renamed and commented the flag formerly known as __map.

- Commented the Wakeup calls.  

- Fixed a bug in the reconnection logic that caused the
  dispatcher to get reinitialized incorrectly when a main loop
  was active. This could cause a client to seem to hang on occasions.



--- Updated File zrpc.py in package Packages/ZEO --
--- zrpc.py	2001/03/27 23:43:32	1.13
+++ zrpc.py	2001/04/01 18:41:13	1.14
@@ -107,7 +107,9 @@
 
 class asyncRPC(SizedMessageAsyncConnection):
 
-    __map=0
+    # Flag indicating whether a main loop is running. If one isn't running,
+    # then we'll have to provide our own main loop at times.
+    __haveMainLoop=0  
     def __Wakeup(*args): pass
 
     def __init__(self, connection, outOfBand=None, tmin=5, tmax=300, debug=0):
@@ -159,7 +161,9 @@
                 return 1
 
     def finishConnect(self, s):
-        SizedMessageAsyncConnection.__init__(self, s, '', {})
+        if self.__haveMainLoop: map=None # use the main loop map
+        else: map = {} # provide a dummy map
+        SizedMessageAsyncConnection.__init__(self, s, '', map)
 
     # we are our own socket map!
     def keys(self): return (self._fileno,)
@@ -171,7 +175,7 @@
         raise KeyError, key
 
     def sync(self):
-        if self.__map: return # in async mode
+        if self.__haveMainLoop: return # in async mode
 
         # Ick, I have to do my own select loop, which sucks
         while 1:
@@ -188,10 +192,10 @@
         self.__lr()
 
     def setLoop(self, map=None, Wakeup=lambda : None):
-        if map is None: self.__map=0
+        if map is None: self.__haveMainLoop=0
         else:
             self.add_channel(map) # asyncore registration
-            self.__map=1
+            self.__haveMainLoop=1
 
         self.__Wakeup=Wakeup
 
@@ -202,7 +206,8 @@
             self._last_args=args=dump(args,1)
             self.message_output(args)
 
-            if self.__map: self.__Wakeup() # You dumb bastard
+            if self.__haveMainLoop:
+                self.__Wakeup() # Wakeup the main loop
             else: self.readLoop()
 
             while 1:
@@ -231,7 +236,8 @@
 
     def sendMessage(self, *args):
         self.message_output(dump(args,1))
-        if self.__map: self.__Wakeup() # You dumb bastard
+        if self.__haveMainLoop:
+            self.__Wakeup() # Wake up the main loop
         else: asyncore.poll(0.0, self)
 
     def setOutOfBand(self, f):
@@ -275,8 +281,10 @@
         return self.__r
 
     def closeIntensionally(self):
-        if self.__map:
-            self.__Wakeup(lambda self=self: self.close()) # You dumb bastard
+        if self.__haveMainLoop:
+            # We aren't willing to close until told to by the main loop.
+            # So we'll tell the main loop to tell us. :)
+            self.__Wakeup(lambda self=self: self.close()) 
         else: self.close()
         
     def close(self):