2004-02-12 18:55:09 +03:00
|
|
|
/*
|
|
|
|
* Compile with:
|
|
|
|
* cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
|
|
|
|
*/
|
|
|
|
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <sys/types.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#ifndef WIN32
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_QUEUE_H
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <sys/queue.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <sys/time.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-02-12 18:55:09 +03:00
|
|
|
#else
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
#include <signal.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <event.h>
|
|
|
|
|
|
|
|
int called = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
signal_cb(int fd, short event, void *arg)
|
|
|
|
{
|
2005-07-04 03:09:55 +04:00
|
|
|
struct opal_event *signal = arg;
|
2004-02-12 18:55:09 +03:00
|
|
|
|
2005-07-04 03:09:55 +04:00
|
|
|
printf("%s: got signal %d\n", __func__, OPAL_EVENT_SIGNAL(signal));
|
2004-02-12 18:55:09 +03:00
|
|
|
|
|
|
|
if (called >= 2)
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_del(signal);
|
2004-02-12 18:55:09 +03:00
|
|
|
|
|
|
|
called++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2005-07-04 03:09:55 +04:00
|
|
|
struct opal_event signal_int;
|
2004-02-12 18:55:09 +03:00
|
|
|
|
|
|
|
/* Initalize the event library */
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_init();
|
2004-02-12 18:55:09 +03:00
|
|
|
|
|
|
|
/* Initalize one event */
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_set(&signal_int, SIGINT, OPAL_EV_SIGNAL|OPAL_EV_PERSIST, signal_cb,
|
2004-02-12 18:55:09 +03:00
|
|
|
&signal_int);
|
|
|
|
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_add(&signal_int, NULL);
|
2004-02-12 18:55:09 +03:00
|
|
|
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_dispatch();
|
2004-02-12 18:55:09 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|