summaryrefslogtreecommitdiffstats
path: root/Lib/asyncore.py
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2001-01-24 15:50:19 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2001-01-24 15:50:19 (GMT)
commitaf6963c2f07c9e163278045cd5aeef4356fe2161 (patch)
tree1afdc3d65d08dc1a7ee876b7be3b10caf28889be /Lib/asyncore.py
parent506f0b1fc6d44fbc1dffae47b0599ddc916dc596 (diff)
downloadcpython-af6963c2f07c9e163278045cd5aeef4356fe2161.zip
cpython-af6963c2f07c9e163278045cd5aeef4356fe2161.tar.gz
cpython-af6963c2f07c9e163278045cd5aeef4356fe2161.tar.bz2
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
Diffstat (limited to 'Lib/asyncore.py')
-rw-r--r--Lib/asyncore.py44
1 files changed, 40 insertions, 4 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index 8b585d4..f177692 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -145,16 +145,52 @@ def poll2 (timeout=0.0, map=None):
except KeyError:
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:
- poll_fun = poll2
+ if hasattr (select, 'poll'):
+ poll_fun = poll3
+ else:
+ poll_fun = poll2
else:
poll_fun = poll
- if map is None:
- map=socket_map
-
while map:
poll_fun (timeout, map)