49 lines
1.2 KiB
C
49 lines
1.2 KiB
C
// Zak's kqueue implementation
|
|
#ifndef SYS_EVENT_H
|
|
#define SYS_EVENT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
// The kevent structure is used for waiting/receiving notifications.
|
|
struct kevent {
|
|
uintptr_t ident;
|
|
int16_t filter;
|
|
uint16_t flags;
|
|
uint32_t fflags;
|
|
int64_t data;
|
|
void* udata;
|
|
uint64_t ext[4];
|
|
};
|
|
|
|
// kqueue1 is the kqueue system call with a flags argument,
|
|
// as defined on NetBSD & OpenBSD.
|
|
int kqueue1(int flags);
|
|
|
|
// kqueue() without flags is equivalent to kqueue1(0)
|
|
#define kqueue() kqueue1(0)
|
|
|
|
// On FreeBSD, kqueue1 is also known as kqueuex
|
|
#define kqueuex(flags) kqueue1(flags)
|
|
|
|
// After creating a kqueue, kevent is the main syscall used.
|
|
// This accepts a list of changes and can receive multiple events.
|
|
int kevent(int queue, const struct kevent* changes, int nch, struct kevent* events, int nev, void* todo_timeout);
|
|
|
|
// The EV_SET() macro is for initialising a struct kevent*
|
|
#define EV_SET(ev,idn,flt,flg,ffl,dat,udt) \
|
|
do { \
|
|
(ev)->ident = idn; \
|
|
(ev)->filter = flt; \
|
|
(ev)->flags = flg; \
|
|
(ev)->fflags = ffl; \
|
|
(ev)->data = dat; \
|
|
(ev)->udata = udt; \
|
|
(ev)->ext[0] = 0; \
|
|
(ev)->ext[1] = 0; \
|
|
(ev)->ext[2] = 0; \
|
|
(ev)->ext[3] = 0; \
|
|
} while(0)
|
|
|
|
// From ifndef at top of file:
|
|
#endif
|