Pipeline: Invalidate weak pointers before returning stop callback.
[chromium-blink-merge.git] / third_party / libevent / sample / time-test.c
blob069d4f8f7837dee1a4c91d52ecbbb60ca3a3a1bb
1 /*
2 * Compile with:
3 * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
4 */
6 #include <sys/types.h>
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
12 #include <sys/stat.h>
13 #ifndef WIN32
14 #include <sys/queue.h>
15 #include <unistd.h>
16 #endif
17 #include <time.h>
18 #ifdef HAVE_SYS_TIME_H
19 #include <sys/time.h>
20 #endif
21 #include <fcntl.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <errno.h>
27 #include <event.h>
28 #include <evutil.h>
30 int lasttime;
32 static void
33 timeout_cb(int fd, short event, void *arg)
35 struct timeval tv;
36 struct event *timeout = arg;
37 int newtime = time(NULL);
39 printf("%s: called at %d: %d\n", __func__, newtime,
40 newtime - lasttime);
41 lasttime = newtime;
43 evutil_timerclear(&tv);
44 tv.tv_sec = 2;
45 event_add(timeout, &tv);
48 int
49 main (int argc, char **argv)
51 struct event timeout;
52 struct timeval tv;
54 /* Initalize the event library */
55 event_init();
57 /* Initalize one event */
58 evtimer_set(&timeout, timeout_cb, &timeout);
60 evutil_timerclear(&tv);
61 tv.tv_sec = 2;
62 event_add(&timeout, &tv);
64 lasttime = time(NULL);
66 event_dispatch();
68 return (0);