ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.54 by root, Tue Nov 27 20:26:51 2007 UTC vs.
Revision 1.57 by root, Wed Nov 28 11:27:29 2007 UTC

703events but its callback has not yet been invoked). As long as a watcher 703events but its callback has not yet been invoked). As long as a watcher
704is pending (but not active) you must not call an init function on it (but 704is pending (but not active) you must not call an init function on it (but
705C<ev_TYPE_set> is safe) and you must make sure the watcher is available to 705C<ev_TYPE_set> is safe) and you must make sure the watcher is available to
706libev (e.g. you cnanot C<free ()> it). 706libev (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
710Returns the callback currently set on the watcher. 710Returns 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
746More interesting and less C-conformant ways of catsing your callback type 746More interesting and less C-conformant ways of casting your callback type
747have been omitted.... 747instead have been omitted.
748
749Another common scenario is having some data structure with multiple
750watchers:
751
752 struct my_biggy
753 {
754 int some_data;
755 ev_timer t1;
756 ev_timer t2;
757 }
758
759In this case getting the pointer to C<my_biggy> is a bit more complicated,
760you 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
752This section describes each watcher in detail, but will not repeat 781This section describes each watcher in detail, but will not repeat
1193not exist" is signified by the C<st_nlink> field being zero (which is 1222not exist" is signified by the C<st_nlink> field being zero (which is
1194otherwise always forced to be at least one) and all the other fields of 1223otherwise always forced to be at least one) and all the other fields of
1195the stat buffer having unspecified contents. 1224the stat buffer having unspecified contents.
1196 1225
1197Since there is no standard to do this, the portable implementation simply 1226Since there is no standard to do this, the portable implementation simply
1198calls C<stat (2)> regulalry on the path to see if it changed somehow. You 1227calls C<stat (2)> regularly on the path to see if it changed somehow. You
1199can specify a recommended polling interval for this case. If you specify 1228can specify a recommended polling interval for this case. If you specify
1200a polling interval of C<0> (highly recommended!) then a I<suitable, 1229a polling interval of C<0> (highly recommended!) then a I<suitable,
1201unspecified default> value will be used (which you can expect to be around 1230unspecified default> value will be used (which you can expect to be around
1202five seconds, although this might change dynamically). Libev will also 1231five seconds, although this might change dynamically). Libev will also
1203impose a minimum interval which is currently around C<0.1>, but thats 1232impose a minimum interval which is currently around C<0.1>, but thats
1205 1234
1206This watcher type is not meant for massive numbers of stat watchers, 1235This watcher type is not meant for massive numbers of stat watchers,
1207as even with OS-supported change notifications, this can be 1236as even with OS-supported change notifications, this can be
1208resource-intensive. 1237resource-intensive.
1209 1238
1210At the time of this writing, no specific OS backends are implemented, but 1239At the time of this writing, only the Linux inotify interface is
1211if demand increases, at least a kqueue and inotify backend will be added. 1240implemented (implementing kqueue support is left as an exercise for the
1241reader). Inotify will be used to give hints only and should not change the
1242semantics of C<ev_stat> watchers, which means that libev sometimes needs
1243to fall back to regular polling again even with inotify, but changes are
1244usually detected immediately, and if the file exists there will be no
1245polling.
1212 1246
1213=over 4 1247=over 4
1214 1248
1215=item ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval) 1249=item ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)
1216 1250
1985 2019
1986=item EV_USE_DEVPOLL 2020=item EV_USE_DEVPOLL
1987 2021
1988reserved for future expansion, works like the USE symbols above. 2022reserved for future expansion, works like the USE symbols above.
1989 2023
2024=item EV_USE_INOTIFY
2025
2026If defined to be C<1>, libev will compile in support for the Linux inotify
2027interface to speed up C<ev_stat> watchers. Its actual availability will
2028be detected at runtime.
2029
1990=item EV_H 2030=item EV_H
1991 2031
1992The name of the F<ev.h> header file used to include it. The default if 2032The name of the F<ev.h> header file used to include it. The default if
1993undefined is C<< <ev.h> >> in F<event.h> and C<"ev.h"> in F<ev.c>. This 2033undefined is C<< <ev.h> >> in F<event.h> and C<"ev.h"> in F<ev.c>. This
1994can be used to virtually rename the F<ev.h> header file in case of conflicts. 2034can be used to virtually rename the F<ev.h> header file in case of conflicts.
2049=item EV_PID_HASHSIZE 2089=item EV_PID_HASHSIZE
2050 2090
2051C<ev_child> watchers use a small hash table to distribute workload by 2091C<ev_child> watchers use a small hash table to distribute workload by
2052pid. The default size is C<16> (or C<1> with C<EV_MINIMAL>), usually more 2092pid. The default size is C<16> (or C<1> with C<EV_MINIMAL>), usually more
2053than enough. If you need to manage thousands of children you might want to 2093than enough. If you need to manage thousands of children you might want to
2054increase this value. 2094increase this value (I<must> be a power of two).
2095
2096=item EV_INOTIFY_HASHSIZE
2097
2098C<ev_staz> watchers use a small hash table to distribute workload by
2099inotify watch id. The default size is C<16> (or C<1> with C<EV_MINIMAL>),
2100usually more than enough. If you need to manage thousands of C<ev_stat>
2101watchers you might want to increase this value (I<must> be a power of
2102two).
2055 2103
2056=item EV_COMMON 2104=item EV_COMMON
2057 2105
2058By default, all watchers have a C<void *data> member. By redefining 2106By default, all watchers have a C<void *data> member. By redefining
2059this macro to a something else you can include more and other types of 2107this macro to a something else you can include more and other types of
2119 2167
2120=item Starting io/check/prepare/idle/signal/child watchers: O(1) 2168=item Starting io/check/prepare/idle/signal/child watchers: O(1)
2121 2169
2122=item Stopping check/prepare/idle watchers: O(1) 2170=item Stopping check/prepare/idle watchers: O(1)
2123 2171
2124=item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % 16)) 2172=item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))
2125 2173
2126=item Finding the next timer per loop iteration: O(1) 2174=item Finding the next timer per loop iteration: O(1)
2127 2175
2128=item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd) 2176=item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)
2129 2177

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines