#ifdef HAVE_SYS_EVENT_H
#include <sys/event.h>
+#include <errno.h>
#define MAX_EVENTS 32
res = kevent(kevent_fd, changes, nchanges, NULL, 0, NULL);
if(res < 0)
iohandler_log(IOLOG_ERROR, "could not add IODescriptor %d to kevent queue. (returned: %d)", res);
- }
}
static void engine_kevent_remove(struct IODescriptor *iofd) {
static void engine_kevent_update(struct IODescriptor *iofd) {
if(iofd->type == IOTYPE_TIMER) return;
+ if(iofd->state == IO_CLOSED) {
+ engine_kevent_remove(iofd);
+ return;
+ }
struct kevent changes[2];
int nchanges = 0;
int res;
}
static void engine_kevent_loop(struct timeval *timeout) {
- struct kevent evts[MAX_EVENTS];
+ struct kevent events[MAX_EVENTS];
struct timeval now, tdiff;
- struct timespec ts, *ptr
+ struct timespec ts, *pts;
int msec;
- int events;
int kevent_result;
gettimeofday(&now, NULL);
tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) {
- iohandler_events(timer_priority, 0, 0);
- iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+ if(timer_priority->constant_timeout) {
+ tdiff.tv_sec = 0;
+ iohandler_set_timeout(timer_priority, &tdiff);
+ iohandler_events(timer_priority, 0, 0);
+ } else {
+ iohandler_events(timer_priority, 0, 0);
+ iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+ }
continue;
} else if(tdiff.tv_usec < 0) {
tdiff.tv_sec--;
}
//select system call
- kevent_result = kevent(kq_fd, NULL, 0, events, MAX_EVENTS, pts);
+ kevent_result = kevent(kevent_fd, NULL, 0, events, MAX_EVENTS, pts);
if (kevent_result < 0) {
if (errno != EINTR) {
} else {
int i;
for(i = 0; i < kevent_result; i++)
- iohandler_events(evts[i].udata, (evts[i].filter == EVFILT_READ), (evts[i].filter == EVFILT_WRITE));
+ iohandler_events(events[i].udata, (events[i].filter == EVFILT_READ), (events[i].filter == EVFILT_WRITE));
}
//check timers
tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) {
- iohandler_events(timer_priority, 0, 0);
- iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+ if(timer_priority->constant_timeout) {
+ tdiff.tv_sec = 0;
+ iohandler_set_timeout(timer_priority, &tdiff);
+ iohandler_events(timer_priority, 0, 0);
+ } else {
+ iohandler_events(timer_priority, 0, 0);
+ iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+ }
continue;
}
break;