A clone of btpd with my configuration changes.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

69 lignes
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 <sys/socket.h>
  9. #include <fcntl.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <unistd.h>
  14. #include <errno.h>
  15. #include <event.h>
  16. int test_okay = 1;
  17. int called = 0;
  18. void
  19. read_cb(int fd, short event, void *arg)
  20. {
  21. char buf[256];
  22. int len;
  23. len = read(fd, buf, sizeof(buf));
  24. printf("%s: read %d%s\n", __func__,
  25. len, len ? "" : " - means EOF");
  26. if (len) {
  27. if (!called)
  28. event_add(arg, NULL);
  29. } else if (called == 1)
  30. test_okay = 0;
  31. called++;
  32. }
  33. int
  34. main (int argc, char **argv)
  35. {
  36. struct event ev;
  37. char *test = "test string";
  38. int pair[2];
  39. if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
  40. return (1);
  41. write(pair[0], test, strlen(test)+1);
  42. shutdown(pair[0], SHUT_WR);
  43. /* Initalize the event library */
  44. event_init();
  45. /* Initalize one event */
  46. event_set(&ev, pair[1], EV_READ, read_cb, &ev);
  47. event_add(&ev, NULL);
  48. event_dispatch();
  49. return (test_okay);
  50. }