A clone of btpd with my configuration changes.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

69 行
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. #include <sys/stat.h>
  7. #include <sys/time.h>
  8. #include <fcntl.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <unistd.h>
  13. #include <errno.h>
  14. #include <event.h>
  15. int called = 0;
  16. #define NEVENT 20000
  17. struct event *ev[NEVENT];
  18. void
  19. time_cb(int fd, short event, void *arg)
  20. {
  21. struct timeval tv;
  22. int i, j;
  23. called++;
  24. if (called < 10*NEVENT) {
  25. for (i = 0; i < 10; i++) {
  26. j = random() % NEVENT;
  27. tv.tv_sec = 0;
  28. tv.tv_usec = random() % 50000L;
  29. if (tv.tv_usec % 2)
  30. evtimer_add(ev[j], &tv);
  31. else
  32. evtimer_del(ev[j]);
  33. }
  34. }
  35. }
  36. int
  37. main (int argc, char **argv)
  38. {
  39. struct timeval tv;
  40. int i;
  41. /* Initalize the event library */
  42. event_init();
  43. for (i = 0; i < NEVENT; i++) {
  44. ev[i] = malloc(sizeof(struct event));
  45. /* Initalize one event */
  46. evtimer_set(ev[i], time_cb, ev[i]);
  47. tv.tv_sec = 0;
  48. tv.tv_usec = random() % 50000L;
  49. evtimer_add(ev[i], &tv);
  50. }
  51. event_dispatch();
  52. return (called < NEVENT);
  53. }