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