loopimpl.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:eventloop 作者: OshynSong 项目源码 文件源码
def poll(self, timeout):
        if timeout < 0:
            timeout = None
        kevents = self._kqueue.control(None, KQueueLoop.MAX_EVENTS, timeout)
        events = {}
        for ke in kevents:
            fd = ke.ident
            if ke.filter == select.KQ_FILTER_READ:
                events[fd] = events.get(fd, 0) | EVENT_READ
            if ke.filter == select.KQ_FILTER_WRITE:
                if ke.flags & select.KQ_EV_EOF:
                    # If an asynchronous connection is refused, kqueue
                    # returns a write event with the EOF flag set.
                    # Turn this into an error for consistency with the
                    # other IOLoop implementations.
                    # Note that for read events, EOF may be returned before
                    # all data has been consumed from the socket buffer,
                    # so we only check for EOF on write events.
                    events[fd] = EVENT_ERROR
                else:
                    events[fd] = events.get(fd, 0) | EVENT_WRITE
            if ke.flags & select.KQ_EV_ERROR:
                events[fd] = events.get(fd, 0) | EVENT_ERROR
        return events.iteritems()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号