--- libev/ev.pod 2011/01/11 01:42:47 1.356 +++ libev/ev.pod 2011/02/20 02:56:23 1.367 @@ -60,7 +60,7 @@ // now wait for events to arrive ev_run (loop, 0); - // unloop was called, so exit + // break was called, so exit return 0; } @@ -444,6 +444,9 @@ want to handle signals only in specific threads and want to avoid libev unblocking the signals. +It's also required by POSIX in a threaded program, as libev calls +C, whose behaviour is officially unspecified. + This flag's behaviour will become the default in future versions of libev. =item C (value 1, portable select backend) @@ -867,7 +870,7 @@ ... queue jobs here, make sure they register event watchers as long ... as they still have work to do (even an idle watcher will do..) ev_run (my_loop, 0); - ... jobs done or somebody called unloop. yeah! + ... jobs done or somebody called break. yeah! =item ev_break (loop, how) @@ -1359,70 +1362,8 @@ =back -=head2 ASSOCIATING CUSTOM DATA WITH A WATCHER - -Each watcher has, by default, a member C that you can change -and read at any time: libev will completely ignore it. This can be used -to associate arbitrary data with your watcher. If you need more data and -don't want to allocate memory and store a pointer to it in that data -member, you can also "subclass" the watcher type and provide your own -data: - - struct my_io - { - ev_io io; - int otherfd; - void *somedata; - struct whatever *mostinteresting; - }; - - ... - struct my_io w; - ev_io_init (&w.io, my_cb, fd, EV_READ); - -And since your callback will be called with a pointer to the watcher, you -can cast it back to your own type: - - static void my_cb (struct ev_loop *loop, ev_io *w_, int revents) - { - struct my_io *w = (struct my_io *)w_; - ... - } - -More interesting and less C-conformant ways of casting your callback type -instead have been omitted. - -Another common scenario is to use some data structure with multiple -embedded watchers: - - struct my_biggy - { - int some_data; - ev_timer t1; - ev_timer t2; - } - -In this case getting the pointer to C is a bit more -complicated: Either you store the address of your C struct -in the C member of the watcher (for woozies), or you need to use -some pointer arithmetic using C inside your watchers (for real -programmers): - - #include - - static void - t1_cb (EV_P_ ev_timer *w, int revents) - { - struct my_biggy big = (struct my_biggy *) - (((char *)w) - offsetof (struct my_biggy, t1)); - } - - static void - t2_cb (EV_P_ ev_timer *w, int revents) - { - struct my_biggy big = (struct my_biggy *) - (((char *)w) - offsetof (struct my_biggy, t2)); - } +See also the L and L idioms. =head2 WATCHER STATES @@ -1439,8 +1380,10 @@ initialised. This can be done with a call to C, or calls to C followed by the watcher-specific C function. -In this state it is simply some block of memory that is suitable for use -in an event loop. It can be moved around, freed, reused etc. at will. +In this state it is simply some block of memory that is suitable for +use in an event loop. It can be moved around, freed, reused etc. at +will - as long as you either keep the memory contents intact, or call +C again. =item started/running/active @@ -1478,8 +1421,9 @@ freeing it is often a good idea. While stopped (and not pending) the watcher is essentially in the -initialised state, that is it can be reused, moved, modified in any way -you wish. +initialised state, that is, it can be reused, moved, modified in any way +you wish (but when you trash the memory block, you need to C +it again). =back @@ -1682,8 +1626,8 @@ Another way to view it is that in the case of sockets, pipes, character devices and so on, there is another party (the sender) that delivers data -on it's own, but in the case of files, there is no such thing: the disk -will not send data on it's own, simply because it doesn't know what you +on its own, but in the case of files, there is no such thing: the disk +will not send data on its own, simply because it doesn't know what you wish to read - you would first have to request some data. Since files are typically not-so-well supported by advanced notification @@ -2209,9 +2153,12 @@ C will try to run the callback in this mode at the next possible time where C