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

Comparing libev/ev.html (file contents):
Revision 1.24 by root, Mon Nov 12 09:07:10 2007 UTC vs.
Revision 1.25 by root, Mon Nov 12 18:49:17 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="Mon Nov 12 10:07:10 2007" /> 9 <meta name="created" content="Mon Nov 12 19:49:15 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 -->
442<p>I/O watchers check whether a file descriptor is readable or writable 442<p>I/O watchers check whether a file descriptor is readable or writable
443in each iteration of the event loop (This behaviour is called 443in each iteration of the event loop (This behaviour is called
444level-triggering because you keep receiving events as long as the 444level-triggering because you keep receiving events as long as the
445condition persists. Remember you can stop the watcher if you don't want to 445condition persists. Remember you can stop the watcher if you don't want to
446act on the event and neither want to receive future events).</p> 446act on the event and neither want to receive future events).</p>
447<p>In general you can register as many read and/or write event watchers oer 447<p>In general you can register as many read and/or write event watchers per
448fd as you want (as long as you don't confuse yourself). Setting all file 448fd as you want (as long as you don't confuse yourself). Setting all file
449descriptors to non-blocking mode is also usually a good idea (but not 449descriptors to non-blocking mode is also usually a good idea (but not
450required if you know what you are doing).</p> 450required if you know what you are doing).</p>
451<p>You have to be careful with dup'ed file descriptors, though. Some backends 451<p>You have to be careful with dup'ed file descriptors, though. Some backends
452(the linux epoll backend is a notable example) cannot handle dup'ed file 452(the linux epoll backend is a notable example) cannot handle dup'ed file
453descriptors correctly if you register interest in two or more fds pointing 453descriptors correctly if you register interest in two or more fds pointing
454to the same file/socket etc. description.</p> 454to the same file/socket etc. description (that is, they share the same
455underlying &quot;file open&quot;).</p>
455<p>If you must do this, then force the use of a known-to-be-good backend 456<p>If you must do this, then force the use of a known-to-be-good backend
456(at the time of this writing, this includes only EVMETHOD_SELECT and 457(at the time of this writing, this includes only EVMETHOD_SELECT and
457EVMETHOD_POLL).</p> 458EVMETHOD_POLL).</p>
458<dl> 459<dl>
459 <dt>ev_io_init (ev_io *, callback, int fd, int events)</dt> 460 <dt>ev_io_init (ev_io *, callback, int fd, int events)</dt>
469<h2 id="code_ev_timer_code_relative_and_opti"><code>ev_timer</code> - relative and optionally recurring timeouts</h2> 470<h2 id="code_ev_timer_code_relative_and_opti"><code>ev_timer</code> - relative and optionally recurring timeouts</h2>
470<div id="code_ev_timer_code_relative_and_opti-2"> 471<div id="code_ev_timer_code_relative_and_opti-2">
471<p>Timer watchers are simple relative timers that generate an event after a 472<p>Timer watchers are simple relative timers that generate an event after a
472given time, and optionally repeating in regular intervals after that.</p> 473given time, and optionally repeating in regular intervals after that.</p>
473<p>The timers are based on real time, that is, if you register an event that 474<p>The timers are based on real time, that is, if you register an event that
474times out after an hour and youreset your system clock to last years 475times out after an hour and you reset your system clock to last years
475time, it will still time out after (roughly) and hour. &quot;Roughly&quot; because 476time, it will still time out after (roughly) and hour. &quot;Roughly&quot; because
476detecting time jumps is hard, and soem inaccuracies are unavoidable (the 477detecting time jumps is hard, and soem inaccuracies are unavoidable (the
477monotonic clock option helps a lot here).</p> 478monotonic clock option helps a lot here).</p>
478<p>The relative timeouts are calculated relative to the <code>ev_now ()</code> 479<p>The relative timeouts are calculated relative to the <code>ev_now ()</code>
479time. This is usually the right thing as this timestamp refers to the time 480time. This is usually the right thing as this timestamp refers to the time
480of the event triggering whatever timeout you are modifying/starting. If 481of the event triggering whatever timeout you are modifying/starting. If
481you suspect event processing to be delayed and you *need* to base the timeout 482you suspect event processing to be delayed and you *need* to base the timeout
482ion the current time, use something like this to adjust for this:</p> 483on the current time, use something like this to adjust for this:</p>
483<pre> ev_timer_set (&amp;timer, after + ev_now () - ev_time (), 0.); 484<pre> ev_timer_set (&amp;timer, after + ev_now () - ev_time (), 0.);
484 485
485</pre> 486</pre>
486<dl> 487<dl>
487 <dt>ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)</dt> 488 <dt>ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)</dt>
492timer will automatically be configured to trigger again <code>repeat</code> seconds 493timer will automatically be configured to trigger again <code>repeat</code> seconds
493later, again, and again, until stopped manually.</p> 494later, again, and again, until stopped manually.</p>
494 <p>The timer itself will do a best-effort at avoiding drift, that is, if you 495 <p>The timer itself will do a best-effort at avoiding drift, that is, if you
495configure a timer to trigger every 10 seconds, then it will trigger at 496configure a timer to trigger every 10 seconds, then it will trigger at
496exactly 10 second intervals. If, however, your program cannot keep up with 497exactly 10 second intervals. If, however, your program cannot keep up with
497the timer (ecause it takes longer than those 10 seconds to do stuff) the 498the timer (because it takes longer than those 10 seconds to do stuff) the
498timer will not fire more than once per event loop iteration.</p> 499timer will not fire more than once per event loop iteration.</p>
499 </dd> 500 </dd>
500 <dt>ev_timer_again (loop)</dt> 501 <dt>ev_timer_again (loop)</dt>
501 <dd> 502 <dd>
502 <p>This will act as if the timer timed out and restart it again if it is 503 <p>This will act as if the timer timed out and restart it again if it is
717 <dt>ev_once (loop, int fd, int events, ev_tstamp timeout, callback)</dt> 718 <dt>ev_once (loop, int fd, int events, ev_tstamp timeout, callback)</dt>
718 <dd> 719 <dd>
719 <p>This function combines a simple timer and an I/O watcher, calls your 720 <p>This function combines a simple timer and an I/O watcher, calls your
720callback on whichever event happens first and automatically stop both 721callback on whichever event happens first and automatically stop both
721watchers. This is useful if you want to wait for a single event on an fd 722watchers. This is useful if you want to wait for a single event on an fd
722or timeout without havign to allocate/configure/start/stop/free one or 723or timeout without having to allocate/configure/start/stop/free one or
723more watchers yourself.</p> 724more watchers yourself.</p>
724 <p>If <code>fd</code> is less than 0, then no I/O watcher will be started and events 725 <p>If <code>fd</code> is less than 0, then no I/O watcher will be started and events
725is being ignored. Otherwise, an <code>ev_io</code> watcher for the given <code>fd</code> and 726is being ignored. Otherwise, an <code>ev_io</code> watcher for the given <code>fd</code> and
726<code>events</code> set will be craeted and started.</p> 727<code>events</code> set will be craeted and started.</p>
727 <p>If <code>timeout</code> is less than 0, then no timeout watcher will be 728 <p>If <code>timeout</code> is less than 0, then no timeout watcher will be

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines