diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2016-03-11 14:41:45 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2016-03-11 14:41:45 +0000 |
commit | bb5bb4407f2578ed8d6dc3b41f6ddb8b798e560c (patch) | |
tree | 1e21750da4e7e9a2b81993f9a5484be95e394cfc /libs/tgl/libevent/sample/signal-test.c | |
parent | 2d0a5026812236b19c573bbe8d08aa20df7083d9 (diff) |
tgl compile under vc2013
git-svn-id: http://svn.miranda-ng.org/main/trunk@16457 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'libs/tgl/libevent/sample/signal-test.c')
-rw-r--r-- | libs/tgl/libevent/sample/signal-test.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/libs/tgl/libevent/sample/signal-test.c b/libs/tgl/libevent/sample/signal-test.c new file mode 100644 index 0000000000..a61642f325 --- /dev/null +++ b/libs/tgl/libevent/sample/signal-test.c @@ -0,0 +1,75 @@ +/* + * Compile with: + * cc -I/usr/local/include -o signal-test \ + * signal-test.c -L/usr/local/lib -levent + */ + +#include <sys/types.h> + +#include <event2/event-config.h> + +#include <sys/stat.h> +#ifndef _WIN32 +#include <sys/queue.h> +#include <unistd.h> +#include <sys/time.h> +#else +#include <winsock2.h> +#include <windows.h> +#endif +#include <signal.h> +#include <fcntl.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include <event2/event.h> + +#ifdef EVENT____func__ +#define __func__ EVENT____func__ +#endif + +int called = 0; + +static void +signal_cb(evutil_socket_t fd, short event, void *arg) +{ + struct event *signal = arg; + + printf("%s: got signal %d\n", __func__, event_get_signal(signal)); + + if (called >= 2) + event_del(signal); + + called++; +} + +int +main(int argc, char **argv) +{ + struct event *signal_int; + struct event_base* base; +#ifdef _WIN32 + WORD wVersionRequested; + WSADATA wsaData; + + wVersionRequested = MAKEWORD(2, 2); + + (void) WSAStartup(wVersionRequested, &wsaData); +#endif + + /* Initalize the event library */ + base = event_base_new(); + + /* Initalize one event */ + signal_int = evsignal_new(base, SIGINT, signal_cb, event_self_cbarg()); + + event_add(signal_int, NULL); + + event_base_dispatch(base); + event_base_free(base); + + return (0); +} + |