Skip to content

Commit

Permalink
test-time: do not use deprecated API
Browse files Browse the repository at this point in the history
- event_init() -> event_base_new()
- event_set() -> event_new()
- check return value of event_base_dispatch()
- use EXIT_SUCCESS/EXIT_FAILURE
  • Loading branch information
azat committed Mar 1, 2020
1 parent a11edbf commit 4e5a41c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions test/test-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ time_cb(evutil_socket_t fd, short event, void *arg)
int
main(int argc, char **argv)
{
struct event_base *base;
struct timeval tv;
int i;

#ifdef _WIN32
WORD wVersionRequested;
WSADATA wsaData;
Expand All @@ -98,23 +100,24 @@ main(int argc, char **argv)
event_enable_debug_logging(EVENT_DBG_ALL);
}

/* Initialize the event library */
event_init();
base = event_base_new();

for (i = 0; i < NEVENT; i++) {
ev[i] = malloc(sizeof(struct event));

/* Initialize one event */
evtimer_set(ev[i], time_cb, ev[i]);
ev[i] = evtimer_new(base, time_cb, event_self_cbarg());
tv.tv_sec = 0;
tv.tv_usec = rand_int(50000);
evtimer_add(ev[i], &tv);
}

event_dispatch();
i = event_base_dispatch(base);

printf("event_base_dispatch=%d, called=%d, EVENT=%d\n",
i, called, NEVENT);

printf("%d, %d\n", called, NEVENT);
return (called < NEVENT);
if (i == 1 && called >= NEVENT) {
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
}

0 comments on commit 4e5a41c

Please sign in to comment.