Reactor模式:主线程只监视是否有客户端链接,创建一个新线程来进行其他服务
使用该库的代码
编译时需指定库 -levent
#include#include #include #include #include #include #include void sig_fun(int fd,short ev,void* arg) { printf("sig=%dn",fd); } void time_cb(int fd,short ev,void* arg) { if(ev & EV_TIMEOUT) { printf("time outn"); } } int main() { struct even_tbase* base=event_init(); assert(base!=NULL); struct event*sig_ev=evsignal_new(base,SIGINT,sig_fun,NULL); event_add(sig_ev,NULL);添加事件,无超时时间设置 struct timeval tv={5,0}; struct event* time_ev=evtimer_new(base,time_cb,NULL);定时器 event_add(time_ev,&tv); event_base_dispatch(base); event_free(sig_ev); event_free(time_ev); event_base_free(base); }



