Commit 1660dcbe authored by Vincent Pelletier's avatar Vincent Pelletier

Remove long-unused, bitrot and poorly scalable select event handler.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1515 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent eafd1f35
......@@ -89,125 +89,6 @@ class IdleEvent(object):
conn.unlock()
return False
class SelectEventManager(object):
"""This class manages connections and events based on select(2)."""
def __init__(self):
self.connection_dict = {}
self.reader_set = set([])
self.writer_set = set([])
self.exc_list = []
self.event_list = []
self.prev_time = time()
self._pending_processing = []
def getConnectionList(self):
return self.connection_dict.values()
def register(self, conn):
self.connection_dict[conn.getConnector()] = conn
def unregister(self, conn):
new_pending_processing = [x for x in self._pending_processing
if x is not conn]
# Check that we removed at most one entry from
# self._pending_processing .
assert len(new_pending_processing) > len(self._pending_processing) - 2
self._pending_processing = new_pending_processing
del self.connection_dict[conn.getConnector()]
def _getPendingConnection(self):
if len(self._pending_processing):
result = self._pending_processing.pop(0)
else:
result = None
return result
def _addPendingConnection(self, conn):
self._pending_processing.append(conn)
def poll(self, timeout = 1):
to_process = self._getPendingConnection()
if to_process is None:
# Fetch messages from polled file descriptors
self._poll(timeout=timeout)
# See if there is anything to process
to_process = self._getPendingConnection()
if to_process is not None:
try:
# Process
to_process.process()
finally:
# ...and requeue if there are pending messages
if to_process.hasPendingMessages():
self._addPendingConnection(to_process)
def _poll(self, timeout = 1):
rlist, wlist, xlist = select(self.reader_set, self.writer_set,
self.exc_list, timeout)
for s in rlist:
conn = self.connection_dict[s]
conn.lock()
try:
conn.readable()
finally:
conn.unlock()
if conn.hasPendingMessages():
self._addPendingConnection(conn)
for s in wlist:
# This can fail, if a connection is closed in readable().
try:
conn = self.connection_dict[s]
except KeyError:
pass
else:
conn.lock()
try:
conn.writable()
finally:
conn.unlock()
# Check idle events. Do not check them out too often, because this
# is somehow heavy.
event_list = self.event_list
if event_list:
t = time()
if t - self.prev_time >= 1:
self.prev_time = t
event_list.sort(key = lambda event: event.getTime(),
reverse = True)
while event_list:
event = event_list.pop()
if event(t):
try:
event_list.remove(event)
except ValueError:
pass
else:
break
def addIdleEvent(self, event):
self.event_list.append(event)
def removeIdleEvent(self, event):
try:
self.event_list.remove(event)
except ValueError:
pass
def addReader(self, conn):
self.reader_set.add(conn.getConnector())
def removeReader(self, conn):
self.reader_set.discard(conn.getConnector())
def addWriter(self, conn):
self.writer_set.add(conn.getConnector())
def removeWriter(self, conn):
self.writer_set.discard(conn.getConnector())
class EpollEventManager(object):
"""This class manages connections and events based on epoll(5)."""
......
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