使用 libevent 的一个代码片段如下:struct event ev_accept;event_set(&ev_accept, listen_fd, EV_READ|EV_PERSIST, on_accept, NULL);event_add(&ev_accept, NULL);这段代码是错误的,因为 ev_accept 是在栈上分配的临时变量,但是 ev_accept 实际上是要求在整个程序的生命期中都有效的,且看 libevent 文档中的描述:Event notificationFor each file descriptor that you wish to monitor, you must declare an event structure and call event_set() to initialize the members of the structure. To enable notification, you add the structure to the list of monitore阅读全文>
发表于 @ 2008年10月10日 17:36:00|评论(loading...)|举报|收藏