Commit 097890fc authored by Denis Bilenko's avatar Denis Bilenko

simplify implementation for select

parent 1e94acd1
......@@ -2,7 +2,7 @@
from gevent.timeout import Timeout
from gevent.event import Event
from gevent.core import MAXPRI, READ, WRITE, EVENTS
from gevent.core import MAXPRI, READ, WRITE
from gevent.hub import get_hub
__implements__ = ['select']
......@@ -32,13 +32,13 @@ class SelectResult(object):
self.write = []
self.event = Event()
def update(self, events, socket):
if events & READ:
self.read.append(socket)
self.event.set()
elif events & WRITE:
self.write.append(socket)
self.event.set()
def add_read(self, socket):
self.read.append(socket)
self.event.set()
def add_write(self, socket):
self.write.append(socket)
self.event.set()
def select(rlist, wlist, xlist, timeout=None):
......@@ -55,12 +55,12 @@ def select(rlist, wlist, xlist, timeout=None):
for readfd in rlist:
watcher = io(get_fileno(readfd), 1)
watcher.priority = MAXPRI
watcher.start(result.update, EVENTS, readfd)
watcher.start(result.add_read, readfd)
watchers.append(watcher)
for writefd in wlist:
watcher = io(get_fileno(writefd), 2)
watcher.priority = MAXPRI
watcher.start(result.update, EVENTS, writefd)
watcher.start(result.add_write, writefd)
watchers.append(watcher)
except IOError, ex:
raise error(*ex.args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment