libevent源码分析:eventop
源码 分析 libevent
2023-09-27 14:28:06 时间
eventop:定义了event_base使用的后端IO复用的一个统一接口
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:用来初始化一个event_base来使用这个后端的函数。
3、add:激活一个给定文件描述符或者信号上的读或写。
4、del:和add的操作相反。
5、dispatch:完成核心事件循环的函数。
6、dealloc:清除和释放event_base数据。
7、need_reinit:标志在fork后是否需要重新初始化event_base。
相关文章
- SpringSession的源码解析(从Cookie中读取Sessionid,根据sessionid查询信息全流程分析)
- 【并发编程】ReentrantLock的lock()方法源码分析
- HTTP流量神器Goreplay核心源码详解
- 【神经网络与深度学习】Caffe源码中各种依赖库的作用及简单使用
- 源码分析
- chainer-人脸关键点检测-FaceNet【附源码】
- java中的锁之AbstractQueuedSynchronizer源码分析(二)
- Netty源码分析 (十)----- 拆包器之LineBasedFrameDecoder
- Tomcat源码分析 (八)----- HTTP请求处理过程(一)
- IK分词器 原理分析 源码解析
- netty源码分析
- ElasticStack系列之十六 & ElasticSearch5.x index/create 和 update 源码分析
- TensorFlow学习笔记之五——源码分析之最近算法
- QEMU1.3.0的源码分析一 : 源码目录简介
- 【HashMap】| 深度剥析Java SE 源码合集Ⅱ | 你会吗?
- Unity3d C#实现将场景中摄像头画面进行采集、录制并上传视频流(推流rtmp)直播的功能(含源码)
- Unity3d C# 实现mp3的字节数组byte[] 转AudioClip并播放(含源码)
- 【Zookeeper】源码分析之持久化(二)之FileSnap
- libevent源码分析:event_assign、event_new
- lievent源码分析:evbuffer
- 【Android 启动过程】Activity 启动源码分析 ( ActivityThread 流程分析 一 )
- React-Redux 源码解析
- Kafka源码分析之MemoryRecords
- java并发包concurrent翻译及源码分析之:ReadWriteLock
- Spark源码分析之六:Task调度(二)