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

simplify implementation for select

parent 1e94acd1
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
from gevent.timeout import Timeout from gevent.timeout import Timeout
from gevent.event import Event 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 from gevent.hub import get_hub
__implements__ = ['select'] __implements__ = ['select']
...@@ -32,11 +32,11 @@ class SelectResult(object): ...@@ -32,11 +32,11 @@ class SelectResult(object):
self.write = [] self.write = []
self.event = Event() self.event = Event()
def update(self, events, socket): def add_read(self, socket):
if events & READ:
self.read.append(socket) self.read.append(socket)
self.event.set() self.event.set()
elif events & WRITE:
def add_write(self, socket):
self.write.append(socket) self.write.append(socket)
self.event.set() self.event.set()
...@@ -55,12 +55,12 @@ def select(rlist, wlist, xlist, timeout=None): ...@@ -55,12 +55,12 @@ def select(rlist, wlist, xlist, timeout=None):
for readfd in rlist: for readfd in rlist:
watcher = io(get_fileno(readfd), 1) watcher = io(get_fileno(readfd), 1)
watcher.priority = MAXPRI watcher.priority = MAXPRI
watcher.start(result.update, EVENTS, readfd) watcher.start(result.add_read, readfd)
watchers.append(watcher) watchers.append(watcher)
for writefd in wlist: for writefd in wlist:
watcher = io(get_fileno(writefd), 2) watcher = io(get_fileno(writefd), 2)
watcher.priority = MAXPRI watcher.priority = MAXPRI
watcher.start(result.update, EVENTS, writefd) watcher.start(result.add_write, writefd)
watchers.append(watcher) watchers.append(watcher)
except IOError, ex: except IOError, ex:
raise error(*ex.args) 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