Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 lines
765 B

  1. #include "io_internal.h"
  2. #ifdef HAVE_EPOLL
  3. #include <sys/epoll.h>
  4. #endif
  5. #ifdef HAVE_KQUEUE
  6. #include <sys/types.h>
  7. #include <sys/event.h>
  8. #include <sys/time.h>
  9. #endif
  10. int iom_init(iomux_t* c) {
  11. #ifdef HAVE_EPOLL
  12. c->ctx = epoll_create1(EPOLL_CLOEXEC);
  13. #elif defined(HAVE_KQUEUE)
  14. if ((c->ctx = kqueue()) != -1) {
  15. if (fcntl(c->ctx,F_SETFD,FD_CLOEXEC) == -1) {
  16. close(c->ctx);
  17. c->ctx=-1;
  18. }
  19. }
  20. #else
  21. #warning "only epoll and kqueue supported for now"
  22. #endif
  23. unsigned int i;
  24. c->working=0;
  25. c->h=c->l=0; /* no elements in queue */
  26. for (i=0; i<SLOTS; ++i) {
  27. c->q[i].fd=-1;
  28. c->q[i].events=0;
  29. }
  30. #ifdef __dietlibc__
  31. mtx_init(&c->mtx, mtx_timed);
  32. cnd_init(&c->sem);
  33. #else
  34. sem_init(&c->sem, 0, 1);
  35. #endif
  36. return (c->ctx!=-1);
  37. }