--- libev/ev.pod 2008/09/08 17:24:39 1.176 +++ libev/ev.pod 2008/09/13 18:25:50 1.178 @@ -1008,7 +1008,11 @@ int otherfd; void *somedata; struct whatever *mostinteresting; - } + }; + + ... + struct my_io w; + ev_io_init (&w.io, my_cb, fd, EV_READ); And since your callback will be called with a pointer to the watcher, you can cast it back to your own type: @@ -1022,8 +1026,8 @@ More interesting and less C-conformant ways of casting your callback type instead have been omitted. -Another common scenario is having some data structure with multiple -watchers: +Another common scenario is to use some data structure with multiple +embedded watchers: struct my_biggy { @@ -1032,8 +1036,10 @@ ev_timer t2; } -In this case getting the pointer to C is a bit more complicated, -you need to use C: +In this case getting the pointer to C is a bit more +complicated: Either you store the address of your C struct +in the C member of the watcher, or you need to use some pointer +arithmetic using C inside your watchers: #include @@ -1231,7 +1237,7 @@ ev_timer_set (&timer, after + ev_now () - ev_time (), 0.); -If the event loop is suspended for a long time, one can also force an +If the event loop is suspended for a long time, you can also force an update of the time returned by C by calling C.