libevent----標誌信息


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


一、事件類型  event-internal.h

  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中

  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

  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

  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

  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. };  


六、事件關閉時的回調函數模式類型 

  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. /** @} */  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章