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

Comparing libev/ev.pod (file contents):
Revision 1.176 by root, Mon Sep 8 17:24:39 2008 UTC vs.
Revision 1.178 by root, Sat Sep 13 18:25:50 2008 UTC

1006 { 1006 {
1007 struct ev_io io; 1007 struct ev_io io;
1008 int otherfd; 1008 int otherfd;
1009 void *somedata; 1009 void *somedata;
1010 struct whatever *mostinteresting; 1010 struct whatever *mostinteresting;
1011 } 1011 };
1012
1013 ...
1014 struct my_io w;
1015 ev_io_init (&w.io, my_cb, fd, EV_READ);
1012 1016
1013And since your callback will be called with a pointer to the watcher, you 1017And since your callback will be called with a pointer to the watcher, you
1014can cast it back to your own type: 1018can cast it back to your own type:
1015 1019
1016 static void my_cb (struct ev_loop *loop, struct ev_io *w_, int revents) 1020 static void my_cb (struct ev_loop *loop, struct ev_io *w_, int revents)
1020 } 1024 }
1021 1025
1022More interesting and less C-conformant ways of casting your callback type 1026More interesting and less C-conformant ways of casting your callback type
1023instead have been omitted. 1027instead have been omitted.
1024 1028
1025Another common scenario is having some data structure with multiple 1029Another common scenario is to use some data structure with multiple
1026watchers: 1030embedded watchers:
1027 1031
1028 struct my_biggy 1032 struct my_biggy
1029 { 1033 {
1030 int some_data; 1034 int some_data;
1031 ev_timer t1; 1035 ev_timer t1;
1032 ev_timer t2; 1036 ev_timer t2;
1033 } 1037 }
1034 1038
1035In this case getting the pointer to C<my_biggy> is a bit more complicated, 1039In this case getting the pointer to C<my_biggy> is a bit more
1036you need to use C<offsetof>: 1040complicated: Either you store the address of your C<my_biggy> struct
1041in the C<data> member of the watcher, or you need to use some pointer
1042arithmetic using C<offsetof> inside your watchers:
1037 1043
1038 #include <stddef.h> 1044 #include <stddef.h>
1039 1045
1040 static void 1046 static void
1041 t1_cb (EV_P_ struct ev_timer *w, int revents) 1047 t1_cb (EV_P_ struct ev_timer *w, int revents)
1229you suspect event processing to be delayed and you I<need> to base the 1235you suspect event processing to be delayed and you I<need> to base the
1230timeout on the current time, use something like this to adjust for this: 1236timeout on the current time, use something like this to adjust for this:
1231 1237
1232 ev_timer_set (&timer, after + ev_now () - ev_time (), 0.); 1238 ev_timer_set (&timer, after + ev_now () - ev_time (), 0.);
1233 1239
1234If the event loop is suspended for a long time, one can also force an 1240If the event loop is suspended for a long time, you can also force an
1235update of the time returned by C<ev_now ()> by calling C<ev_now_update 1241update of the time returned by C<ev_now ()> by calling C<ev_now_update
1236()>. 1242()>.
1237 1243
1238=head3 Watcher-Specific Functions and Data Members 1244=head3 Watcher-Specific Functions and Data Members
1239 1245

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines