2002-04-10 00:31:31 +00:00
|
|
|
/*
|
|
|
|
* Compile with:
|
2009-01-15 06:15:24 +00:00
|
|
|
* cc -I/usr/local/include -o signal-test \
|
|
|
|
* signal-test.c -L/usr/local/lib -levent
|
2002-04-10 00:31:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2004-05-24 00:19:52 +00:00
|
|
|
|
2009-11-06 21:46:57 +00:00
|
|
|
#include <event-config.h>
|
2007-03-01 06:25:18 +00:00
|
|
|
|
2002-04-10 00:31:31 +00:00
|
|
|
#include <sys/stat.h>
|
2003-09-25 03:29:37 +00:00
|
|
|
#ifndef WIN32
|
2002-04-10 00:31:31 +00:00
|
|
|
#include <sys/queue.h>
|
2003-09-25 03:29:37 +00:00
|
|
|
#include <unistd.h>
|
2002-04-10 00:31:31 +00:00
|
|
|
#include <sys/time.h>
|
2003-09-25 03:29:37 +00:00
|
|
|
#else
|
2009-07-28 19:41:39 +00:00
|
|
|
#include <winsock2.h>
|
2003-09-25 03:29:37 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2002-04-10 00:31:31 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <event.h>
|
|
|
|
|
2009-05-22 19:11:59 +00:00
|
|
|
#ifdef _EVENT___func__
|
|
|
|
#define __func__ _EVENT___func__
|
|
|
|
#endif
|
|
|
|
|
2002-04-10 00:31:31 +00:00
|
|
|
int called = 0;
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2010-03-05 12:47:46 -05:00
|
|
|
signal_cb(evutil_socket_t fd, short event, void *arg)
|
2002-04-10 00:31:31 +00:00
|
|
|
{
|
|
|
|
struct event *signal = arg;
|
|
|
|
|
2003-09-25 03:29:37 +00:00
|
|
|
printf("%s: got signal %d\n", __func__, EVENT_SIGNAL(signal));
|
2002-04-10 00:31:31 +00:00
|
|
|
|
|
|
|
if (called >= 2)
|
|
|
|
event_del(signal);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2002-04-10 00:31:31 +00:00
|
|
|
called++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-02-19 03:39:50 -05:00
|
|
|
main(int argc, char **argv)
|
2002-04-10 00:31:31 +00:00
|
|
|
{
|
|
|
|
struct event signal_int;
|
2009-12-08 17:02:24 -05:00
|
|
|
struct event_base* base;
|
2009-05-22 19:11:59 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
WORD wVersionRequested;
|
|
|
|
WSADATA wsaData;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
wVersionRequested = MAKEWORD(2, 2);
|
|
|
|
|
|
|
|
err = WSAStartup(wVersionRequested, &wsaData);
|
|
|
|
#endif
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2002-04-10 00:31:31 +00:00
|
|
|
/* Initalize the event library */
|
2009-12-08 17:02:24 -05:00
|
|
|
base = event_base_new();
|
2002-04-10 00:31:31 +00:00
|
|
|
|
|
|
|
/* Initalize one event */
|
2009-12-08 17:02:24 -05:00
|
|
|
event_assign(&signal_int, base, SIGINT, EV_SIGNAL|EV_PERSIST, signal_cb,
|
2002-04-10 02:10:47 +00:00
|
|
|
&signal_int);
|
2002-04-10 00:31:31 +00:00
|
|
|
|
|
|
|
event_add(&signal_int, NULL);
|
|
|
|
|
2009-12-08 17:02:24 -05:00
|
|
|
event_base_dispatch(base);
|
|
|
|
event_base_free(base);
|
2002-04-10 00:31:31 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|