From 73ce65a9122dd90fac253802fe20630572fdd4be Mon Sep 17 00:00:00 2001
From: root
Unlike ev_timer
's, they are not based on real time (or relative time)
but on wallclock time (absolute time). You can tell a periodic watcher
to trigger "at" some specific point in time. For example, if you tell a
-periodic watcher to trigger in 10 seconds (by specifiying e.g. c<ev_now ()
-+ 10.>) and then reset your system clock to the last year, then it will
+periodic watcher to trigger in 10 seconds (by specifiying e.g. ev_now ()
++ 10.
) and then reset your system clock to the last year, then it will
take a year to trigger the event (unlike an ev_timer
, which would trigger
roughly 10 seconds later and of course not if you reset your system time
again).
TBD.
+Libev comes with some simplistic wrapper classes for C++ that mainly allow +you to use some convinience methods to start/stop watchers and also change +the callback model to a model using method callbacks on objects.
+To use it,
+#include <ev++.h> + ++
(it is not installed by default). This automatically includes ev.h
+and puts all of its definitions (many of them macros) into the global
+namespace. All C++ specific things are put into the ev
namespace.
It should support all the same embedding options as ev.h, most notably
+EV_MULTIPLICITY
.
Here is a list of things available in the ev
namespace:
ev::READ
, ev::WRITE
etc.These are just enum values with the same values as the EV_READ
etc.
+macros from ev.h.
ev::tstamp
, ev::now
Aliases to the same types/functions as with the ev_
prefix.
ev::io
, ev::timer
, ev::periodic
, ev::idle
, ev::sig
etc.For each ev_TYPE
watcher in ev.h there is a corresponding class of
+the same name in the ev
namespace, with the exception of ev_signal
+which is called ev::sig
to avoid clashes with the signal
macro
+defines by many implementations.
All of those classes have these methods:
++
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
+ev_init
for you, which means you have to call the set
method
+before starting it. If you do not specify a loop then the constructor
+automatically associates the default loop with this watcher.
The destructor automatically stops the watcher if it is active.
+Associates a different struct ev_loop
with this watcher. You can only
+do this when the watcher is inactive (and not pending either).
Basically the same as ev_TYPE_set
, with the same args. Must be
+called at least once. Unlike the C counterpart, an active watcher gets
+automatically stopped and restarted.
Starts the watcher. Note that there is no loop
argument as the
+constructor already takes the loop.
Stops the watcher if it is active. Again, no loop
argument.
ev::timer
, ev::periodic
onlyFor ev::timer
and ev::periodic
, this invokes the corresponding
+ev_TYPE_again
function.
ev::embed
onlyInvokes ev_embed_sweep
.
Example: Define a class with an IO and idle watcher, start one of them in +the constructor.
+class myclass + { + ev_io io; void io_cb (ev::io &w, int revents); + ev_idle idle void idle_cb (ev::idle &w, int revents); + + myclass (); + } + + myclass::myclass (int fd) + : io (this, &myclass::io_cb), + idle (this, &myclass::idle_cb) + { + io.start (fd, ev::READ); + } + +