--- libev/ev.pod 2007/12/07 19:15:39 1.69 +++ libev/ev.pod 2007/12/08 14:12:08 1.74 @@ -738,8 +738,9 @@ Returns a true value iff the watcher is pending, (i.e. it has outstanding events but its callback has not yet been invoked). As long as a watcher is pending (but not active) you must not call an init function on it (but -C is safe) and you must make sure the watcher is available to -libev (e.g. you cnanot C it). +C is safe), you must not change its priority, and you must +make sure the watcher is available to libev (e.g. you cannot C +it). =item callback ev_cb (ev_TYPE *watcher) @@ -768,6 +769,9 @@ If you need to suppress invocation when higher priority events are pending you need to look at C watchers, which provide this functionality. +You I change the priority of a watcher as long as it is active or +pending. + The default priority used by watchers when no priority has been set is always C<0>, which is supposed to not be too high and not be too low :). @@ -775,6 +779,18 @@ fine, as long as you do not mind that the priority value you query might or might not have been adjusted to be within valid range. +=item ev_invoke (loop, ev_TYPE *watcher, int revents) + +Invoke the C with the given C and C. Neither +C nor C need to be valid as long as the watcher callback +can deal with that fact. + +=item int ev_clear_pending (loop, ev_TYPE *watcher) + +If the watcher is pending, this function returns clears its pending status +and returns its C bitset (as if its callback was invoked). If the +watcher isn't pending it does nothing and returns C<0>. + =back @@ -1746,12 +1762,21 @@ #include -(it is not installed by default). This automatically includes F -and puts all of its definitions (many of them macros) into the global -namespace. All C++ specific things are put into the C namespace. - -It should support all the same embedding options as F, most notably -C. +This automatically includes F and puts all of its definitions (many +of them macros) into the global namespace. All C++ specific things are +put into the C namespace. It should support all the same embedding +options as F, most notably C. + +Care has been taken to keep the overhead low. The only data member the C++ +classes add (compared to plain C-style watchers) is the event loop pointer +that the watcher is associated with (or no additional members at all if +you disable C when embedding libev). + +Currently, functions, and static and non-static member functions can be +used as callbacks. Other types should be easy to add as long as they only +need one additional pointer for context. If you need support for other +types of functors please contact the author (preferably after implementing +it). Here is a list of things available in the C namespace: @@ -1777,20 +1802,58 @@ =over 4 -=item ev::TYPE::TYPE (object *, object::method *) +=item ev::TYPE::TYPE () -=item ev::TYPE::TYPE (object *, object::method *, struct ev_loop *) +=item ev::TYPE::TYPE (struct ev_loop *) =item ev::TYPE::~TYPE -The constructor takes a pointer to an object and a method pointer to -the event handler callback to call in this class. The constructor calls -C for you, which means you have to call the C method -before starting it. If you do not specify a loop then the constructor -automatically associates the default loop with this watcher. +The constructor (optionally) takes an event loop to associate the watcher +with. If it is omitted, it will use C. + +The constructor calls C for you, which means you have to call the +C method before starting it. + +It will not set a callback, however: You have to call the templated C +method to set a callback before you can start the watcher. + +(The reason why you have to use a method is a limitation in C++ which does +not allow explicit template arguments for constructors). The destructor automatically stops the watcher if it is active. +=item w->set (object *) + +This method sets the callback method to call. The method has to have a +signature of C, it receives the watcher as +first argument and the C as second. The object must be given as +parameter and is stored in the C member of the watcher. + +This method synthesizes efficient thunking code to call your method from +the C callback that libev requires. If your compiler can inline your +callback (i.e. it is visible to it at the place of the C call and +your compiler is good :), then the method will be fully inlined into the +thunking function, making it as fast as a direct C callback. + +Example: simple class declaration and watcher initialisation + + struct myclass + { + void io_cb (ev::io &w, int revents) { } + } + + myclass obj; + ev::io iow; + iow.set (&obj); + +=item w->set (void (*function)(watcher &w, int), void *data = 0) + +Also sets a callback, but uses a static method or plain function as +callback. The optional C argument will be stored in the watcher's +C member and is free for you to use. + +See the method-C above for more details. + =item w->set (struct ev_loop *) Associates a different C with this watcher. You can only @@ -1799,13 +1862,14 @@ =item w->set ([args]) Basically the same as C, with the same args. Must be -called at least once. Unlike the C counterpart, an active watcher gets -automatically stopped and restarted. +called at least once. Unlike the C counterpart, an active watcher gets +automatically stopped and restarted when reconfiguring it with this +method. =item w->start () -Starts the watcher. Note that there is no C argument as the -constructor already takes the loop. +Starts the watcher. Note that there is no C argument, as the +constructor already stores the event loop. =item w->stop () @@ -1840,9 +1904,10 @@ } myclass::myclass (int fd) - : io (this, &myclass::io_cb), - idle (this, &myclass::idle_cb) { + io .set (this); + idle.set (this); + io.start (fd, ev::READ); } @@ -2257,6 +2322,12 @@ libev will be explained. For complexity discussions about backends see the documentation for C. +All of the following are about amortised time: If an array needs to be +extended, libev needs to realloc and move the whole array, but this +happens asymptotically never with higher number of elements, so O(1) might +mean it might do a lengthy realloc operation in rare cases, but on average +it is much faster and asymptotically approaches constant time. + =over 4 =item Starting and stopping timer/periodic watchers: O(log skipped_other_timers) @@ -2272,11 +2343,7 @@ =item Starting io/check/prepare/idle/signal/child watchers: O(1) -These just add the watcher into an array or at the head of a list. If -the array needs to be extended libev needs to realloc and move the whole -array, but this happen asymptotically less and less with more watchers, -thus amortised O(1). - +These just add the watcher into an array or at the head of a list. =item Stopping check/prepare/idle watchers: O(1) =item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))