File: iom_add.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (28 lines) | stat: -rw-r--r-- 787 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "io_internal.h"
#ifdef HAVE_EPOLL
#include <sys/epoll.h>
#endif
#ifdef HAVE_KQUEUE
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#endif

int iom_add(iomux_t* c,int64 s,unsigned int events) {
#ifdef HAVE_EPOLL
  struct epoll_event e = { .events=EPOLLONESHOT, .data.fd=s };
  if (events & IOM_READ) e.events|=EPOLLIN;
  if (events & IOM_WRITE) e.events|=EPOLLOUT;
  return epoll_ctl(c->ctx, EPOLL_CTL_ADD, s, &e);
#elif defined(HAVE_KQUEUE)
  struct kevent kev;
  struct timespec ts = { 0 };
  EV_SET(&kev, s,
	 (events & IOM_READ ? EVFILT_READ : 0) +
	 (events & IOM_WRITE ? EVFILT_WRITE : 0),
	 EV_ADD | EV_ENABLE | EV_ONESHOT, 0, 0, (void*)s);
  return kevent(c->ctx, &kev, 1, 0, 0, &ts);
#else
#warning "only epoll and kqueue supported for now"
#endif
}