A clone of btpd with my configuration changes.

71 lines
1.1 KiB

  1. /*
  2. * Compile with:
  3. * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
  4. */
  5. #include <sys/types.h>
  6. #ifdef HAVE_CONFIG_H
  7. #include "config.h"
  8. #endif
  9. #include <sys/stat.h>
  10. #ifndef WIN32
  11. #include <sys/queue.h>
  12. #include <unistd.h>
  13. #else
  14. #include <time.h>
  15. #endif
  16. #ifdef HAVE_SYS_TIME_H
  17. #include <sys/time.h>
  18. #endif
  19. #include <fcntl.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <errno.h>
  24. #include <event.h>
  25. int lasttime;
  26. void
  27. timeout_cb(int fd, short event, void *arg)
  28. {
  29. struct timeval tv;
  30. struct event *timeout = arg;
  31. int newtime = time(NULL);
  32. printf("%s: called at %d: %d\n", __func__, newtime,
  33. newtime - lasttime);
  34. lasttime = newtime;
  35. timerclear(&tv);
  36. tv.tv_sec = 2;
  37. event_add(timeout, &tv);
  38. }
  39. int
  40. main (int argc, char **argv)
  41. {
  42. struct event timeout;
  43. struct timeval tv;
  44. /* Initalize the event library */
  45. event_init();
  46. /* Initalize one event */
  47. evtimer_set(&timeout, timeout_cb, &timeout);
  48. timerclear(&tv);
  49. tv.tv_sec = 2;
  50. event_add(&timeout, &tv);
  51. lasttime = time(NULL);
  52. event_dispatch();
  53. return (0);
  54. }