Ejemplo n.º 1
0
 def test_create(self):
     """
     Test the creation of an epoll object.
     """
     try:
         p = _epoll.epoll(16)
     except OSError, e:
         raise unittest.FailTest(str(e))
Ejemplo n.º 2
0
 def test_create(self):
     """
     Test the creation of an epoll object.
     """
     try:
         p = _epoll.epoll(16)
     except OSError, e:
         raise unittest.FailTest(str(e))
Ejemplo n.º 3
0
 def __init__(self):
     """
     Initialize epoll object, file descriptor tracking dictionaries, and the
     base class.
     """
     # Create the poller we're going to use.  The 1024 here is just a hint
     # to the kernel, it is not a hard maximum.
     self._poller = _epoll.epoll(1024)
     self._reads = {}
     self._writes = {}
     self._selectables = {}
     posixbase.PosixReactorBase.__init__(self)
Ejemplo n.º 4
0
    def test_add(self):
        """
        Test adding a socket to an epoll object.
        """
        server, client = self._connectedPair()

        p = _epoll.epoll(2)
        try:
            p._control(_epoll.CTL_ADD, server.fileno(), _epoll.IN | _epoll.OUT)
            p._control(_epoll.CTL_ADD, client.fileno(), _epoll.IN | _epoll.OUT)
        finally:
            p.close()
Ejemplo n.º 5
0
 def __init__(self):
     """
     Initialize epoll object, file descriptor tracking dictionaries, and the
     base class.
     """
     # Create the poller we're going to use.  The 1024 here is just a hint
     # to the kernel, it is not a hard maximum.
     self._poller = _epoll.epoll(1024)
     self._reads = {}
     self._writes = {}
     self._selectables = {}
     posixbase.PosixReactorBase.__init__(self)
Ejemplo n.º 6
0
    def test_add(self):
        """
        Test adding a socket to an epoll object.
        """
        server, client = self._connectedPair()

        p = _epoll.epoll(2)
        try:
            p._control(_epoll.CTL_ADD, server.fileno(), _epoll.IN | _epoll.OUT)
            p._control(_epoll.CTL_ADD, client.fileno(), _epoll.IN | _epoll.OUT)
        finally:
            p.close()
 def __init__(self):
     """
     Initialize epoll object, file descriptor tracking dictionaries, and the
     base class.
     """
     # Create the poller we're going to use.  The 1024 here is just a hint to
     # the kernel, it is not a hard maximum.  After Linux 2.6.8, the size
     # argument is completely ignored.
     self._poller = _epoll.epoll(1024)
     self._reads = {}
     self._writes = {}
     self._selectables = {}
     posixbase.PosixReactorBase.__init__(self)
Ejemplo n.º 8
0
 def __init__(self):
     """
     Initialize epoll object, file descriptor tracking dictionaries, and the
     base class.
     """
     # Create the poller we're going to use.  The 1024 here is just a hint to
     # the kernel, it is not a hard maximum.  After Linux 2.6.8, the size
     # argument is completely ignored.
     self._poller = _epoll.epoll(1024)
     self._reads = {}
     self._writes = {}
     self._selectables = {}
     posixbase.PosixReactorBase.__init__(self)
Ejemplo n.º 9
0
    def test_controlAndWait(self):
        """
        Test waiting on an epoll object which has had some sockets added to
        it.
        """
        client, server = self._connectedPair()

        p = _epoll.epoll(16)
        p._control(_epoll.CTL_ADD, client.fileno(), _epoll.IN | _epoll.OUT |
                   _epoll.ET)
        p._control(_epoll.CTL_ADD, server.fileno(), _epoll.IN | _epoll.OUT |
                   _epoll.ET)

        now = time.time()
        events = untilConcludes(p.wait, 4, 1000)
        then = time.time()
        self.failIf(then - now > 0.01)

        events.sort()
        expected = [(client.fileno(), _epoll.OUT),
                    (server.fileno(), _epoll.OUT)]
        expected.sort()

        self.assertEquals(events, expected)

        now = time.time()
        events = untilConcludes(p.wait, 4, 200)
        then = time.time()
        self.failUnless(then - now > 0.1)
        self.failIf(events)

        client.send("Hello!")
        server.send("world!!!")

        now = time.time()
        events = untilConcludes(p.wait, 4, 1000)
        then = time.time()
        self.failIf(then - now > 0.01)

        events.sort()
        expected = [(client.fileno(), _epoll.IN | _epoll.OUT),
                    (server.fileno(), _epoll.IN | _epoll.OUT)]
        expected.sort()

        self.assertEquals(events, expected)
Ejemplo n.º 10
0
    def test_controlAndWait(self):
        """
        Test waiting on an epoll object which has had some sockets added to
        it.
        """
        client, server = self._connectedPair()

        p = _epoll.epoll(16)
        p._control(_epoll.CTL_ADD, client.fileno(),
                   _epoll.IN | _epoll.OUT | _epoll.ET)
        p._control(_epoll.CTL_ADD, server.fileno(),
                   _epoll.IN | _epoll.OUT | _epoll.ET)

        now = time.time()
        events = p.wait(4, 1000)
        then = time.time()
        self.failIf(then - now > 0.01)

        events.sort()
        expected = [(client.fileno(), _epoll.OUT),
                    (server.fileno(), _epoll.OUT)]
        expected.sort()

        self.assertEquals(events, expected)

        now = time.time()
        events = p.wait(4, 200)
        then = time.time()
        self.failUnless(then - now > 0.1)
        self.failIf(events)

        client.send("Hello!")
        server.send("world!!!")

        now = time.time()
        events = p.wait(4, 1000)
        then = time.time()
        self.failIf(then - now > 0.01)

        events.sort()
        expected = [(client.fileno(), _epoll.IN | _epoll.OUT),
                    (server.fileno(), _epoll.IN | _epoll.OUT)]
        expected.sort()

        self.assertEquals(events, expected)
Ejemplo n.º 11
0
        client.send("Hello!")
        server.send("world!!!")

        now = time.time()
        events = untilConcludes(p.wait, 4, 1000)
        then = time.time()
        self.failIf(then - now > 0.01)

        events.sort()
        expected = [(client.fileno(), _epoll.IN | _epoll.OUT),
                    (server.fileno(), _epoll.IN | _epoll.OUT)]
        expected.sort()

        self.assertEquals(events, expected)

if _epoll is None:
    EPoll.skip = "_epoll module unavailable"
else:
    try:
        e = _epoll.epoll(16)
    except IOError, exc:
        if exc.errno == errno.ENOSYS:
            del exc
            EPoll.skip = "epoll support missing from platform"
        else:
            raise
    else:
        e.close()
        del e
Ejemplo n.º 12
0
        client.send("Hello!")
        server.send("world!!!")

        now = time.time()
        events = p.wait(4, 1000)
        then = time.time()
        self.failIf(then - now > 0.01)

        events.sort()
        expected = [(client.fileno(), _epoll.IN | _epoll.OUT),
                    (server.fileno(), _epoll.IN | _epoll.OUT)]
        expected.sort()

        self.assertEquals(events, expected)


if _epoll is None:
    EPoll.skip = "_epoll module unavailable"
else:
    try:
        e = _epoll.epoll(16)
    except IOError, exc:
        if exc.errno == errno.ENOSYS:
            del exc
            EPoll.skip = "epoll support missing from platform"
        else:
            raise
    else:
        e.close()
        del e
Ejemplo n.º 13
0
# Twisted imports
from twisted.python import _epoll
from twisted.python import log
from twisted.internet import main, posixbase, error

# globals. They're often passed as default arguments for performance purpose.
reads = {}
writes = {}
selectables = {}

# Create the poller we're going to use (we should really do this in __init__
# of the reactor - but hey, poorly thought out globals like this are
# practically a design pattern in Twisted reactors.  The 1024 here is just a
# hint to the kernel, it is not a hard maximum.
poller = _epoll.epoll(1024)

class EPollReactor(posixbase.PosixReactorBase):
    """
    A reactor that uses epoll(4).
    """

    def _add(self, xer, primary, other, selectables, event, antievent):
        """
        Private method for adding a descriptor from the event loop.

        It takes care of adding it if  new or modifying it if already added
        for another state (read -> read/write for example).
        """
        fd = xer.fileno()
        if fd not in primary: