Commit b69cd29d authored by Vincent Pelletier's avatar Vincent Pelletier

Split handling of IN, OUT and (ERR | HUP) epoll events.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1912 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 815ff693
...@@ -93,13 +93,17 @@ class Epoll(object): ...@@ -93,13 +93,17 @@ class Epoll(object):
else: else:
readable_fd_list = [] readable_fd_list = []
writable_fd_list = [] writable_fd_list = []
error_fd_list = []
for i in xrange(n): for i in xrange(n):
ev = self.events[i] ev = self.events[i]
if ev.events & (EPOLLIN | EPOLLERR | EPOLLHUP): fd = int(ev.data.fd)
readable_fd_list.append(int(ev.data.fd)) if ev.events & EPOLLIN:
elif ev.events & EPOLLOUT: readable_fd_list.append(fd)
writable_fd_list.append(int(ev.data.fd)) if ev.events & EPOLLOUT:
return readable_fd_list, writable_fd_list writable_fd_list.append(fd)
if ev.events & (EPOLLERR | EPOLLHUP):
error_fd_list.append(fd)
return readable_fd_list, writable_fd_list, error_fd_list
def register(self, fd): def register(self, fd):
ev = EpollEvent() ev = EpollEvent()
......
...@@ -100,7 +100,7 @@ class EpollEventManager(object): ...@@ -100,7 +100,7 @@ class EpollEventManager(object):
def _poll(self, timeout = 1): def _poll(self, timeout = 1):
assert timeout >= 0 assert timeout >= 0
rlist, wlist = self.epoll.poll(timeout) rlist, wlist, elist = self.epoll.poll(timeout)
r_done_set = set() r_done_set = set()
for fd in rlist: for fd in rlist:
if fd in r_done_set: if fd in r_done_set:
...@@ -132,6 +132,24 @@ class EpollEventManager(object): ...@@ -132,6 +132,24 @@ class EpollEventManager(object):
finally: finally:
conn.unlock() conn.unlock()
e_done_set = set()
for fd in elist:
if fd in e_done_set:
continue
e_done_set.add(fd)
# This can fail, if a connection is closed in previous calls to
# readable() or writable().
try:
conn = self.connection_dict[fd]
except KeyError:
pass
else:
conn.lock()
try:
conn.readable()
finally:
conn.unlock()
t = time() t = time()
for conn in self.connection_dict.values(): for conn in self.connection_dict.values():
conn.lock() conn.lock()
......
...@@ -106,6 +106,7 @@ class EventTests(NeoTestBase): ...@@ -106,6 +106,7 @@ class EventTests(NeoTestBase):
em.epoll = Mock({"poll":( em.epoll = Mock({"poll":(
(r_connector.getDescriptor(),), (r_connector.getDescriptor(),),
(w_connector.getDescriptor(),), (w_connector.getDescriptor(),),
(),
)}) )})
em.poll(timeout=10) em.poll(timeout=10)
# check it called poll on epoll # check it called poll on epoll
......
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