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.55 by root, Tue Nov 27 20:38:07 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines