ipc/chromium/src/third_party/libevent/sample/signal-test.c

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

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.)

     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 #include <event2/event-config.h>
    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>
    27 #include <event.h>
    29 #ifdef _EVENT___func__
    30 #define __func__ _EVENT___func__
    31 #endif
    33 int called = 0;
    35 static void
    36 signal_cb(evutil_socket_t fd, short event, void *arg)
    37 {
    38 	struct event *signal = arg;
    40 	printf("%s: got signal %d\n", __func__, EVENT_SIGNAL(signal));
    42 	if (called >= 2)
    43 		event_del(signal);
    45 	called++;
    46 }
    48 int
    49 main(int argc, char **argv)
    50 {
    51 	struct event signal_int;
    52 	struct event_base* base;
    53 #ifdef WIN32
    54 	WORD wVersionRequested;
    55 	WSADATA wsaData;
    57 	wVersionRequested = MAKEWORD(2, 2);
    59 	(void) WSAStartup(wVersionRequested, &wsaData);
    60 #endif
    62 	/* Initalize the event library */
    63 	base = event_base_new();
    65 	/* Initalize one event */
    66 	event_assign(&signal_int, base, SIGINT, EV_SIGNAL|EV_PERSIST, signal_cb,
    67 	    &signal_int);
    69 	event_add(&signal_int, NULL);
    71 	event_base_dispatch(base);
    72 	event_base_free(base);
    74 	return (0);
    75 }

mercurial