Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / libevent / sample / signal-test.c
blob9a131cb50c249a5a753335a821129bd6486fe66a
1 /*
2 * Compile with:
3 * cc -I/usr/local/include -o signal-test \
4 * signal-test.c -L/usr/local/lib -levent
5 */
7 #include <sys/types.h>
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
13 #include <sys/stat.h>
14 #ifndef WIN32
15 #include <sys/queue.h>
16 #include <unistd.h>
17 #include <sys/time.h>
18 #else
19 #include <windows.h>
20 #endif
21 #include <signal.h>
22 #include <fcntl.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <errno.h>
28 #include <event.h>
30 int called = 0;
32 static void
33 signal_cb(int fd, short event, void *arg)
35 struct event *signal = arg;
37 printf("%s: got signal %d\n", __func__, EVENT_SIGNAL(signal));
39 if (called >= 2)
40 event_del(signal);
42 called++;
45 int
46 main (int argc, char **argv)
48 struct event signal_int;
50 /* Initalize the event library */
51 event_init();
53 /* Initalize one event */
54 event_set(&signal_int, SIGINT, EV_SIGNAL|EV_PERSIST, signal_cb,
55 &signal_int);
57 event_add(&signal_int, NULL);
59 event_dispatch();
61 return (0);