From 59905999ce145a81e0003766d468945c2444a90e Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Fri, 9 Jan 2009 18:26:23 +0100 Subject: Add evloop, btpd's new event loop. This will replace libevent. --- evloop/evloop.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 evloop/evloop.h (limited to 'evloop/evloop.h') diff --git a/evloop/evloop.h b/evloop/evloop.h new file mode 100644 index 0000000..97f7665 --- /dev/null +++ b/evloop/evloop.h @@ -0,0 +1,57 @@ +#ifndef BTPD_EVLOOP_H +#define BTPD_EVLOOP_H + +#include +#include + +#include "timeheap.h" + +#define EV_READ 1 +#define EV_WRITE 2 +#define EV_TIMEOUT 3 + +typedef void (*evloop_cb_t)(int fd, short type, void *arg); + +#if defined(EVLOOP_EPOLL) || defined(EVLOOP_KQUEUE) + +struct fdev { + evloop_cb_t cb; + void *arg; + int fd; + uint16_t flags; + int16_t index; +}; + +#elif defined(EVLOOP_POLL) + +struct fdev { + int i; +}; + +#else +#error No evloop method defined. +#endif + +struct timeout { + evloop_cb_t cb; + void *arg; + struct th_handle th; +}; + +int evloop_init(void); +int evloop(void); + +int fdev_new(struct fdev *ev, int fd, uint16_t flags, evloop_cb_t cb, + void *arg); +int fdev_del(struct fdev *ev); +int fdev_enable(struct fdev *ev, uint16_t flags); +int fdev_disable(struct fdev *ev, uint16_t flags); + +void timer_init(struct timeout *, evloop_cb_t, void *); +int timer_add(struct timeout *, struct timespec *); +void timer_del(struct timeout *); + +void timers_run(void); +struct timespec timer_delay(void); + +#endif -- cgit 1.4.1