1 /*
2 * Compile with:
3 * cc -I/usr/local/include -o signal-test \
4 * signal-test.c -L/usr/local/lib -levent
5 */
6
7 #include <sys/types.h>
8
9 #include <event2/event-config.h>
10
11 #include <sys/stat.h>
12 #ifndef _WIN32
13 #include <sys/queue.h>
14 #include <unistd.h>
15 #include <sys/time.h>
16 #else
17 #include <winsock2.h>
18 #include <windows.h>
19 #endif
20 #include <signal.h>
21 #include <fcntl.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <errno.h>
26
27 #include <event2/event.h>
28
29 int called = 0;
30
31 static void
signal_cb(evutil_socket_t fd,short event,void * arg)32 signal_cb(evutil_socket_t fd, short event, void *arg)
33 {
34 struct event *signal = arg;
35
36 printf("signal_cb: got signal %d\n", event_get_signal(signal));
37
38 if (called >= 2)
39 event_del(signal);
40
41 called++;
42 }
43
44 int
main(int argc,char ** argv)45 main(int argc, char **argv)
46 {
47 struct event *signal_int;
48 struct event_base* base;
49 #ifdef _WIN32
50 WORD wVersionRequested;
51 WSADATA wsaData;
52
53 wVersionRequested = MAKEWORD(2, 2);
54
55 (void) WSAStartup(wVersionRequested, &wsaData);
56 #endif
57
58 /* Initalize the event library */
59 base = event_base_new();
60
61 /* Initalize one event */
62 signal_int = evsignal_new(base, SIGINT, signal_cb, event_self_cbarg());
63
64 event_add(signal_int, NULL);
65
66 event_base_dispatch(base);
67 event_free(signal_int);
68 event_base_free(base);
69
70 return (0);
71 }
72
73