zoukankan      html  css  js  c++  java
  • libevent(六)事件监听

    libevent是如何实现事件监听的呢?

    在Linux,libevent的底层实现是epoll,因此实现事件监听的方式就是,把需要监听的fd加入epoll中。

    I/O事件

    定时器事件

    定时器事件没有fd,那么如何监听呢?

    这里先看下epoll_wait这个函数

    int epoll_wait(int epfd, struct epoll_event *events,
                          int maxevents, int timeout);
    // The timeout argument specifies the number of milliseconds that epoll_wait() will block.

    libevent采用的方法是:每次运行epoll_wait时,选择最小堆堆顶事件的超时时间与当前时间的差值作为epoll_wait函数的timeout。

    信号事件

    信号事件也没有fd,那么如何监听呢?可参考

    libevent(七)信号事件监听

  • 相关阅读:
    Python之sys & os
    1161
    1142
    P1599 货币
    P1547逆转,然后再见
    P1629八
    P1753HackSon的趣味题
    Problem 2233 ~APTX4869
    1269
    1091. Tmutarakan Exams
  • 原文地址:https://www.cnblogs.com/gattaca/p/7697797.html
Copyright © 2011-2022 走看看