… | |
… | |
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="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 |
443 | in each iteration of the event loop (This behaviour is called |
443 | in each iteration of the event loop (This behaviour is called |
444 | level-triggering because you keep receiving events as long as the |
444 | level-triggering because you keep receiving events as long as the |
445 | condition persists. Remember you can stop the watcher if you don't want to |
445 | condition persists. Remember you can stop the watcher if you don't want to |
446 | act on the event and neither want to receive future events).</p> |
446 | act 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 |
448 | fd as you want (as long as you don't confuse yourself). Setting all file |
448 | fd as you want (as long as you don't confuse yourself). Setting all file |
449 | descriptors to non-blocking mode is also usually a good idea (but not |
449 | descriptors to non-blocking mode is also usually a good idea (but not |
450 | required if you know what you are doing).</p> |
450 | required 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 |
453 | descriptors correctly if you register interest in two or more fds pointing |
453 | descriptors correctly if you register interest in two or more fds pointing |
454 | to the same file/socket etc. description.</p> |
454 | to the same file/socket etc. description (that is, they share the same |
|
|
455 | underlying "file open").</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 |
457 | EVMETHOD_POLL).</p> |
458 | EVMETHOD_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 |
472 | given time, and optionally repeating in regular intervals after that.</p> |
473 | given 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 |
474 | times out after an hour and youreset your system clock to last years |
475 | times out after an hour and you reset your system clock to last years |
475 | time, it will still time out after (roughly) and hour. "Roughly" because |
476 | time, it will still time out after (roughly) and hour. "Roughly" because |
476 | detecting time jumps is hard, and soem inaccuracies are unavoidable (the |
477 | detecting time jumps is hard, and soem inaccuracies are unavoidable (the |
477 | monotonic clock option helps a lot here).</p> |
478 | monotonic 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> |
479 | time. This is usually the right thing as this timestamp refers to the time |
480 | time. This is usually the right thing as this timestamp refers to the time |
480 | of the event triggering whatever timeout you are modifying/starting. If |
481 | of the event triggering whatever timeout you are modifying/starting. If |
481 | you suspect event processing to be delayed and you *need* to base the timeout |
482 | you suspect event processing to be delayed and you *need* to base the timeout |
482 | ion the current time, use something like this to adjust for this:</p> |
483 | on the current time, use something like this to adjust for this:</p> |
483 | <pre> ev_timer_set (&timer, after + ev_now () - ev_time (), 0.); |
484 | <pre> ev_timer_set (&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> |
… | |
… | |
492 | timer will automatically be configured to trigger again <code>repeat</code> seconds |
493 | timer will automatically be configured to trigger again <code>repeat</code> seconds |
493 | later, again, and again, until stopped manually.</p> |
494 | later, 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 |
495 | configure a timer to trigger every 10 seconds, then it will trigger at |
496 | configure a timer to trigger every 10 seconds, then it will trigger at |
496 | exactly 10 second intervals. If, however, your program cannot keep up with |
497 | exactly 10 second intervals. If, however, your program cannot keep up with |
497 | the timer (ecause it takes longer than those 10 seconds to do stuff) the |
498 | the timer (because it takes longer than those 10 seconds to do stuff) the |
498 | timer will not fire more than once per event loop iteration.</p> |
499 | timer 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 |
720 | callback on whichever event happens first and automatically stop both |
721 | callback on whichever event happens first and automatically stop both |
721 | watchers. This is useful if you want to wait for a single event on an fd |
722 | watchers. This is useful if you want to wait for a single event on an fd |
722 | or timeout without havign to allocate/configure/start/stop/free one or |
723 | or timeout without having to allocate/configure/start/stop/free one or |
723 | more watchers yourself.</p> |
724 | more 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 |
725 | is being ignored. Otherwise, an <code>ev_io</code> watcher for the given <code>fd</code> and |
726 | is 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 |