[Python-checkins] CVS: python/dist/src/Lib asyncore.py,1.8,1.9

A.M. Kuchling akuchling@users.sourceforge.net
Wed, 24 Jan 2001 07:50:21 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv27203

Modified Files:
	asyncore.py 
Log Message:
Updated version of asyncore.py from Sam Rushing:
    Adds support for using select.poll() if it's available

    Move a 'map is None' test out of an else branch and into the right place


Index: asyncore.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/asyncore.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** asyncore.py	2001/01/14 18:09:23	1.8
--- asyncore.py	2001/01/24 15:50:19	1.9
***************
*** 146,158 ****
                  pass
  
  def loop (timeout=30.0, use_poll=0, map=None):
  
      if use_poll:
!         poll_fun = poll2
      else:
          poll_fun = poll
- 
-         if map is None:
-             map=socket_map
  
      while map:
--- 146,194 ----
                  pass
  
+ def poll3 (timeout=0.0, map=None):
+     # Use the poll() support added to the select module in Python 2.0
+     if map is None:
+         map=socket_map
+     # timeout is in milliseconds
+     timeout = int(timeout*1000)
+     pollster = select.poll()
+     if map:
+         l = []
+         for fd, obj in map.items():
+             flags = 0
+             if obj.readable():
+                 flags = select.POLLIN
+             if obj.writable():
+                 flags = flags | select.POLLOUT
+             if flags:
+                 pollster.register(fd, flags)
+         r = pollster.poll (timeout)
+         for fd, flags in r:
+             try:
+                 obj = map[fd]
+                 try:
+                     if (flags  & select.POLLIN):
+                         obj.handle_read_event()
+                     if (flags & select.POLLOUT):
+                         obj.handle_write_event()
+                 except ExitNow:
+                     raise ExitNow
+                 except:
+                     obj.handle_error()
+             except KeyError:
+                 pass
+ 
  def loop (timeout=30.0, use_poll=0, map=None):
  
+     if map is None:
+         map=socket_map
+ 
      if use_poll:
!         if hasattr (select, 'poll'):
!             poll_fun = poll3
!         else:
!             poll_fun = poll2
      else:
          poll_fun = poll
  
      while map: