ibev的代码很简练 但对于看他代码的人 简直就是噩梦 到处都是宏 宏还嵌套 于是我在看libev代码时 对其进行了还原 去掉了宏
4 |
struct
ev_watcher_list *list;
|
9 |
void (*cb)( struct
ev_loop *loop, struct
ev_io *w, int
revents);
|
ev_io在触发EV_READ或者是EV_WRITE被调用
8 |
void (*cb)( struct
ev_loop *loop, struct
ev_timer *w, int
revents);
|
ev_timer在特定的时间调用,并周期性进行,其基于单调时钟
(PS:单调时钟:此时间来源会严格的线性递增,一般linux会使用系统正常运行时间来表示,也就是从开机开始算起) 触发事件EV_TIMEOUT
4 |
ev_tstamp (*reschedule_cb)( struct
ev_periodic *w, ev_tstamp now);
|
10 |
void (*cb)( struct
ev_loop *loop, struct
ev_periodic *w, int
revents);
|
ev_periodic在特定的时间调用,可能会在定期间隔反复调用,其基于UTC时间
(PS:UTC:协调时间 也就是从1970年1月1日00:00:00开始记时) 触发事件EV_PERIODIC
3 |
struct
ev_watcher_list *next;
|
8 |
void (*cb)( struct
ev_loop *loop, struct
ev_signal *w, int
revents);
|
ev_signal当接收到指定的信号时调用 触发事件EV_SIGNAL
6 |
struct
ev_watcher_list *next;
|
11 |
void (*cb)( struct
ev_loop *loop, struct
ev_child *w, int
revents);
|
ev_child当接收到SIGCHLD信号并且waitpid表示了给出的pid时调用 触发EV_CHILD事件
其不支持优先级
8 |
struct
ev_watcher_list *next;
|
13 |
void (*cb)( struct
ev_loop *loop, struct
ev_stat *w, int
revents);
|
ev_stat当每次指定的路径状态数据发生改变时调用 触发EV_STAT
6 |
void (*cb)( struct
ev_loop *loop, struct
ev_idle *w, int
revents);
|
ev_idle当啥事情都不需要做的时候调用,用来保持进程远离阻塞 触发EV_IDLE
6 |
void (*cb)( struct
ev_loop *loop, struct
ev_prepare *w, int
revents);
|
ev_prepare每次执行mainloop主循环,在主循环之前调用 触发EV_PREPARE;
6 |
void (*cb)( struct
ev_loop *loop, struct
ev_check *w, int
revents);
|
ev_check每次执行mainloop主循环,在主循环之后调用 触发EV_CHECK
6 |
void (*cb)( struct
ev_loop *loop, struct
ev_fork *w, int
revents);
|
ev_fok在fork行为被检测到,并且在检测子进程之前调用 触发EV_FORK;
6 |
void (*cb)( struct
ev_loop *loop, struct
ev_cheanup *w, int
revents);
|
ev_cleanup在主循被销毁之后调用 触发EV_CLEANUP
ev_embed用于将一个事件循环嵌套到另一个中,当事件循环处理事件的时候被调用
2 |
sig_atomic_t
volatile sent;
|
7 |
void (*cb)( struct
ev_loop *loop, struct
ev_async *w, int
revents);
|
ev_async当ev_async_send通过watcher调用时调用,触发EV_ASYNC
3 |
struct
ev_watcher_list wl;
|
6 |
struct
ev_periodic periodic;
|
7 |
struct
ev_signal signal ;
|
15 |
struct
ev_prepare prepare;
|
16 |
struct
ev_check check;
|
21 |
struct
ev_cleanup cleanup;
|
24 |
struct
ev_embed embed;
|
27 |
struct
ev_async async;
|
该结构的存在用以强制类似结构的布局
6 |
void (*cb)( struct
ev_loop* loop, struct
ev_watcher *w, int
revent);
|
9 |
struct
ev_watcher_list {
|
10 |
struct
ev_wather_list *next;
|
15 |
void (*cb)( struct
ev_loop* loop, struct
ev_watcher_list *w, int
revent);
|
1 |
static
unsigned int ev_linux_version( void )
|
通过使用utsname结构以及uname函数获取linux版本号
1 |
static
void ev_printerr( const
char *msg)
|
输出错误新方法,实现很简单用write直接往STDERR写数据
1 |
void ev_set_syserr_cb( void
(*cb)( const
char *msg))
|
设置系统错误控制方法回调
1 |
static
void ev_syserr( const
char *msg)
|
系统错误处理函数,首先判断msg是否为空,msg==NULL填充为”(libev) system error”,然后如果系统错误控制回调不为空 也就是通过上面方法设置的,就调用该控制回调 否则的话就格式化输出 并中断程序运行
1 |
static
void * ev_realloc_emul( void
*ptr, long
size)
|
作者分装的一个realloc,主要为了屏蔽不同平台的差异,比如 有些系统(如openBSD)不支持realloc(x,0)这种行为,于是作者进行了判定如果是含有__GLIBC__宏 那么就可以之间诶用realloc 否则的话当size为0则进行free操作
1 |
static
void *(*alloc)( void
*ptr, long
size) = ev_realloc_emul;
|
定义了一个变量,并赋值,啥变量 一个指向返回值是void* 参数是void*,long的函数指针 不过看着总觉得不爽 习惯于typedef的写法,另一方面也就是说alloc等价与ev_realloc_emul哦
1 |
void ev_set_allocator( void
*(*cb)( void * ptr, long
size))
|
设置alloc函数的实现,我们在上面的语句看到alloc的默认实现是啥,通过该函数可以改变其实现
1 |
inline_speed void * ev_realloc( void * ptr,
long size)
|
一个realloc的实现调用的alloc,比之增加错误日志输出 有意思的是这里有一个叫做inline_speed的宏,libev的作者在libev中大量使用了,使人看代码相当不爽的说
2 |
#define inline_speed static inline |
4 |
#define inline_speed static noinline |
这里又一把宏定义,不过都是见名知义,EV_FEATURE_CODE默认情况是非0,也就是inline_speed默认为static inline
1 |
#define ev_malloc(size) ev_realloc(0,(size)) |
2 |
#define ev_free(ptr)m ev_realloc((ptr),0) |
我们看到ev_malloc以及ev_free其实也是通过ev_realloc实现的
10 |
#if EV_SELECT_ISWINSOCKET || EV_USE_IOCP |
文件描述符信息结构
指定等待事件的监听者结构
每个inotify-id对应的哈希表的每个节点的结构
堆结构的节点
1 |
ev_tstamp ev_time( void )
|
获取当前时间如果设置了EV_USE_REALTIME会考虑是否使用clock_gettime纳秒(have_realtiem如果为非负就使用 clock_gettime了) 否则使用gettimeofday 注意这里的时间都是和当前设置的时间是有关系的 也就是说如果我把系统时间修改了 可能得到过去的时间
另外这里用了一个宏expect_true 其原型是__builtin_expect((a) != 0, 1)也就是告诉编译器绝大多数情况下a != 0是满足的 方便编译器进行优化 同理相反的还有expect_false
1 |
inline_size ev_tstamp get_clock( void )
|
这个函数优先是使用CLOCK_MONOTONIC时间 也就是单调时间不会被修改减小 然后达不到要求 则调用ev_time来获取时间 inline_size就是 static inline
1 |
ev_tstamp ev_now( struct
ev_loop *loop)
|
获取当前时间时间 也就是loop->ev_rt_now
1 |
void ev_sleep(ev_tstamp delay)
|
如果可以使用nanosleep则使用nanosleep 如果在window下使用Sleep,否则使用select实现
1 |
inline_size int
array_next( int
elem, int cur,
int cnt)
|
用来生成内存对齐大小的实际需要开辟的内存大
1 |
static
ninline void * array_realloc( int
elem, void
*base, int *cur,
int cnt)
|
开辟或重新非配一定大小的内存块,该方法会调用上面的函数进行内存对齐大小 所以返回后的大小不一定会和想开辟的相等
1 |
array_init_zero(base,count) |
顾名思义初始化为0,通过memset实现
1 |
array_needsize(type,base,cur,cnt,init) |
分配需要大小的内存 就是分配出内存 并初始化为0
分享到:
相关推荐
libev4-4.15-7.1.x86_64.rpm percona-xtrabackup-2.1.3-608.rhel6.x86_64 安装需要的包
libhv libev libuv libevent 2020-08-28 最新源代码。这是几个经典的跨平台网络开发库
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
libev是高性能事件循环/事件模型的网络库,并且包含大量新特性,除了提供了基本的三大类事件(IO事件、定时器事件、信号事件)支持外还提供了周期事件、子进程事件、文件状态改变事件等多个事件的支持
官方离线安装包,亲测可用
离线安装包,亲测可用
安装xtrabackup必须要用到的一个依赖,分享给大家,分享给大家。
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,亲测可用
官方离线安装包,亲测可用
离线安装包,亲测可用
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官网已经无法下载,备份出来分享给大家,libev是libevent之后的一个事件驱动的编程框架
离线安装包,亲测可用
离线安装包,亲测可用
libev-4.15 最新代码
rabbitmq安装依赖包,libev是libevent之后的一个事件驱动的编程框架,其接口和libevent基本类似。据官方介绍,其性能比libevent还要高,bug比libevent还少。
libev4.24下载