… | |
… | |
4 | <head> |
4 | <head> |
5 | <title>libev</title> |
5 | <title>libev</title> |
6 | <meta name="description" content="Pod documentation for libev" /> |
6 | <meta name="description" content="Pod documentation for libev" /> |
7 | <meta name="inputfile" content="<standard input>" /> |
7 | <meta name="inputfile" content="<standard input>" /> |
8 | <meta name="outputfile" content="<standard output>" /> |
8 | <meta name="outputfile" content="<standard output>" /> |
9 | <meta name="created" content="Sat Nov 24 08:20:38 2007" /> |
9 | <meta name="created" content="Sat Nov 24 10:48:32 2007" /> |
10 | <meta name="generator" content="Pod::Xhtml 1.57" /> |
10 | <meta name="generator" content="Pod::Xhtml 1.57" /> |
11 | <link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head> |
11 | <link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head> |
12 | <body> |
12 | <body> |
13 | <div class="pod"> |
13 | <div class="pod"> |
14 | <!-- INDEX START --> |
14 | <!-- INDEX START --> |
… | |
… | |
877 | <p>Periodic watchers are also timers of a kind, but they are very versatile |
877 | <p>Periodic watchers are also timers of a kind, but they are very versatile |
878 | (and unfortunately a bit complex).</p> |
878 | (and unfortunately a bit complex).</p> |
879 | <p>Unlike <code>ev_timer</code>'s, they are not based on real time (or relative time) |
879 | <p>Unlike <code>ev_timer</code>'s, they are not based on real time (or relative time) |
880 | but on wallclock time (absolute time). You can tell a periodic watcher |
880 | but on wallclock time (absolute time). You can tell a periodic watcher |
881 | to trigger "at" some specific point in time. For example, if you tell a |
881 | to trigger "at" some specific point in time. For example, if you tell a |
882 | periodic watcher to trigger in 10 seconds (by specifiying e.g. c<ev_now () |
882 | periodic watcher to trigger in 10 seconds (by specifiying e.g. <code>ev_now () |
883 | + 10.>) and then reset your system clock to the last year, then it will |
883 | + 10.</code>) and then reset your system clock to the last year, then it will |
884 | take a year to trigger the event (unlike an <code>ev_timer</code>, which would trigger |
884 | take a year to trigger the event (unlike an <code>ev_timer</code>, which would trigger |
885 | roughly 10 seconds later and of course not if you reset your system time |
885 | roughly 10 seconds later and of course not if you reset your system time |
886 | again).</p> |
886 | again).</p> |
887 | <p>They can also be used to implement vastly more complex timers, such as |
887 | <p>They can also be used to implement vastly more complex timers, such as |
888 | triggering an event on eahc midnight, local time.</p> |
888 | triggering an event on eahc midnight, local time.</p> |
… | |
… | |
1306 | </dl> |
1306 | </dl> |
1307 | |
1307 | |
1308 | </div> |
1308 | </div> |
1309 | <h1 id="C_SUPPORT">C++ SUPPORT</h1><p><a href="#TOP" class="toplink">Top</a></p> |
1309 | <h1 id="C_SUPPORT">C++ SUPPORT</h1><p><a href="#TOP" class="toplink">Top</a></p> |
1310 | <div id="C_SUPPORT_CONTENT"> |
1310 | <div id="C_SUPPORT_CONTENT"> |
1311 | <p>TBD.</p> |
1311 | <p>Libev comes with some simplistic wrapper classes for C++ that mainly allow |
|
|
1312 | you to use some convinience methods to start/stop watchers and also change |
|
|
1313 | the callback model to a model using method callbacks on objects.</p> |
|
|
1314 | <p>To use it,</p> |
|
|
1315 | <pre> #include <ev++.h> |
|
|
1316 | |
|
|
1317 | </pre> |
|
|
1318 | <p>(it is not installed by default). This automatically includes <cite>ev.h</cite> |
|
|
1319 | and puts all of its definitions (many of them macros) into the global |
|
|
1320 | namespace. All C++ specific things are put into the <code>ev</code> namespace.</p> |
|
|
1321 | <p>It should support all the same embedding options as <cite>ev.h</cite>, most notably |
|
|
1322 | <code>EV_MULTIPLICITY</code>.</p> |
|
|
1323 | <p>Here is a list of things available in the <code>ev</code> namespace:</p> |
|
|
1324 | <dl> |
|
|
1325 | <dt><code>ev::READ</code>, <code>ev::WRITE</code> etc.</dt> |
|
|
1326 | <dd> |
|
|
1327 | <p>These are just enum values with the same values as the <code>EV_READ</code> etc. |
|
|
1328 | macros from <cite>ev.h</cite>.</p> |
|
|
1329 | </dd> |
|
|
1330 | <dt><code>ev::tstamp</code>, <code>ev::now</code></dt> |
|
|
1331 | <dd> |
|
|
1332 | <p>Aliases to the same types/functions as with the <code>ev_</code> prefix.</p> |
|
|
1333 | </dd> |
|
|
1334 | <dt><code>ev::io</code>, <code>ev::timer</code>, <code>ev::periodic</code>, <code>ev::idle</code>, <code>ev::sig</code> etc.</dt> |
|
|
1335 | <dd> |
|
|
1336 | <p>For each <code>ev_TYPE</code> watcher in <cite>ev.h</cite> there is a corresponding class of |
|
|
1337 | the same name in the <code>ev</code> namespace, with the exception of <code>ev_signal</code> |
|
|
1338 | which is called <code>ev::sig</code> to avoid clashes with the <code>signal</code> macro |
|
|
1339 | defines by many implementations.</p> |
|
|
1340 | <p>All of those classes have these methods:</p> |
|
|
1341 | <p> |
|
|
1342 | <dl> |
|
|
1343 | <dt>ev::TYPE::TYPE (object *, object::method *)</dt> |
|
|
1344 | <dt>ev::TYPE::TYPE (object *, object::method *, struct ev_loop *)</dt> |
|
|
1345 | <dt>ev::TYPE::~TYPE</dt> |
|
|
1346 | <dd> |
|
|
1347 | <p>The constructor takes a pointer to an object and a method pointer to |
|
|
1348 | the event handler callback to call in this class. The constructor calls |
|
|
1349 | <code>ev_init</code> for you, which means you have to call the <code>set</code> method |
|
|
1350 | before starting it. If you do not specify a loop then the constructor |
|
|
1351 | automatically associates the default loop with this watcher.</p> |
|
|
1352 | <p>The destructor automatically stops the watcher if it is active.</p> |
|
|
1353 | </dd> |
|
|
1354 | <dt>w->set (struct ev_loop *)</dt> |
|
|
1355 | <dd> |
|
|
1356 | <p>Associates a different <code>struct ev_loop</code> with this watcher. You can only |
|
|
1357 | do this when the watcher is inactive (and not pending either).</p> |
|
|
1358 | </dd> |
|
|
1359 | <dt>w->set ([args])</dt> |
|
|
1360 | <dd> |
|
|
1361 | <p>Basically the same as <code>ev_TYPE_set</code>, with the same args. Must be |
|
|
1362 | called at least once. Unlike the C counterpart, an active watcher gets |
|
|
1363 | automatically stopped and restarted.</p> |
|
|
1364 | </dd> |
|
|
1365 | <dt>w->start ()</dt> |
|
|
1366 | <dd> |
|
|
1367 | <p>Starts the watcher. Note that there is no <code>loop</code> argument as the |
|
|
1368 | constructor already takes the loop.</p> |
|
|
1369 | </dd> |
|
|
1370 | <dt>w->stop ()</dt> |
|
|
1371 | <dd> |
|
|
1372 | <p>Stops the watcher if it is active. Again, no <code>loop</code> argument.</p> |
|
|
1373 | </dd> |
|
|
1374 | <dt>w->again () <code>ev::timer</code>, <code>ev::periodic</code> only</dt> |
|
|
1375 | <dd> |
|
|
1376 | <p>For <code>ev::timer</code> and <code>ev::periodic</code>, this invokes the corresponding |
|
|
1377 | <code>ev_TYPE_again</code> function.</p> |
|
|
1378 | </dd> |
|
|
1379 | <dt>w->sweep () <code>ev::embed</code> only</dt> |
|
|
1380 | <dd> |
|
|
1381 | <p>Invokes <code>ev_embed_sweep</code>.</p> |
|
|
1382 | </dd> |
|
|
1383 | </dl> |
|
|
1384 | </p> |
|
|
1385 | </dd> |
|
|
1386 | </dl> |
|
|
1387 | <p>Example: Define a class with an IO and idle watcher, start one of them in |
|
|
1388 | the constructor.</p> |
|
|
1389 | <pre> class myclass |
|
|
1390 | { |
|
|
1391 | ev_io io; void io_cb (ev::io &w, int revents); |
|
|
1392 | ev_idle idle void idle_cb (ev::idle &w, int revents); |
|
|
1393 | |
|
|
1394 | myclass (); |
|
|
1395 | } |
|
|
1396 | |
|
|
1397 | myclass::myclass (int fd) |
|
|
1398 | : io (this, &myclass::io_cb), |
|
|
1399 | idle (this, &myclass::idle_cb) |
|
|
1400 | { |
|
|
1401 | io.start (fd, ev::READ); |
|
|
1402 | } |
|
|
1403 | |
|
|
1404 | </pre> |
1312 | |
1405 | |
1313 | </div> |
1406 | </div> |
1314 | <h1 id="AUTHOR">AUTHOR</h1><p><a href="#TOP" class="toplink">Top</a></p> |
1407 | <h1 id="AUTHOR">AUTHOR</h1><p><a href="#TOP" class="toplink">Top</a></p> |
1315 | <div id="AUTHOR_CONTENT"> |
1408 | <div id="AUTHOR_CONTENT"> |
1316 | <p>Marc Lehmann <libev@schmorp.de>.</p> |
1409 | <p>Marc Lehmann <libev@schmorp.de>.</p> |