diff options
-rw-r--r-- | tulip/selectors.py | 50 | ||||
-rw-r--r-- | tulip/unix_events.py | 28 |
2 files changed, 39 insertions, 39 deletions
diff --git a/tulip/selectors.py b/tulip/selectors.py index d3f16a3..8af5e5f 100644 --- a/tulip/selectors.py +++ b/tulip/selectors.py @@ -11,11 +11,11 @@ from select import * # generic events, that must be mapped to implementation-specific ones # read event -SELECT_IN = (1 << 0) +EVENT_READ = (1 << 0) # write event -SELECT_OUT = (1 << 1) +EVENT_WRITE = (1 << 1) # connect event -SELECT_CONNECT = SELECT_OUT +EVENT_CONNECT = EVENT_WRITE def _fileobj_to_fd(fileobj): @@ -79,13 +79,13 @@ class _BaseSelector: Parameters: fileobj -- file object - events -- events to monitor (bitwise mask of SELECT_IN|SELECT_OUT) + events -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE) data -- attached data Returns: SelectorKey instance """ - if (not events) or (events & ~(SELECT_IN|SELECT_OUT)): + if (not events) or (events & ~(EVENT_READ|EVENT_WRITE)): raise ValueError("Invalid events: {}".format(events)) if fileobj in self._fileobj_to_key: @@ -118,7 +118,7 @@ class _BaseSelector: Parameters: fileobj -- file object - events -- events to monitor (bitwise mask of SELECT_IN|SELECT_OUT) + events -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE) data -- attached data """ self.unregister(fileobj) @@ -138,7 +138,7 @@ class _BaseSelector: Returns: list of (fileobj, events, attached data) for ready file objects - `events` is a bitwise mask of SELECT_IN|SELECT_OUT + `events` is a bitwise mask of EVENT_READ|EVENT_WRITE """ raise NotImplementedError() @@ -204,9 +204,9 @@ class SelectSelector(_BaseSelector): def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) - if events & SELECT_IN: + if events & EVENT_READ: self._readers.add(key.fd) - if events & SELECT_OUT: + if events & EVENT_WRITE: self._writers.add(key.fd) return key @@ -228,9 +228,9 @@ class SelectSelector(_BaseSelector): for fd in r | w: events = 0 if fd in r: - events |= SELECT_IN + events |= EVENT_READ if fd in w: - events |= SELECT_OUT + events |= EVENT_WRITE key = self._key_from_fd(fd) if key: @@ -257,9 +257,9 @@ if 'poll' in globals(): def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) poll_events = 0 - if events & SELECT_IN: + if events & EVENT_READ: poll_events |= POLLIN - if events & SELECT_OUT: + if events & EVENT_WRITE: poll_events |= POLLOUT self._poll.register(key.fd, poll_events) return key @@ -280,9 +280,9 @@ if 'poll' in globals(): for fd, event in fd_event_list: events = 0 if event & ~POLLIN: - events |= SELECT_OUT + events |= EVENT_WRITE if event & ~POLLOUT: - events |= SELECT_IN + events |= EVENT_READ key = self._key_from_fd(fd) if key: @@ -302,9 +302,9 @@ if 'epoll' in globals(): def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) epoll_events = 0 - if events & SELECT_IN: + if events & EVENT_READ: epoll_events |= EPOLLIN - if events & SELECT_OUT: + if events & EVENT_WRITE: epoll_events |= EPOLLOUT self._epoll.register(key.fd, epoll_events) return key @@ -326,9 +326,9 @@ if 'epoll' in globals(): for fd, event in fd_event_list: events = 0 if event & ~EPOLLIN: - events |= SELECT_OUT + events |= EVENT_WRITE if event & ~EPOLLOUT: - events |= SELECT_IN + events |= EVENT_READ key = self._key_from_fd(fd) if key: @@ -352,20 +352,20 @@ if 'kqueue' in globals(): def unregister(self, fileobj): key = super().unregister(fileobj) mask = 0 - if key.events & SELECT_IN: + if key.events & EVENT_READ: kev = kevent(key.fd, KQ_FILTER_READ, KQ_EV_DELETE) self._kqueue.control([kev], 0, 0) - if key.events & SELECT_OUT: + if key.events & EVENT_WRITE: kev = kevent(key.fd, KQ_FILTER_WRITE, KQ_EV_DELETE) self._kqueue.control([kev], 0, 0) return key def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) - if events & SELECT_IN: + if events & EVENT_READ: kev = kevent(key.fd, KQ_FILTER_READ, KQ_EV_ADD) self._kqueue.control([kev], 0, 0) - if events & SELECT_OUT: + if events & EVENT_WRITE: kev = kevent(key.fd, KQ_FILTER_WRITE, KQ_EV_ADD) self._kqueue.control([kev], 0, 0) return key @@ -383,9 +383,9 @@ if 'kqueue' in globals(): flag = kev.filter events = 0 if flag == KQ_FILTER_READ: - events |= SELECT_IN + events |= EVENT_READ if flag == KQ_FILTER_WRITE: - events |= SELECT_OUT + events |= EVENT_WRITE key = self._key_from_fd(fd) if key: diff --git a/tulip/unix_events.py b/tulip/unix_events.py index 685a576..fc32cba 100644 --- a/tulip/unix_events.py +++ b/tulip/unix_events.py @@ -393,10 +393,10 @@ class UnixEventLoop(events.EventLoop): try: mask, (reader, writer, connector) = self._selector.get_info(fd) except KeyError: - self._selector.register(fd, selectors.SELECT_IN, + self._selector.register(fd, selectors.EVENT_READ, (handler, None, None)) else: - self._selector.modify(fd, mask | selectors.SELECT_IN, + self._selector.modify(fd, mask | selectors.EVENT_READ, (handler, writer, connector)) return handler @@ -408,7 +408,7 @@ class UnixEventLoop(events.EventLoop): except KeyError: return False else: - mask &= ~selectors.SELECT_IN + mask &= ~selectors.EVENT_READ if not mask: self._selector.unregister(fd) else: @@ -421,10 +421,10 @@ class UnixEventLoop(events.EventLoop): try: mask, (reader, writer, connector) = self._selector.get_info(fd) except KeyError: - self._selector.register(fd, selectors.SELECT_OUT, + self._selector.register(fd, selectors.EVENT_WRITE, (None, handler, None)) else: - self._selector.modify(fd, mask | selectors.SELECT_OUT, + self._selector.modify(fd, mask | selectors.EVENT_WRITE, (reader, handler, connector)) return handler @@ -435,7 +435,7 @@ class UnixEventLoop(events.EventLoop): except KeyError: return False else: - mask &= ~selectors.SELECT_OUT + mask &= ~selectors.EVENT_WRITE if not mask: self._selector.unregister(fd) else: @@ -444,16 +444,16 @@ class UnixEventLoop(events.EventLoop): def add_connector(self, fd, callback, *args): """Add a connector callback. Return a Handler instance.""" - # XXX As long as SELECT_CONNECT == SELECT_OUT, set the handler + # XXX As long as EVENT_CONNECT == EVENT_WRITE, set the handler # as both writer and connector. handler = events.make_handler(None, callback, args) try: mask, (reader, writer, connector) = self._selector.get_info(fd) except KeyError: - self._selector.register(fd, selectors.SELECT_CONNECT, + self._selector.register(fd, selectors.EVENT_CONNECT, (None, handler, handler)) else: - self._selector.modify(fd, mask | selectors.SELECT_CONNECT, + self._selector.modify(fd, mask | selectors.EVENT_CONNECT, (reader, handler, handler)) return handler @@ -464,7 +464,7 @@ class UnixEventLoop(events.EventLoop): except KeyError: return False else: - mask &= ~selectors.SELECT_CONNECT + mask &= ~selectors.EVENT_CONNECT if not mask: self._selector.unregister(fd) else: @@ -724,19 +724,19 @@ class UnixEventLoop(events.EventLoop): level = logging.DEBUG logging.log(level, 'poll%s took %.3f seconds', argstr, t1-t0) for fileobj, mask, (reader, writer, connector) in event_list: - if mask & selectors.SELECT_IN and reader is not None: + if mask & selectors.EVENT_READ and reader is not None: if reader.cancelled: self.remove_reader(fileobj) else: self._add_callback(reader) - if mask & selectors.SELECT_OUT and writer is not None: + if mask & selectors.EVENT_WRITE and writer is not None: if writer.cancelled: self.remove_writer(fileobj) else: self._add_callback(writer) # XXX The next elif is unreachable until selector.py - # changes to implement SELECT_CONNECT != SELECTOR_OUT. - elif mask & selectors.SELECT_CONNECT and connector is not None: + # changes to implement EVENT_CONNECT != EVENT_WRITE. + elif mask & selectors.EVENT_CONNECT and connector is not None: if connector.cancelled: self.remove_connector(fileobj) else: |