freebsd - using kqueue for EVFILT_USER -


i have trouble understand, how use kqueue user space events.
2 use cases.
use case 1: manual reset event
use case 2: auto reset event

i think understand, how use kqueue() , kevent(), yet unclear on how events passed kevent() related operations:
let there struct kevent variable named "event".
let assume, have no problem finding new event id not colliding other event ids kqueue instance, named "eventid".

  1. create user event: ev_set(&event, eventid, evfilt_user, ev_add, note_ffnop, 0, null)
  2. destroy user event: ev_set(&event, eventid, evfilt_user, ev_destroy, note_ffnop, 0, null)
  3. set user event: ev_set(&event, eventid, evfilt_user, ?????, note_ffnop, 0, null)
  4. reset user event: ev_set(&event, eventid, evfilt_user, ??ev_clear???, note_ffnop, 0, null )
  5. pulse user event: ev_set(&event, eventid, evfilt_user, 0, note_trigger, 0, null )
  6. in wait loop, think snipped along: if( event.filter == evfilt_user && event.ident == eventid ) { // event! something! }

see ???? in above ev_set() calls see need help.
use case 1 (manual reset event), operation (1) create might different compared use case 2 (auto reset event).
operations (3) , (4) in dark. might need ev_enable/ev_disable those? ev_clear fitting in?
far assume not need in operation (6) beyond "dispatching". pretty positive, operation (5) work gave above.

i spent better of day trying find documentation or samples showing how done. found in apple codebase kqueue test program doubt, doing right. also, sends 1 event in test , event terminates loop of receiving thread. not helping me understand details 2 use cases.

i plan use under freebsd 9.1 on x86 machine...for now.

after experimenting, found:

  1. create user event: ev_set(&ev, identifier, evfilt_user, ev_add, note_ffcopy, 0, null )
  2. destroy user event: ev_set(&ev, identifier, evfilt_user, ev_delete, 0, 0, 0)
  3. set user event: ev_set( &event, m_eventid, evfilt_user, ev_enable, note_ffcopy|note_trigger|0x1, 0, null )
  4. reset user event: ev_set( &event, m_eventid, evfilt_user, ev_disable, ev_clear|note_ffcopy, 0, null )
  5. pulse user event: not tested...did use case 1 now.
  6. wait code snippet: given in original post.

test works charm. in test did note_ffcopy thing don't think necessary.

the user events have 2 states - signalled, not signalled. ev_enable , ev_disable set states seems.

the test verified, events in signalled state reported kevent() repeatedly.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -