Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* |
michael@0 | 2 | * Compile with: |
michael@0 | 3 | * cc -I/usr/local/include -o signal-test \ |
michael@0 | 4 | * signal-test.c -L/usr/local/lib -levent |
michael@0 | 5 | */ |
michael@0 | 6 | |
michael@0 | 7 | #include <sys/types.h> |
michael@0 | 8 | |
michael@0 | 9 | #include <event2/event-config.h> |
michael@0 | 10 | |
michael@0 | 11 | #include <sys/stat.h> |
michael@0 | 12 | #ifndef WIN32 |
michael@0 | 13 | #include <sys/queue.h> |
michael@0 | 14 | #include <unistd.h> |
michael@0 | 15 | #include <sys/time.h> |
michael@0 | 16 | #else |
michael@0 | 17 | #include <winsock2.h> |
michael@0 | 18 | #include <windows.h> |
michael@0 | 19 | #endif |
michael@0 | 20 | #include <signal.h> |
michael@0 | 21 | #include <fcntl.h> |
michael@0 | 22 | #include <stdlib.h> |
michael@0 | 23 | #include <stdio.h> |
michael@0 | 24 | #include <string.h> |
michael@0 | 25 | #include <errno.h> |
michael@0 | 26 | |
michael@0 | 27 | #include <event.h> |
michael@0 | 28 | |
michael@0 | 29 | #ifdef _EVENT___func__ |
michael@0 | 30 | #define __func__ _EVENT___func__ |
michael@0 | 31 | #endif |
michael@0 | 32 | |
michael@0 | 33 | int called = 0; |
michael@0 | 34 | |
michael@0 | 35 | static void |
michael@0 | 36 | signal_cb(evutil_socket_t fd, short event, void *arg) |
michael@0 | 37 | { |
michael@0 | 38 | struct event *signal = arg; |
michael@0 | 39 | |
michael@0 | 40 | printf("%s: got signal %d\n", __func__, EVENT_SIGNAL(signal)); |
michael@0 | 41 | |
michael@0 | 42 | if (called >= 2) |
michael@0 | 43 | event_del(signal); |
michael@0 | 44 | |
michael@0 | 45 | called++; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | int |
michael@0 | 49 | main(int argc, char **argv) |
michael@0 | 50 | { |
michael@0 | 51 | struct event signal_int; |
michael@0 | 52 | struct event_base* base; |
michael@0 | 53 | #ifdef WIN32 |
michael@0 | 54 | WORD wVersionRequested; |
michael@0 | 55 | WSADATA wsaData; |
michael@0 | 56 | |
michael@0 | 57 | wVersionRequested = MAKEWORD(2, 2); |
michael@0 | 58 | |
michael@0 | 59 | (void) WSAStartup(wVersionRequested, &wsaData); |
michael@0 | 60 | #endif |
michael@0 | 61 | |
michael@0 | 62 | /* Initalize the event library */ |
michael@0 | 63 | base = event_base_new(); |
michael@0 | 64 | |
michael@0 | 65 | /* Initalize one event */ |
michael@0 | 66 | event_assign(&signal_int, base, SIGINT, EV_SIGNAL|EV_PERSIST, signal_cb, |
michael@0 | 67 | &signal_int); |
michael@0 | 68 | |
michael@0 | 69 | event_add(&signal_int, NULL); |
michael@0 | 70 | |
michael@0 | 71 | event_base_dispatch(base); |
michael@0 | 72 | event_base_free(base); |
michael@0 | 73 | |
michael@0 | 74 | return (0); |
michael@0 | 75 | } |
michael@0 | 76 |