libevent 支持的东西越来越多,也越来越重了。
发现 libev 不错,研究下。尝试“Say bye to libevent”。
libev 中设定了各种 XX_watcher,我们来看看最基本的 io watcher。
-------------------------------------------------------------------------------------
#include <ev.h>
#include <stdio.h>
#include <unistd.h> // STDIN_FILENO
static void
stdin_cb(struct ev_loop *loop, ev_io *w, int revents)
{
puts("quit!");
ev_io_stop(loop, w);
ev_break(loop, EVBREAK_ALL);
}
int main(void)
{
struct ev_loop *loop = ev_default_loop(0);
ev_io stdin_watcher;
ev_init(&stdin_watcher, stdin_cb);
ev_io_set(&stdin_watcher, STDIN_FILENO, EV_READ);
ev_io_start(loop, &stdin_watcher);
puts("press any key to continue...");
ev_run(loop, 0);
return 0;
}
-------------------------------------------------------------------------------------
评论