/* 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链表