… | |
… | |
856 | Returns a true value iff the watcher is pending, (i.e. it has outstanding |
856 | Returns a true value iff the watcher is pending, (i.e. it has outstanding |
857 | events but its callback has not yet been invoked). As long as a watcher |
857 | events but its callback has not yet been invoked). As long as a watcher |
858 | is pending (but not active) you must not call an init function on it (but |
858 | is pending (but not active) you must not call an init function on it (but |
859 | \&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe) and you must make sure the watcher is available to |
859 | \&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe) and you must make sure the watcher is available to |
860 | libev (e.g. you cnanot \f(CW\*(C`free ()\*(C'\fR it). |
860 | libev (e.g. you cnanot \f(CW\*(C`free ()\*(C'\fR it). |
861 | .IP "callback = ev_cb (ev_TYPE *watcher)" 4 |
861 | .IP "callback ev_cb (ev_TYPE *watcher)" 4 |
862 | .IX Item "callback = ev_cb (ev_TYPE *watcher)" |
862 | .IX Item "callback ev_cb (ev_TYPE *watcher)" |
863 | Returns the callback currently set on the watcher. |
863 | Returns the callback currently set on the watcher. |
864 | .IP "ev_cb_set (ev_TYPE *watcher, callback)" 4 |
864 | .IP "ev_cb_set (ev_TYPE *watcher, callback)" 4 |
865 | .IX Item "ev_cb_set (ev_TYPE *watcher, callback)" |
865 | .IX Item "ev_cb_set (ev_TYPE *watcher, callback)" |
866 | Change the callback. You can change the callback at virtually any time |
866 | Change the callback. You can change the callback at virtually any time |
867 | (modulo threads). |
867 | (modulo threads). |
… | |
… | |
893 | \& struct my_io *w = (struct my_io *)w_; |
893 | \& struct my_io *w = (struct my_io *)w_; |
894 | \& ... |
894 | \& ... |
895 | \& } |
895 | \& } |
896 | .Ve |
896 | .Ve |
897 | .PP |
897 | .PP |
898 | More interesting and less C\-conformant ways of catsing your callback type |
898 | More interesting and less C\-conformant ways of casting your callback type |
899 | have been omitted.... |
899 | instead have been omitted. |
|
|
900 | .PP |
|
|
901 | Another common scenario is having some data structure with multiple |
|
|
902 | watchers: |
|
|
903 | .PP |
|
|
904 | .Vb 6 |
|
|
905 | \& struct my_biggy |
|
|
906 | \& { |
|
|
907 | \& int some_data; |
|
|
908 | \& ev_timer t1; |
|
|
909 | \& ev_timer t2; |
|
|
910 | \& } |
|
|
911 | .Ve |
|
|
912 | .PP |
|
|
913 | In this case getting the pointer to \f(CW\*(C`my_biggy\*(C'\fR is a bit more complicated, |
|
|
914 | you need to use \f(CW\*(C`offsetof\*(C'\fR: |
|
|
915 | .PP |
|
|
916 | .Vb 1 |
|
|
917 | \& #include <stddef.h> |
|
|
918 | .Ve |
|
|
919 | .PP |
|
|
920 | .Vb 6 |
|
|
921 | \& static void |
|
|
922 | \& t1_cb (EV_P_ struct ev_timer *w, int revents) |
|
|
923 | \& { |
|
|
924 | \& struct my_biggy big = (struct my_biggy * |
|
|
925 | \& (((char *)w) - offsetof (struct my_biggy, t1)); |
|
|
926 | \& } |
|
|
927 | .Ve |
|
|
928 | .PP |
|
|
929 | .Vb 6 |
|
|
930 | \& static void |
|
|
931 | \& t2_cb (EV_P_ struct ev_timer *w, int revents) |
|
|
932 | \& { |
|
|
933 | \& struct my_biggy big = (struct my_biggy * |
|
|
934 | \& (((char *)w) - offsetof (struct my_biggy, t2)); |
|
|
935 | \& } |
|
|
936 | .Ve |
900 | .SH "WATCHER TYPES" |
937 | .SH "WATCHER TYPES" |
901 | .IX Header "WATCHER TYPES" |
938 | .IX Header "WATCHER TYPES" |
902 | This section describes each watcher in detail, but will not repeat |
939 | This section describes each watcher in detail, but will not repeat |
903 | information given in the last section. Any initialisation/set macros, |
940 | information given in the last section. Any initialisation/set macros, |
904 | functions and members specific to the watcher type are explained. |
941 | functions and members specific to the watcher type are explained. |