[Zodb-checkins] CVS: ZODB3/ZEO/zrpc - connection.py:1.16

Jeremy Hylton jeremy@zope.com
Sat, 7 Sep 2002 20:16:39 -0400


Update of /cvs-repository/ZODB3/ZEO/zrpc
In directory cvs.zope.org:/tmp/cvs-serv5940

Modified Files:
	connection.py 
Log Message:
Add pending() method to Connection.


=== ZODB3/ZEO/zrpc/connection.py 1.15 => 1.16 ===
--- ZODB3/ZEO/zrpc/connection.py:1.15	Sat Sep  7 19:45:09 2002
+++ ZODB3/ZEO/zrpc/connection.py	Sat Sep  7 20:16:38 2002
@@ -12,6 +12,7 @@
 #
 ##############################################################################
 import asyncore
+import errno
 import select
 import sys
 import threading
@@ -331,6 +332,7 @@
         self.thr_async = 1
 
     def is_async(self):
+        # overridden for ManagedConnection
         if self.thr_async:
             return 1
         else:
@@ -367,6 +369,36 @@
         else:
             asyncore.poll(0.0, self._map)
 
+    def pending(self):
+        """Invoke mainloop until any pending messages are handled."""
+        if __debug__:
+            log("pending(), async=%d" % self.is_async(), level=zLOG.TRACE)
+        if self.is_async():
+            return
+        # Inline the asyncore poll3 function to know whether any input
+        # was actually read.  Repeat until know input is ready.
+        # XXX This only does reads.
+        poll = select.poll()
+        poll.register(self._fileno, select.POLLIN)
+        # put dummy value in r so we enter the while loop the first time
+        r = [(self._fileno, None)]
+        while r:
+            try:
+                r = poll.poll()
+            except select.error, err:
+                if err[0] == errno.EINTR:
+                    continue
+                else:
+                    raise
+            if r:
+                try:
+                    self.handle_read_event()
+                except asyncore.ExitNow:
+                    raise
+                else:
+                    self.handle_error()
+                    
+
 class ServerConnection(Connection):
     """Connection on the server side"""
 
@@ -423,6 +455,7 @@
         return 0
 
     def is_async(self):
+        # XXX could the check_mgr_async() be avoided on each test?
         if self.thr_async:
             return 1
         return self.check_mgr_async()