Remove building with NOCRYPTO option
[minix.git] / external / bsd / libevent / dist / sample / signal-test.c
blobab6393ecde022028a4a607284d8030c5d2b1ca48
1 /* $NetBSD: signal-test.c,v 1.1.1.1 2013/04/11 16:43:31 christos Exp $ */
2 /*
3 * Compile with:
4 * cc -I/usr/local/include -o signal-test \
5 * signal-test.c -L/usr/local/lib -levent
6 */
8 #include <sys/types.h>
10 #include <event2/event-config.h>
12 #include <sys/stat.h>
13 #ifndef WIN32
14 #include <sys/queue.h>
15 #include <unistd.h>
16 #include <sys/time.h>
17 #else
18 #include <winsock2.h>
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 #ifdef _EVENT___func__
31 #define __func__ _EVENT___func__
32 #endif
34 int called = 0;
36 static void
37 signal_cb(evutil_socket_t fd, short event, void *arg)
39 struct event *signal = arg;
41 printf("%s: got signal %d\n", __func__, EVENT_SIGNAL(signal));
43 if (called >= 2)
44 event_del(signal);
46 called++;
49 int
50 main(int argc, char **argv)
52 struct event signal_int;
53 struct event_base* base;
54 #ifdef WIN32
55 WORD wVersionRequested;
56 WSADATA wsaData;
58 wVersionRequested = MAKEWORD(2, 2);
60 (void) WSAStartup(wVersionRequested, &wsaData);
61 #endif
63 /* Initalize the event library */
64 base = event_base_new();
66 /* Initalize one event */
67 event_assign(&signal_int, base, SIGINT, EV_SIGNAL|EV_PERSIST, signal_cb,
68 &signal_int);
70 event_add(&signal_int, NULL);
72 event_base_dispatch(base);
73 event_base_free(base);
75 return (0);