mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-14 23:05:03 -04:00
test-time: do not use deprecated API
- event_init() -> event_base_new() - event_set() -> event_new() - check return value of event_base_dispatch() - use EXIT_SUCCESS/EXIT_FAILURE (cherry picked from commit 4e5a41ca0f668da1a18832e5cb02b4afeae074ff)
This commit is contained in:
parent
29e2c7f2b7
commit
e41a1969b0
@ -81,8 +81,10 @@ time_cb(evutil_socket_t fd, short event, void *arg)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
struct event_base *base;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WORD wVersionRequested;
|
WORD wVersionRequested;
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
@ -98,23 +100,24 @@ main(int argc, char **argv)
|
|||||||
event_enable_debug_logging(EVENT_DBG_ALL);
|
event_enable_debug_logging(EVENT_DBG_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the event library */
|
base = event_base_new();
|
||||||
event_init();
|
|
||||||
|
|
||||||
for (i = 0; i < NEVENT; i++) {
|
for (i = 0; i < NEVENT; i++) {
|
||||||
ev[i] = malloc(sizeof(struct event));
|
ev[i] = evtimer_new(base, time_cb, event_self_cbarg());
|
||||||
|
|
||||||
/* Initialize one event */
|
|
||||||
evtimer_set(ev[i], time_cb, ev[i]);
|
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = rand_int(50000);
|
tv.tv_usec = rand_int(50000);
|
||||||
evtimer_add(ev[i], &tv);
|
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);
|
if (i == 1 && called >= NEVENT) {
|
||||||
return (called < NEVENT);
|
return EXIT_SUCCESS;
|
||||||
|
} else {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user