libevent----标志信息

来源:互联网 发布:js的math.abs 编辑:程序博客网 时间:2024/05/14 20:56


出处:http://blog.csdn.net/beitiandijun/article/details/72772899


一、事件类型  event-internal.h

[cpp] view plain copy
  1. /** 
  2.  * @name event flags 
  3.  * 
  4.  * Flags to pass to event_new(), event_assign(), event_pending(), and 
  5.  * anything else with an argument of the form "short events" 
  6.  */  
  7. /**@{*/  
  8. /** Indicates that a timeout has occurred.  It's not necessary to pass 
  9.  * this flag to event_for new()/event_assign() to get a timeout. */  
  10. // 定时事件  
  11. #define EV_TIMEOUT    0x01  
  12. /** Wait for a socket or FD to become readable */  
  13. // 读事件  
  14. #define EV_READ        0x02  
  15. /** Wait for a socket or FD to become writeable */  
  16. // 写事件  
  17. #define EV_WRITE    0x04  
  18. /** Wait for a POSIX signal to be raised*/  
  19. // 信号  
  20. #define EV_SIGNAL    0x08  
  21. /** 
  22.  * Persistent event: won't get removed automatically when activated. 
  23.  * 
  24.  * When a persistent event with a timeout becomes activated, its timeout 
  25.  * is reset to 0. 
  26.  */  
  27. // 永久事件,激活执行后会重新加到队列中等待下一次激活,否则激活执行后会自动移除  
  28. #define EV_PERSIST    0x10  
  29. /** Select edge-triggered behavior, if supported by the backend. */  
  30. // 边沿触发,一般需要后台方法支持  
  31. #define EV_ET        0x20  
  32. /** 
  33.  * If this option is provided, then event_del() will not block in one thread 
  34.  * while waiting for the event callback to complete in another thread. 
  35.  * 
  36.  * To use this option safely, you may need to use event_finalize() or 
  37.  * event_free_finalize() in order to safely tear down an event in a 
  38.  * multithreaded application.  See those functions for more information. 
  39.  * 
  40.  * THIS IS AN EXPERIMENTAL API. IT MIGHT CHANGE BEFORE THE LIBEVENT 2.1 SERIES 
  41.  * BECOMES STABLE. 
  42.  **/  
  43. // 终止事件,如果设置这个选项,则event_del不会阻塞,需要使用event_finalize或者  
  44. // event_free_finalize以保证多线程安全  
  45. #define EV_FINALIZE     0x40  
  46. /** 
  47.  * Detects connection close events.  You can use this to detect when a 
  48.  * connection has been closed, without having to read all the pending data 
  49.  * from a connection. 
  50.  * 
  51.  * Not all backends support EV_CLOSED.  To detect or require it, use the 
  52.  * feature flag EV_FEATURE_EARLY_CLOSE. 
  53.  **/  
  54. // 检查事件连接是否关闭;可以使用这个选项来检测链接是否关闭,而不需要读取此链接所有未决数据;  
  55. #define EV_CLOSED    0x80  


二、事件状态标志     event_struct.h中

[cpp] view plain copy
  1. // 事件在time min_heap堆中  
  2. #define EVLIST_TIMEOUT        0x01  
  3. // 事件在已注册事件链表中  
  4. #define EVLIST_INSERTED        0x02  
  5. // 目前未使用  
  6. #define EVLIST_SIGNAL        0x04  
  7. // 事件在激活链表中  
  8. #define EVLIST_ACTIVE        0x08  
  9. // 内部使用标记  
  10. #define EVLIST_INTERNAL        0x10  
  11. // 事件在下一次激活链表中  
  12. #define EVLIST_ACTIVE_LATER 0x20  
  13. // 事件已经终止  
  14. #define EVLIST_FINALIZING   0x40  
  15. // 事件初始化完成,但是哪儿都不在  
  16. #define EVLIST_INIT        0x80  
  17. // 包含所有事件状态,用于判断合法性的  
  18. #define EVLIST_ALL          0xff  


三、后台方法 event.c

[cpp] view plain copy
  1. /* Array of backends in order of preference. */  
  2. 后台方法的全局静态数组  
  3. static const struct eventop *eventops[] = {  
  4. #ifdef EVENT__HAVE_EVENT_PORTS  
  5.     &evportops,  
  6. #endif  
  7. #ifdef EVENT__HAVE_WORKING_KQUEUE  
  8.     &kqops,  
  9. #endif  
  10. #ifdef EVENT__HAVE_EPOLL  
  11.     &epollops,  
  12. #endif  
  13. #ifdef EVENT__HAVE_DEVPOLL  
  14.     &devpollops,  
  15. #endif  
  16. #ifdef EVENT__HAVE_POLL  
  17.     &pollops,  
  18. #endif  
  19. #ifdef EVENT__HAVE_SELECT  
  20.     &selectops,  
  21. #endif  
  22. #ifdef _WIN32  
  23.     &win32ops,  
  24. #endif  
  25.     NULL  
  26. };  


四、后台方法特征列表 event.h

[cpp] view plain copy
  1. /** 
  2.    A flag used to describe which features an event_base (must) provide. 
  3.    Because of OS limitations, not every Libevent backend supports every 
  4.    possible feature.  You can use this type with 
  5.    event_config_require_features() to tell Libevent to only proceed if your 
  6.    event_base implements a given feature, and you can receive this type from 
  7.    event_base_get_features() to see which features are available. 
  8. */  
  9. // 用来描述event_base必须提供的特征值,其实是后台方法提供的;  
  10. // 因为OS的限制,不是所有event_base后台方法都支持每个可能的特征;  
  11. // 必须使用event_config_require_features()进行配置,同时必须使用  
  12. // event_base_get_features()查看是否支持配置的特征。  
  13. enum event_method_feature {  
  14.     /** Require an event method that allows edge-triggered events with EV_ET. */  
  15.      // 边沿触发,高效但是容易丢消息,注意与水平触发区分  
  16.     EV_FEATURE_ET = 0x01,  
  17.     /** Require an event method where having one event triggered among 
  18.      * many is [approximately] an O(1) operation. This excludes (for 
  19.      * example) select and poll, which are approximately O(N) for N 
  20.      * equal to the total number of possible events. */  
  21.      // 要求具有很多事件的后台方法可以以近似O(1)处理事件;select和poll  
  22.      // 无法提供这种特征,它们只能提供近似O(N)的操作  
  23.     EV_FEATURE_O1 = 0x02,  
  24.     /** Require an event method that allows file descriptors as well as 
  25.      * sockets. */  
  26.      // 后台方法可以处理包括sockets在内的各种文件描述符  
  27.     EV_FEATURE_FDS = 0x04,  
  28.     /** Require an event method that allows you to use EV_CLOSED to detect 
  29.      * connection close without the necessity of reading all the pending data. 
  30.      * 
  31.      * Methods that do support EV_CLOSED may not be able to provide support on 
  32.      * all kernel versions. 
  33.      **/  
  34.      // 要求后台方法可以使用EV_CLOSED检测链接关闭,而不需要读完所有未决数据才能判断  
  35.      // 支持EV_CLOSED的后台方法不是所有OS内核都支持的  
  36.     EV_FEATURE_EARLY_CLOSE = 0x08  
  37. };  


五、event_base或者libevent工作模式 event.h

[cpp] view plain copy
  1. /** 
  2.    A flag passed to event_config_set_flag(). 
  3.     These flags change the behavior of an allocated event_base. 
  4.     @see event_config_set_flag(), event_base_new_with_config(), 
  5.        event_method_feature 
  6.  */  
  7. // 可以使用event_config_set_flag设置以下配置。  
  8. // 这个配置可以改变event_base的行为  
  9. enum event_base_config_flag {  
  10.     /** Do not allocate a lock for the event base, even if we have 
  11.         locking set up. 
  12.         Setting this option will make it unsafe and nonfunctional to call 
  13.         functions on the base concurrently from multiple threads. 
  14.     */  
  15.      // 非阻塞模式,多线程不安全  
  16.     EVENT_BASE_FLAG_NOLOCK = 0x01,  
  17.     /** Do not check the EVENT_* environment variables when configuring 
  18.         an event_base  */  
  19.      // 这种模式下不再检查EVENT_*环境变量  
  20.     EVENT_BASE_FLAG_IGNORE_ENV = 0x02,  
  21.     /** Windows only: enable the IOCP dispatcher at startup 
  22.         If this flag is set then bufferevent_socket_new() and 
  23.         evconn_listener_new() will use IOCP-backed implementations 
  24.         instead of the usual select-based one on Windows. 
  25.      */  
  26.      // 只应用于windows环境  
  27.     EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,  
  28.     /** Instead of checking the current time every time the event loop is 
  29.         ready to run timeout callbacks, check after each timeout callback. 
  30.      */  
  31.      // 每次event_loop准备运行timeout回调时,不再检查当前的时间,而是  
  32.      // 在每次timeout回调之后检查  
  33.     EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08,  
  34.   
  35.     /** If we are using the epoll backend, this flag says that it is 
  36.         safe to use Libevent's internal change-list code to batch up 
  37.         adds and deletes in order to try to do as few syscalls as 
  38.         possible.  Setting this flag can make your code run faster, but 
  39.         it may trigger a Linux bug: it is not safe to use this flag 
  40.         if you have any fds cloned by dup() or its variants.  Doing so 
  41.         will produce strange and hard-to-diagnose bugs. 
  42.         This flag can also be activated by setting the 
  43.         EVENT_EPOLL_USE_CHANGELIST environment variable. 
  44.         This flag has no effect if you wind up using a backend other than 
  45.         epoll. 
  46.      */  
  47.      // 如果后台方法是epoll,则此模式是指可以安全的使用libevent内部changelist  
  48.      // 进行批量增删而尽可能减少系统调用。这种模式可以让代码性能更高,  
  49.      // 但是可能会引起Linux bug:如果有任何由dup()或者他的变量克隆的fds,  
  50.      // 则是不安全的。这样做会引起奇怪并且难以检查的bugs。此模式可以通过  
  51.      // EVENT_EPOLL_USE_CHANGELIST环境变量激活。  
  52.      // 此模式只有在使用epoll时可用  
  53.     EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10,  
  54.   
  55.     /** Ordinarily, Libevent implements its time and timeout code using 
  56.         the fastest monotonic timer that we have.  If this flag is set, 
  57.         however, we use less efficient more precise timer, assuming one is 
  58.         present. 
  59.      */  
  60.      // 通常情况下,libevent使用最快的monotonic计时器实现自己的计时和超时控制;  
  61.      // 此模式下,会使用性能较低但是准确性更高的计时器。  
  62.     EVENT_BASE_FLAG_PRECISE_TIMER = 0x20  
  63. };  


六、事件关闭时的回调函数模式类型 

[cpp] view plain copy
  1. /** @name Event closure codes 
  2.     Possible values for evcb_closure in struct event_callback 
  3.     @{ 
  4.  */  
  5. /** A regular event. Uses the evcb_callback callback */  
  6. // 常规事件,使用evcb_callback回调  
  7. #define EV_CLOSURE_EVENT 0  
  8. /** A signal event. Uses the evcb_callback callback */  
  9. // 信号事件;使用evcb_callback回调  
  10. #define EV_CLOSURE_EVENT_SIGNAL 1  
  11. /** A persistent non-signal event. Uses the evcb_callback callback */  
  12. // 永久性非信号事件;使用evcb_callback回调  
  13. #define EV_CLOSURE_EVENT_PERSIST 2  
  14. /** A simple callback. Uses the evcb_selfcb callback. */  
  15. // 简单回调,使用evcb_selfcb回调  
  16. #define EV_CLOSURE_CB_SELF 3  
  17. /** A finalizing callback. Uses the evcb_cbfinalize callback. */  
  18. // 结束的回调,使用evcb_cbfinalize回调  
  19. #define EV_CLOSURE_CB_FINALIZE 4  
  20. /** A finalizing event. Uses the evcb_evfinalize callback. */  
  21. // 结束事件回调,使用evcb_evfinalize回调  
  22. #define EV_CLOSURE_EVENT_FINALIZE 5  
  23. /** A finalizing event that should get freed after. Uses the evcb_evfinalize 
  24.  * callback. */  
  25. // 结束事件之后应该释放,使用evcb_evfinalize回调  
  26. #define EV_CLOSURE_EVENT_FINALIZE_FREE 6  
  27. /** @} */  

原创粉丝点击