… | |
… | |
703 | events but its callback has not yet been invoked). As long as a watcher |
703 | events but its callback has not yet been invoked). As long as a watcher |
704 | is pending (but not active) you must not call an init function on it (but |
704 | is pending (but not active) you must not call an init function on it (but |
705 | C<ev_TYPE_set> is safe) and you must make sure the watcher is available to |
705 | C<ev_TYPE_set> is safe) and you must make sure the watcher is available to |
706 | libev (e.g. you cnanot C<free ()> it). |
706 | libev (e.g. you cnanot C<free ()> it). |
707 | |
707 | |
708 | =item callback = ev_cb (ev_TYPE *watcher) |
708 | =item callback ev_cb (ev_TYPE *watcher) |
709 | |
709 | |
710 | Returns the callback currently set on the watcher. |
710 | Returns the callback currently set on the watcher. |
711 | |
711 | |
712 | =item ev_cb_set (ev_TYPE *watcher, callback) |
712 | =item ev_cb_set (ev_TYPE *watcher, callback) |
713 | |
713 | |
… | |
… | |
741 | { |
741 | { |
742 | struct my_io *w = (struct my_io *)w_; |
742 | struct my_io *w = (struct my_io *)w_; |
743 | ... |
743 | ... |
744 | } |
744 | } |
745 | |
745 | |
746 | More interesting and less C-conformant ways of catsing your callback type |
746 | More interesting and less C-conformant ways of casting your callback type |
747 | have been omitted.... |
747 | instead have been omitted. |
|
|
748 | |
|
|
749 | Another common scenario is having some data structure with multiple |
|
|
750 | watchers: |
|
|
751 | |
|
|
752 | struct my_biggy |
|
|
753 | { |
|
|
754 | int some_data; |
|
|
755 | ev_timer t1; |
|
|
756 | ev_timer t2; |
|
|
757 | } |
|
|
758 | |
|
|
759 | In this case getting the pointer to C<my_biggy> is a bit more complicated, |
|
|
760 | you need to use C<offsetof>: |
|
|
761 | |
|
|
762 | #include <stddef.h> |
|
|
763 | |
|
|
764 | static void |
|
|
765 | t1_cb (EV_P_ struct ev_timer *w, int revents) |
|
|
766 | { |
|
|
767 | struct my_biggy big = (struct my_biggy * |
|
|
768 | (((char *)w) - offsetof (struct my_biggy, t1)); |
|
|
769 | } |
|
|
770 | |
|
|
771 | static void |
|
|
772 | t2_cb (EV_P_ struct ev_timer *w, int revents) |
|
|
773 | { |
|
|
774 | struct my_biggy big = (struct my_biggy * |
|
|
775 | (((char *)w) - offsetof (struct my_biggy, t2)); |
|
|
776 | } |
748 | |
777 | |
749 | |
778 | |
750 | =head1 WATCHER TYPES |
779 | =head1 WATCHER TYPES |
751 | |
780 | |
752 | This section describes each watcher in detail, but will not repeat |
781 | This section describes each watcher in detail, but will not repeat |
… | |
… | |
1985 | |
2014 | |
1986 | =item EV_USE_DEVPOLL |
2015 | =item EV_USE_DEVPOLL |
1987 | |
2016 | |
1988 | reserved for future expansion, works like the USE symbols above. |
2017 | reserved for future expansion, works like the USE symbols above. |
1989 | |
2018 | |
|
|
2019 | =item EV_USE_INOTIFY |
|
|
2020 | |
|
|
2021 | If defined to be C<1>, libev will compile in support for the Linux inotify |
|
|
2022 | interface to speed up C<ev_stat> watchers. Its actual availability will |
|
|
2023 | be detected at runtime. |
|
|
2024 | |
1990 | =item EV_H |
2025 | =item EV_H |
1991 | |
2026 | |
1992 | The name of the F<ev.h> header file used to include it. The default if |
2027 | The name of the F<ev.h> header file used to include it. The default if |
1993 | undefined is C<< <ev.h> >> in F<event.h> and C<"ev.h"> in F<ev.c>. This |
2028 | undefined is C<< <ev.h> >> in F<event.h> and C<"ev.h"> in F<ev.c>. This |
1994 | can be used to virtually rename the F<ev.h> header file in case of conflicts. |
2029 | can be used to virtually rename the F<ev.h> header file in case of conflicts. |
… | |
… | |
2049 | =item EV_PID_HASHSIZE |
2084 | =item EV_PID_HASHSIZE |
2050 | |
2085 | |
2051 | C<ev_child> watchers use a small hash table to distribute workload by |
2086 | C<ev_child> watchers use a small hash table to distribute workload by |
2052 | pid. The default size is C<16> (or C<1> with C<EV_MINIMAL>), usually more |
2087 | pid. The default size is C<16> (or C<1> with C<EV_MINIMAL>), usually more |
2053 | than enough. If you need to manage thousands of children you might want to |
2088 | than enough. If you need to manage thousands of children you might want to |
2054 | increase this value. |
2089 | increase this value (I<must> be a power of two). |
|
|
2090 | |
|
|
2091 | =item EV_INOTIFY_HASHSIZE |
|
|
2092 | |
|
|
2093 | C<ev_staz> watchers use a small hash table to distribute workload by |
|
|
2094 | inotify watch id. The default size is C<16> (or C<1> with C<EV_MINIMAL>), |
|
|
2095 | usually more than enough. If you need to manage thousands of C<ev_stat> |
|
|
2096 | watchers you might want to increase this value (I<must> be a power of |
|
|
2097 | two). |
2055 | |
2098 | |
2056 | =item EV_COMMON |
2099 | =item EV_COMMON |
2057 | |
2100 | |
2058 | By default, all watchers have a C<void *data> member. By redefining |
2101 | By default, all watchers have a C<void *data> member. By redefining |
2059 | this macro to a something else you can include more and other types of |
2102 | this macro to a something else you can include more and other types of |
… | |
… | |
2119 | |
2162 | |
2120 | =item Starting io/check/prepare/idle/signal/child watchers: O(1) |
2163 | =item Starting io/check/prepare/idle/signal/child watchers: O(1) |
2121 | |
2164 | |
2122 | =item Stopping check/prepare/idle watchers: O(1) |
2165 | =item Stopping check/prepare/idle watchers: O(1) |
2123 | |
2166 | |
2124 | =item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % 16)) |
2167 | =item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE)) |
2125 | |
2168 | |
2126 | =item Finding the next timer per loop iteration: O(1) |
2169 | =item Finding the next timer per loop iteration: O(1) |
2127 | |
2170 | |
2128 | =item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd) |
2171 | =item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd) |
2129 | |
2172 | |