I have trouble to understand, how to use kqueue for user space events.
I look for 2 use cases.
Use case 1: Manual Reset event
Use case 2: Auto Reset event
I think I understand, how to use kqueue() and kevent(), yet I am unclear on how the events passed to kevent() look for the related operations:
Let there be a struct kevent variable named "event".
Let us assume, we have no problem finding a new event id which is not colliding with other event ids for that kqueue instance, named "eventId".
See the ???? in the above EV_SET() calls to see where I need help.
For use case 1 (Manual reset event), operation (1) Create might look different compared to use case 2 (auto reset event).
Operations (3) and (4) I am completely in the dark. Might I need EV_ENABLE/EV_DISABLE for those? Where is EV_CLEAR fitting in?
So far I assume that I do not need to do anything in operation (6) beyond the "dispatching".
I am pretty positive, that operation (5) could work as I gave it above.
I spent now the better of a day trying to find documentation or samples showing how it is done. I found in apple codebase a kqueue test program but I doubt, it is doing it right. Also, it only sends 1 event in the test and that event terminates the loop of the receiving thread. So it is not helping me to understand the details for my 2 use cases.
I plan to use it under FreeBsd 9.1 on a x86 machine...for now.
After some experimenting, I found:
Test works like a charm. In my test I did the NOTE_FFCOPY thing but I don't think it is necessary.
The user events have 2 states - signalled, not signalled. EV_ENABLE and EV_DISABLE set those states it seems.
The test verified, that the events in signalled state actually are reported by kevent() repeatedly.