代码拉取完成,页面将自动刷新
#include <event2/event.h>
void read_cb(evutil_socket_t, short, void* );
void write_cb(evutil_socket_t, short, void* );
void main_loop(evutil_socket_t fd)
{
struct event* important, * unimportant;
struct event_base* base;
struct timeval five_seconds = {5,0};
base = event_base_new();
event_base_priority_init(base, 2);
/* Now base has priority 0, and priority 1 */
important = event_new(base, fd, EV_WRITE|EV_PERSIST, write_cb, NULL);
unimportant = event_new(base, fd, EV_READ|EV_PERSIST, read_cb, NULL);
event_priority_set(important, 0);
event_priority_set(unimportant, 1);
/* Now, whenever the fd is ready for writing, the write callback will
happen before the read callback. The read callback won’t happen at
all until the write callback is no longer active.
*/
event_add(important, &five_seconds);
event_add(important, NULL);
event_base_dispatch(base);
}
int main()
{
main_loop(fileno(stdin));
return 0;
}
void read_cb(evutil_socket_t fd, short what, void* arg)
{
const char* data = arg;
printf("Got an event on socket %d:%s%s%s%s [%s]\n",
(int) fd,
(what&EV_TIMEOUT) ? " timeout" : "",
(what&EV_READ) ? " read" : "",
(what&EV_WRITE) ? " write" : "",
(what&EV_SIGNAL) ? " signal" : "",
data);
}
void write_cb(evutil_socket_t fd, short what, void* arg)
{
read_cb(fd, what, arg);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。