libev ev_init分析

/* these may evaluate ev multiple times, and the other arguments at most once */
/* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */
#define ev_init(ev,cb_) do {            \
  ((ev_watcher *)(void *)(ev))->active  =    \
  ((ev_watcher *)(void *)(ev))->pending = 0;    \
  ev_set_priority ((ev), 0);            \
  ev_set_cb ((ev), cb_);            \
} while (0)

当event_loop初始化后,就可以把自己想要做的时间丢给loop啦,具体怎么搞呢,可以调用ev_init这个宏,尼玛,又是宏!

其实关键的一句就是

ev_set_cb ((ev), cb_);   就是把ev_io的回调设置为cb_啦。

ok,就是这样!


其中,
ev_watcher 是神马玩意呢?

/* shared by all watchers */
#define EV_WATCHER(type) \
int active; /* private */ \
int pending; /* private */ \
EV_DECL_PRIORITY /* private */ \ //int priority
EV_COMMON /* rw */ \ //void* Data
EV_CB_DECLARE (type) /* private */ //声明了第一个参数为type的回调

 

#define EV_WATCHER_LIST(type) \
EV_WATCHER (type) \
struct ev_watcher_list *next; /* private */

是指一个watcher链表



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值