Commit 1ea1dc9e authored by Julien Muchembled's avatar Julien Muchembled

Simplify EpollEventManager.poll

parent 02763c9a
...@@ -78,38 +78,32 @@ class EpollEventManager(object): ...@@ -78,38 +78,32 @@ class EpollEventManager(object):
self.epoll.unregister(fd) self.epoll.unregister(fd)
del self.connection_dict[fd] del self.connection_dict[fd]
def _getPendingConnection(self):
if self._pending_processing:
return self._pending_processing.pop(0)
def _addPendingConnection(self, conn): def _addPendingConnection(self, conn):
pending_processing = self._pending_processing pending_processing = self._pending_processing
if conn not in pending_processing: if conn not in pending_processing:
pending_processing.append(conn) pending_processing.append(conn)
def poll(self, timeout=1): def poll(self, timeout=1):
to_process = self._getPendingConnection() if not self._pending_processing:
if to_process is None:
# Fetch messages from polled file descriptors # Fetch messages from polled file descriptors
self._poll(timeout=timeout) self._poll(timeout=timeout)
# See if there is anything to process if not self._pending_processing:
to_process = self._getPendingConnection() return
if to_process is not None: to_process = self._pending_processing.pop(0)
to_process.lock() to_process.lock()
try:
try: try:
try: to_process.process()
# Process
to_process.process()
finally:
# ...and requeue if there are pending messages
if to_process.hasPendingMessages():
self._addPendingConnection(to_process)
finally: finally:
to_process.unlock() # ...and requeue if there are pending messages
# Non-blocking call: as we handled a packet, we should just offer if to_process.hasPendingMessages():
# poll a chance to fetch & send already-available data, but it must self._addPendingConnection(to_process)
# not delay us. finally:
self._poll(timeout=0) to_process.unlock()
# Non-blocking call: as we handled a packet, we should just offer
# poll a chance to fetch & send already-available data, but it must
# not delay us.
self._poll(timeout=0)
def _poll(self, timeout=1): def _poll(self, timeout=1):
try: try:
......
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