/*
* BSD kqueue() based ioloop handler.
*
* Copyright (c) 2005 Vaclav Haisman <v.haisman@sh.cvut.cz>
*/
#include "lib.h"
#ifdef IOLOOP_KQUEUE
#include "array.h"
#include "ioloop-private.h"
#include <unistd.h>
#include <fcntl.h>
/* kevent.udata's type just has to be different in NetBSD than in
FreeBSD and OpenBSD.. */
#ifdef __NetBSD__
# define MY_EV_SET(a, b, c, d, e, f, g) \
#else
# define MY_EV_SET(a, b, c, d, e, f, g) \
EV_SET(a, b, c, d, e, f, g)
#endif
struct ioloop_handler_context {
int kq;
unsigned int deleted_count;
};
{
i_fatal("kqueue() in io_loop_handler_init() failed: %m");
}
{
i_error("close(kqueue) in io_loop_handler_deinit() failed: %m");
}
{
}
}
/* allow kevent() to return the maximum number of events
by keeping space allocated for each handle */
if (ctx->deleted_count > 0)
ctx->deleted_count--;
else
}
{
}
}
/* since we're not freeing memory in any case, just increase
deleted counter so next handle_add() can just decrease it
instead of appending to the events array */
ctx->deleted_count++;
}
{
unsigned int events_count;
/* get the time left for next timeout task */
/* wait for events */
if (events_count > 0) {
i_panic("kevent(events=%u, ts=%ld.%u) failed: %m",
}
} else {
if (msecs < 0)
i_panic("BUG: No IOs or timeouts set. Not waiting for infinity.");
ret = 0;
}
/* reference all IOs */
for (i = 0; i < ret; i++) {
}
/* execute timeout handlers */
for (i = 0; i < ret; i++) {
/* io_loop_handle_add() may cause events array reallocation,
so we have use array_idx() */
/* callback is NULL if io_remove() was already called */
}
}
#endif