2#if defined(__FreeBSD__) || defined(__OpenBSD__)
25#if defined(__NetBSD__)
26 #define KEVENT_UDATA_DATATYPE __intptr_t
28 #define KEVENT_UDATA_DATATYPE void*
31KernelEventMechanism::KernelEventMechanism() : initialized(false),_psd(NULL) {
47 if (psd->kqChangeListCurrent + 2 >= psd->kqChangeListMax) {
49 bool reallocated =
false;
50 auto kqChangeList0Resized = (
struct kevent*)realloc(psd->kqChangeList[0],
sizeof(
struct kevent) * (psd->kqChangeListMax << 1));
51 auto kqChangeList1Resized = (
struct kevent*)realloc(psd->kqChangeList[1],
sizeof(
struct kevent) * (psd->kqChangeListMax << 1));
54 if (kqChangeList0Resized == NULL || kqChangeList1Resized == NULL) {
58 if (kqChangeList0Resized != NULL) psd->kqChangeList[0] = kqChangeList0Resized;
59 if (kqChangeList1Resized != NULL) psd->kqChangeList[1] = kqChangeList1Resized;
64 psd->kqChangeListMax<<=1;
66 psd->kqChangeList[0] = kqChangeList0Resized;
67 psd->kqChangeList[1] = kqChangeList1Resized;
71 if (reallocated ==
false) {
72 psd->kqMutex.unlock();
78 struct kevent* ke = &psd->kqChangeList[psd->kqChangeListBuffer][psd->kqChangeListCurrent++];
80 ke->filter = EVFILT_READ;
81 ke->flags = EV_ADD | EV_ENABLE;
86 struct kevent* ke = &psd->kqChangeList[psd->kqChangeListBuffer][psd->kqChangeListCurrent++];
88 ke->filter = EVFILT_READ;
89 ke->flags = EV_ADD | EV_DISABLE;
96 struct kevent* ke = &psd->kqChangeList[psd->kqChangeListBuffer][psd->kqChangeListCurrent++];
98 ke->filter = EVFILT_WRITE;
99 ke->flags = EV_ADD | EV_ENABLE;
104 struct kevent* ke = &psd->kqChangeList[psd->kqChangeListBuffer][psd->kqChangeListCurrent++];
106 ke->filter = EVFILT_WRITE;
107 ke->flags = EV_ADD | EV_DISABLE;
112 psd->kqMutex.unlock();
123 psd->
kqChangeList = (
struct kevent**)malloc(
sizeof(
void*) * 2);
153 std::string msg =
"Could not create kqueue: ";
154 msg+= strerror(errno);
170 free(psd->kqChangeList[0]);
171 free(psd->kqChangeList[1]);
172 free(psd->kqChangeList);
173 free(psd->kqEventList);
184 const struct timespec timeout = {0, 1L * 1000L * 1000L};
187 while (
true ==
true) {
208 kqChangeListFilledCurrent,
216 if (errno == EINTR) {
219 std::string msg =
"kevent failed: ";
220 msg+= strerror(errno);
235 cookie = (
void*)ke->udata;
236 switch (ke->filter) {
#define KEVENT_UDATA_DATATYPE
Interface to kernel event mechanismns.
void shutdownKernelEventMechanism()
shutdowns the kernel event mechanism
void setSocketInterest(const NetworkSocket &socket, const NIOInterest lastInterest, const NIOInterest interest, const void *cookie)
sets a non blocked socket io interest
int doKernelEventMechanism()
do the kernel event mechanism
void initKernelEventMechanism(const unsigned int maxCCU)
initializes the kernel event mechanism
~KernelEventMechanism()
destructor
void decodeKernelEvent(const unsigned int index, NIOInterest &interest, void *&cookie)
decodes a kernel event
Kernel event mechanism exception class.
Base class of network sockets.
void unlock()
Unlocks this mutex.
void lock()
Locks the mutex, additionally mutex locks will block until other locks have been unlocked.
const NIOInterest NIO_INTEREST_NONE
const NIOInterest NIO_INTEREST_READ
uint8_t NIOInterest
type definiton for network UI interest
const NIOInterest NIO_INTEREST_WRITE