#include <stdio.h>
#include <stdlib.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/listener.h>
#include <event2/util.h>
#include <event2/event.h>
#include <event2/event_struct.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
void time_callback(evutil_socket_t fd, short event, void*arg)
{
printf("*****hello **********\n");
return;
}
int main(int argc,char *argv[])
{
struct event_base *base;
struct event *tevent;
struct event eve;
int i = 0;
//設置超時時間爲3秒
struct timeval ti={3,0};
//開啓debug logging 用於信息調試
event_enable_debug_logging(EVENT_DBG_ALL);
base = event_base_new();
if(NULL == base)
{
printf("new base is error\n");
return -1;
}
tevent = event_new(base,-1,EV_TIMEOUT|EV_PERSIST,time_callback,NULL);
if(NULL == tevent)
{
event_base_free(base);
printf("create time event is error\n");
return -1;
}
event_add(tevent,&ti);
event_base_dispatch(base);
event_free(tevent);
event_base_free(base);
return 0;
}