/*
* BSD kqueue() based ioloop notify handler.
*
* Copyright (c) 2005 Vaclav Haisman <v.haisman@sh.cvut.cz>
*/
#define _GNU_SOURCE
#include "lib.h"
#ifdef IOLOOP_NOTIFY_KQUEUE
#include "ioloop-private.h"
#include "llist.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 io_notify {
int refcount;
int fd;
};
struct ioloop_notify_handler_context {
int kq;
};
static void
{
}
{
int i, ret;
if (ret <= 0) {
return;
i_fatal("kevent(notify) failed: %m");
}
i_fatal("gettimeofday() failed: %m");
for (i = 0; i < ret; i++) {
}
for (i = 0; i < ret; i++) {
/* there can be multiple events for a single io.
call the callback only once if that happens. */
}
}
{
i_fatal("kqueue(notify) failed: %m");
return ctx;
}
{
i_warning("I/O notify leak: %p (%s:%u, fd %d)",
}
i_error("close(kqueue notify) failed: %m");
}
enum io_notify_result
unsigned int source_linenum,
{
int fd;
if (fd == -1) {
/* ESTALE could happen with NFS. Don't bother giving an error
message then. */
return IO_NOTIFY_NOTFOUND;
}
/* EV_CLEAR flag is needed because the EVFILT_VNODE filter reports
event state transitions and not the current state. With this flag,
the same event is only returned once. */
NOTE_REVOKE, 0, io);
i_close_fd(&fd);
return IO_NOTIFY_NOSUPPORT;
}
}
return IO_NOTIFY_ADDED;
}
{
}
{
return -1;
if (new_kq < 0) {
i_error("kqueue(notify) failed: %m");
return -1;
}
return fd;
}
#endif