2006-07-27 05:51:18 +04:00
|
|
|
/*
|
|
|
|
* Compile with:
|
|
|
|
* cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2008-03-23 15:33:04 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <time.h>
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <event.h>
|
2008-03-23 15:33:04 +03:00
|
|
|
#include <evutil.h>
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
int lasttime;
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
static void
|
2006-07-27 05:51:18 +04:00
|
|
|
timeout_cb(int fd, short event, void *arg)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
2008-03-23 15:33:04 +03:00
|
|
|
struct event *timeout = arg;
|
2006-07-27 05:51:18 +04:00
|
|
|
int newtime = time(NULL);
|
|
|
|
|
|
|
|
printf("%s: called at %d: %d\n", __func__, newtime,
|
|
|
|
newtime - lasttime);
|
|
|
|
lasttime = newtime;
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
evutil_timerclear(&tv);
|
2006-07-27 05:51:18 +04:00
|
|
|
tv.tv_sec = 2;
|
2008-03-23 15:33:04 +03:00
|
|
|
event_add(timeout, &tv);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
struct event timeout;
|
2006-07-27 05:51:18 +04:00
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
/* Initalize the event library */
|
2008-03-23 15:33:04 +03:00
|
|
|
event_init();
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
/* Initalize one event */
|
2008-03-23 15:33:04 +03:00
|
|
|
evtimer_set(&timeout, timeout_cb, &timeout);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
evutil_timerclear(&tv);
|
2006-07-27 05:51:18 +04:00
|
|
|
tv.tv_sec = 2;
|
2008-03-23 15:33:04 +03:00
|
|
|
event_add(&timeout, &tv);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
lasttime = time(NULL);
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
event_dispatch();
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|