Hi, I just wrote a simple program trying to use the timeout event in
libevent 2.0.3-alpha. The source code is at the end of the email. I'm
expecting to see a print out of "***in dummy_callback()", but this line does
not show up at all. What I am seeing is only:
***entering main()
***entering EventLoop()
***dummy_event=0x60e690
***exiting EventLoop()
***exiting main()
What am I doing wrong in the following source code? A lot of thanks in
advance...
#include <stdlib.h>
#include <stdio.h>
#include "event2/event.h"
struct event_base *global_event_base;
static void dummy_callback(evutil_socket_t fd, short what, void *arg)
{
printf("***in dummy_callback()\n");
}
static void* EventLoop(void *arg)
{
printf("***entering EventLoop()\n");
global_event_base = event_base_new();
if (!global_event_base) {
printf("event_base_new() failed\n");
exit (-1);
}
struct timeval five_seconds = {5,0};
struct event *dummy_event =
evtimer_new(global_event_base, dummy_callback, arg);
printf("***dummy_event=%p\n", dummy_event);
event_add(dummy_event, &five_seconds);
int ret = event_base_loop(global_event_base, EVLOOP_NONBLOCK);
if (ret!=0)
printf("event_base_loop() failed\n");
printf("***exiting EventLoop()\n");
return NULL;
}
int main()
{
printf("***entering main()\n");
EventLoop(NULL);
printf("***exiting main()\n");
fflush(stdout);
return 0;
}