def doIteration(self, timeout):
        # This function sits and waits for an IO completion event.
        #
        # There are two requirements: process IO events as soon as they arrive
        # and process ctrl-break from the user in a reasonable amount of time.
        #
        # There are three kinds of waiting.
        # 1) GetQueuedCompletionStatus (self.port.getEvent) to wait for IO
        # events only.
        # 2) Msg* family of wait functions that can stop waiting when
        # ctrl-break is detected (then, I think, Python converts it into a
        # KeyboardInterrupt)
        # 3) *Ex family of wait functions that put the thread into an
        # "alertable" wait state which is supposedly triggered by IO completion
        #
        # 2) and 3) can be combined. Trouble is, my IO completion is not
        # causing 3) to trigger, possibly because I do not use an IO completion
        # callback. Windows is weird.
        # There are two ways to handle this. I could use MsgWaitForSingleObject
        # here and GetQueuedCompletionStatus in a thread. Or I could poll with
        # a reasonable interval. Guess what! Threads are hard.

        processed_events = 0
        if timeout is None:
            timeout = MAX_TIMEOUT
        else:
            timeout = min(MAX_TIMEOUT, int(1000*timeout))
        rc, bytes, key, evt = self.port.getEvent(timeout)
        while processed_events < EVENTS_PER_LOOP:
            if rc == WAIT_TIMEOUT:
                break
            if key != KEY_WAKEUP:
                assert key == KEY_NORMAL
                if not evt.ignore:
                    log.callWithLogger(evt.owner, self._callEventCallback,
                                       rc, bytes, evt)
                    processed_events += 1
            rc, bytes, key, evt = self.port.getEvent(0)
dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/internet/iocpreactor/reactor.py/IOCPReactor.doIteration/original