Ticket #5158: twisted_std_epoll.2.patch

File twisted_std_epoll.2.patch, 5.1 KB (added by jell, 4 years ago)

fixed patch with some missing parts

  • python/_epoll.pyx

     
    124124        if result == -1:
    125125            raise IOError(errno, strerror(errno))
    126126
    127     def wait(self, unsigned int maxevents, int timeout):
     127    def register(self, int fd, int eventmask=0):
     128        self._control(CTL_ADD, fd, eventmask)
     129
     130    def unregister(self, int fd):
     131        self._control(CTL_ADD, fd)
     132
     133    def modify(self, inft fd, int eventmask):
     134        self._control(CTL_MOD, fd, eventmask)
     135
     136    def poll(self, unsigned int maxevents, int timeout):
    128137        """
    129         Wait for an I/O event, wrap epoll_wait(2).
     138        Poll for an I/O event, wrap epoll_wait(2).
    130139
    131140        @type maxevents: C{int}
    132141        @param maxevents: Maximum number of events returned.
     
    166175CTL_DEL = EPOLL_CTL_DEL
    167176CTL_MOD = EPOLL_CTL_MOD
    168177
    169 IN = EPOLLIN
    170 OUT = EPOLLOUT
    171 PRI = EPOLLPRI
    172 ERR = EPOLLERR
    173 HUP = EPOLLHUP
    174 ET = EPOLLET
     178EPOLLIN = EPOLLIN
     179EPOLLOUT = EPOLLOUT
     180EPOLLPRI = EPOLLPRI
     181EPOLLERR = EPOLLERR
     182EPOLLHUP = EPOLLHUP
     183EPOLLET = EPOLLET
    175184
    176 RDNORM = EPOLLRDNORM
    177 RDBAND = EPOLLRDBAND
    178 WRNORM = EPOLLWRNORM
    179 WRBAND = EPOLLWRBAND
    180 MSG = EPOLLMSG
     185EPOLLRDNORM = EPOLLRDNORM
     186EPOLLRDBAND = EPOLLRDBAND
     187EPOLLWRNORM = EPOLLWRNORM
     188EPOLLWRBAND = EPOLLWRBAND
     189EPOLLMSG = EPOLLMSG
    181190
  • internet/epollreactor.py

     
    1717
    1818from twisted.internet.interfaces import IReactorFDSet
    1919
    20 from twisted.python import log, _epoll
     20from twisted.python import log
     21try:
     22   from select import epoll as _epoll
     23except ImportError:
     24   from twisted.python import _epoll
     25
    2126from twisted.internet import posixbase
    2227
    2328
     
    4954    implements(IReactorFDSet)
    5055
    5156    # Attributes for _PollLikeMixin
    52     _POLL_DISCONNECTED = (_epoll.HUP | _epoll.ERR)
    53     _POLL_IN = _epoll.IN
    54     _POLL_OUT = _epoll.OUT
     57    _POLL_DISCONNECTED = (_epoll.EPOLLHUP | _epoll.EPOLLERR)
     58    _POLL_IN = _epoll.EPOLLIN
     59    _POLL_OUT = _epoll.EPOLLOUT
    5560
    5661    def __init__(self):
    5762        """
     
    7681        """
    7782        fd = xer.fileno()
    7883        if fd not in primary:
    79             cmd = _epoll.CTL_ADD
     84            cmd = self._poller.register
    8085            flags = event
    8186            if fd in other:
    8287                flags |= antievent
    83                 cmd = _epoll.CTL_MOD
     88                cmd = self._poller.modify
    8489            # epoll_ctl can raise all kinds of IOErrors, and every one
    8590            # indicates a bug either in the reactor or application-code.
    8691            # Let them all through so someone sees a traceback and fixes
    8792            # something.  We'll do the same thing for every other call to
    8893            # this method in this file.
    89             self._poller._control(cmd, fd, flags)
     94            cmd(fd, flags)
    9095
    9196            # Update our own tracking state *only* after the epoll call has
    9297            # succeeded.  Otherwise we may get out of sync.
     
    98103        """
    99104        Add a FileDescriptor for notification of data available to read.
    100105        """
    101         self._add(reader, self._reads, self._writes, self._selectables, _epoll.IN, _epoll.OUT)
     106        self._add(reader, self._reads, self._writes, self._selectables, _epoll.IN, _epoll.EPOLLOUT)
    102107
    103108
    104109    def addWriter(self, writer):
    105110        """
    106111        Add a FileDescriptor for notification of data available to write.
    107112        """
    108         self._add(writer, self._writes, self._reads, self._selectables, _epoll.OUT, _epoll.IN)
     113        self._add(writer, self._writes, self._reads, self._selectables, _epoll.OUT, _epoll.EPOLLIN)
    109114
    110115
    111116    def _remove(self, xer, primary, other, selectables, event, antievent):
     
    123128            else:
    124129                return
    125130        if fd in primary:
    126             cmd = _epoll.CTL_DEL
    127131            flags = event
    128132            if fd in other:
    129133                flags = antievent
    130                 cmd = _epoll.CTL_MOD
     134                self._poller.modify(fd, flags)
    131135            else:
     136                self._poller.unregister(fd)
    132137                del selectables[fd]
    133138            del primary[fd]
    134             # See comment above _control call in _add.
    135             self._poller._control(cmd, fd, flags)
    136139
    137140
    138141    def removeReader(self, reader):
    139142        """
    140143        Remove a Selectable for notification of data available to read.
    141144        """
    142         self._remove(reader, self._reads, self._writes, self._selectables, _epoll.IN, _epoll.OUT)
     145        self._remove(reader, self._reads, self._writes, self._selectables, _epoll.EPOLLIN, _epoll.EPOLLOUT)
    143146
    144147
    145148    def removeWriter(self, writer):
     
    178181            # currently tracking (because that's maybe a good heuristic) and
    179182            # the amount of time we block to the value specified by our
    180183            # caller.
    181             l = self._poller.wait(len(self._selectables), timeout)
     184            l = self._poller.poll(len(self._selectables), timeout)
    182185        except IOError, err:
    183186            if err.errno == errno.EINTR:
    184187                return