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

Comparing libev/ev.html (file contents):
Revision 1.38 by root, Sat Nov 24 07:20:43 2007 UTC vs.
Revision 1.39 by root, Sat Nov 24 09:48:38 2007 UTC

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="&lt;standard input&gt;" /> 7 <meta name="inputfile" content="&lt;standard input&gt;" />
8 <meta name="outputfile" content="&lt;standard output&gt;" /> 8 <meta name="outputfile" content="&lt;standard output&gt;" />
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)
880but on wallclock time (absolute time). You can tell a periodic watcher 880but on wallclock time (absolute time). You can tell a periodic watcher
881to trigger &quot;at&quot; some specific point in time. For example, if you tell a 881to trigger &quot;at&quot; some specific point in time. For example, if you tell a
882periodic watcher to trigger in 10 seconds (by specifiying e.g. c&lt;ev_now () 882periodic watcher to trigger in 10 seconds (by specifiying e.g. <code>ev_now ()
883+ 10.&gt;) 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
884take a year to trigger the event (unlike an <code>ev_timer</code>, which would trigger 884take a year to trigger the event (unlike an <code>ev_timer</code>, which would trigger
885roughly 10 seconds later and of course not if you reset your system time 885roughly 10 seconds later and of course not if you reset your system time
886again).</p> 886again).</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
888triggering an event on eahc midnight, local time.</p> 888triggering 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
1312you to use some convinience methods to start/stop watchers and also change
1313the callback model to a model using method callbacks on objects.</p>
1314<p>To use it,</p>
1315<pre> #include &lt;ev++.h&gt;
1316
1317</pre>
1318<p>(it is not installed by default). This automatically includes <cite>ev.h</cite>
1319and puts all of its definitions (many of them macros) into the global
1320namespace. 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.
1328macros 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
1337the same name in the <code>ev</code> namespace, with the exception of <code>ev_signal</code>
1338which is called <code>ev::sig</code> to avoid clashes with the <code>signal</code> macro
1339defines 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
1348the 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
1350before starting it. If you do not specify a loop then the constructor
1351automatically 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-&gt;set (struct ev_loop *)</dt>
1355 <dd>
1356 <p>Associates a different <code>struct ev_loop</code> with this watcher. You can only
1357do this when the watcher is inactive (and not pending either).</p>
1358 </dd>
1359 <dt>w-&gt;set ([args])</dt>
1360 <dd>
1361 <p>Basically the same as <code>ev_TYPE_set</code>, with the same args. Must be
1362called at least once. Unlike the C counterpart, an active watcher gets
1363automatically stopped and restarted.</p>
1364 </dd>
1365 <dt>w-&gt;start ()</dt>
1366 <dd>
1367 <p>Starts the watcher. Note that there is no <code>loop</code> argument as the
1368constructor already takes the loop.</p>
1369 </dd>
1370 <dt>w-&gt;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-&gt;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-&gt;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
1388the constructor.</p>
1389<pre> class myclass
1390 {
1391 ev_io io; void io_cb (ev::io &amp;w, int revents);
1392 ev_idle idle void idle_cb (ev::idle &amp;w, int revents);
1393
1394 myclass ();
1395 }
1396
1397 myclass::myclass (int fd)
1398 : io (this, &amp;myclass::io_cb),
1399 idle (this, &amp;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 &lt;libev@schmorp.de&gt;.</p> 1409<p>Marc Lehmann &lt;libev@schmorp.de&gt;.</p>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines