[Neo-report] r1912 vincent - in /trunk/neo: epoll.py event.py tests/testEvent.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Mar 8 11:59:17 CET 2010


Author: vincent
Date: Mon Mar  8 11:59:16 2010
New Revision: 1912

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

Modified:
    trunk/neo/epoll.py
    trunk/neo/event.py
    trunk/neo/tests/testEvent.py

Modified: trunk/neo/epoll.py
==============================================================================
--- trunk/neo/epoll.py [iso-8859-1] (original)
+++ trunk/neo/epoll.py [iso-8859-1] Mon Mar  8 11:59:16 2010
@@ -93,13 +93,17 @@
             else:
                 readable_fd_list = []
                 writable_fd_list = []
+                error_fd_list = []
                 for i in xrange(n):
                     ev = self.events[i]
-                    if ev.events & (EPOLLIN | EPOLLERR | EPOLLHUP):
-                        readable_fd_list.append(int(ev.data.fd))
-                    elif ev.events & EPOLLOUT:
-                        writable_fd_list.append(int(ev.data.fd))
-                return readable_fd_list, writable_fd_list
+                    fd = int(ev.data.fd)
+                    if ev.events & EPOLLIN:
+                        readable_fd_list.append(fd)
+                    if ev.events & EPOLLOUT:
+                        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):
         ev = EpollEvent()

Modified: trunk/neo/event.py
==============================================================================
--- trunk/neo/event.py [iso-8859-1] (original)
+++ trunk/neo/event.py [iso-8859-1] Mon Mar  8 11:59:16 2010
@@ -100,7 +100,7 @@
 
     def _poll(self, timeout = 1):
         assert timeout >= 0
-        rlist, wlist = self.epoll.poll(timeout)
+        rlist, wlist, elist = self.epoll.poll(timeout)
         r_done_set = set()
         for fd in rlist:
             if fd in r_done_set:
@@ -129,6 +129,24 @@
                 conn.lock()
                 try:
                     conn.writable()
+                finally:
+                    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()
 

Modified: trunk/neo/tests/testEvent.py
==============================================================================
--- trunk/neo/tests/testEvent.py [iso-8859-1] (original)
+++ trunk/neo/tests/testEvent.py [iso-8859-1] Mon Mar  8 11:59:16 2010
@@ -106,6 +106,7 @@
         em.epoll = Mock({"poll":(
           (r_connector.getDescriptor(),),
           (w_connector.getDescriptor(),),
+          (),
         )})
         em.poll(timeout=10)
         # check it called poll on epoll





More information about the Neo-report mailing list