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.
 
 
 
 

29 lines
787 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_add(iomux_t* c,int64 s,unsigned int events) {
  11. #ifdef HAVE_EPOLL
  12. struct epoll_event e = { .events=EPOLLONESHOT, .data.fd=s };
  13. if (events & IOM_READ) e.events|=EPOLLIN;
  14. if (events & IOM_WRITE) e.events|=EPOLLOUT;
  15. return epoll_ctl(c->ctx, EPOLL_CTL_ADD, s, &e);
  16. #elif defined(HAVE_KQUEUE)
  17. struct kevent kev;
  18. struct timespec ts = { 0 };
  19. EV_SET(&kev, s,
  20. (events & IOM_READ ? EVFILT_READ : 0) +
  21. (events & IOM_WRITE ? EVFILT_WRITE : 0),
  22. EV_ADD | EV_ENABLE | EV_ONESHOT, 0, 0, (void*)s);
  23. return kevent(c->ctx, &kev, 1, 0, 0, &ts);
  24. #else
  25. #warning "only epoll and kqueue supported for now"
  26. #endif
  27. }