日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

libevent源码分析:eventop

發(fā)布時(shí)間:2024/1/17 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 libevent源码分析:eventop 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

eventop:定義了event_base使用的后端IO復(fù)用的一個(gè)統(tǒng)一接口

1 /** Structure to define the backend of a given event_base. */ 2 struct eventop { 3 /** The name of this backend. */ 4 const char *name; 5 /** Function to set up an event_base to use this backend. It should 6 * create a new structure holding whatever information is needed to 7 * run the backend, and return it. The returned pointer will get 8 * stored by event_init into the event_base.evbase field. On failure, 9 * this function should return NULL. */ 10 void *(*init)(struct event_base *); 11 /** Enable reading/writing on a given fd or signal. 'events' will be 12 * the events that we're trying to enable: one or more of EV_READ, 13 * EV_WRITE, EV_SIGNAL, and EV_ET. 'old' will be those events that 14 * were enabled on this fd previously. 'fdinfo' will be a structure 15 * associated with the fd by the evmap; its size is defined by the 16 * fdinfo field below. It will be set to 0 the first time the fd is 17 * added. The function should return 0 on success and -1 on error. 18 */ 19 int (*add)(struct event_base *, evutil_socket_t fd, short old, short events, void *fdinfo); 20 /** As "add", except 'events' contains the events we mean to disable. */ 21 int (*del)(struct event_base *, evutil_socket_t fd, short old, short events, void *fdinfo); 22 /** Function to implement the core of an event loop. It must see which 23 added events are ready, and cause event_active to be called for each 24 active event (usually via event_io_active or such). It should 25 return 0 on success and -1 on error. 26 */ 27 int (*dispatch)(struct event_base *, struct timeval *); 28 /** Function to clean up and free our data from the event_base. */ 29 void (*dealloc)(struct event_base *); 30 /** Flag: set if we need to reinitialize the event base after we fork. 31 */ 32 int need_reinit; 33 /** Bit-array of supported event_method_features that this backend can 34 * provide. */ 35 enum event_method_feature features; 36 /** Length of the extra information we should record for each fd that 37 has one or more active events. This information is recorded 38 as part of the evmap entry for each fd, and passed as an argument 39 to the add and del functions above. 40 */ 41 size_t fdinfo_len; 42 };

定義的成員包括:

1、name:后端的名字,例如:select、poll、epoll

2、init:用來(lái)初始化一個(gè)event_base來(lái)使用這個(gè)后端的函數(shù)。

3、add:激活一個(gè)給定文件描述符或者信號(hào)上的讀或?qū)憽?/p>

4、del:和add的操作相反。

5、dispatch:完成核心事件循環(huán)的函數(shù)。

6、dealloc:清除和釋放event_base數(shù)據(jù)。

7、need_reinit:標(biāo)志在fork后是否需要重新初始化event_base。

總結(jié)

以上是生活随笔為你收集整理的libevent源码分析:eventop的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。