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

Comparing libev/ev.pod (file contents):
Revision 1.98 by root, Sat Dec 22 06:10:25 2007 UTC vs.
Revision 1.101 by ayin, Sat Dec 22 14:11:25 2007 UTC

339(or space) is available. 339(or space) is available.
340 340
341=item C<EVBACKEND_KQUEUE> (value 8, most BSD clones) 341=item C<EVBACKEND_KQUEUE> (value 8, most BSD clones)
342 342
343Kqueue deserves special mention, as at the time of this writing, it 343Kqueue deserves special mention, as at the time of this writing, it
344was broken on I<all> BSDs (usually it doesn't work with anything but 344was broken on all BSDs except NetBSD (usually it doesn't work reliably
345sockets and pipes, except on Darwin, where of course it's completely 345with anything but sockets and pipes, except on Darwin, where of course
346useless. On NetBSD, it seems to work for all the FD types I tested, so it
347is used by default there). For this reason it's not being "autodetected" 346it's completely useless). For this reason it's not being "autodetected"
348unless you explicitly specify it explicitly in the flags (i.e. using 347unless you explicitly specify it explicitly in the flags (i.e. using
349C<EVBACKEND_KQUEUE>) or libev was compiled on a known-to-be-good (-enough) 348C<EVBACKEND_KQUEUE>) or libev was compiled on a known-to-be-good (-enough)
350system like NetBSD. 349system like NetBSD.
351 350
351You still can embed kqueue into a normal poll or select backend and use it
352only for sockets (after having made sure that sockets work with kqueue on
353the target platform). See C<ev_embed> watchers for more info.
354
352It scales in the same way as the epoll backend, but the interface to the 355It scales in the same way as the epoll backend, but the interface to the
353kernel is more efficient (which says nothing about its actual speed, 356kernel is more efficient (which says nothing about its actual speed, of
354of course). While stopping, setting and starting an I/O watcher does 357course). While stopping, setting and starting an I/O watcher does never
355never cause an extra syscall as with epoll, it still adds up to two event 358cause an extra syscall as with C<EVBACKEND_EPOLL>, it still adds up to
356changes per incident, support for C<fork ()> is very bad and it drops fds 359two event changes per incident, support for C<fork ()> is very bad and it
357silently in similarly hard-to-detetc cases. 360drops fds silently in similarly hard-to-detect cases.
358 361
359=item C<EVBACKEND_DEVPOLL> (value 16, Solaris 8) 362=item C<EVBACKEND_DEVPOLL> (value 16, Solaris 8)
360 363
361This is not implemented yet (and might never be). 364This is not implemented yet (and might never be).
362 365
596overhead for the actual polling but can deliver many events at once. 599overhead for the actual polling but can deliver many events at once.
597 600
598By setting a higher I<io collect interval> you allow libev to spend more 601By setting a higher I<io collect interval> you allow libev to spend more
599time collecting I/O events, so you can handle more events per iteration, 602time collecting I/O events, so you can handle more events per iteration,
600at the cost of increasing latency. Timeouts (both C<ev_periodic> and 603at the cost of increasing latency. Timeouts (both C<ev_periodic> and
601C<ev_timer>) will be not affected. 604C<ev_timer>) will be not affected. Setting this to a non-null value will
605introduce an additional C<ev_sleep ()> call into most loop iterations.
602 606
603Likewise, by setting a higher I<timeout collect interval> you allow libev 607Likewise, by setting a higher I<timeout collect interval> you allow libev
604to spend more time collecting timeouts, at the expense of increased 608to spend more time collecting timeouts, at the expense of increased
605latency (the watcher callback will be called later). C<ev_io> watchers 609latency (the watcher callback will be called later). C<ev_io> watchers
606will not be affected. 610will not be affected. Setting this to a non-null value will not introduce
611any overhead in libev.
607 612
608Many (busy) programs can usually benefit by setting the io collect 613Many (busy) programs can usually benefit by setting the io collect
609interval to a value near C<0.1> or so, which is often enough for 614interval to a value near C<0.1> or so, which is often enough for
610interactive servers (of course not for games), likewise for timeouts. It 615interactive servers (of course not for games), likewise for timeouts. It
611usually doesn't make much sense to set it to a lower value than C<0.01>, 616usually doesn't make much sense to set it to a lower value than C<0.01>,
1621 1626
1622It is recommended to give C<ev_check> watchers highest (C<EV_MAXPRI>) 1627It is recommended to give C<ev_check> watchers highest (C<EV_MAXPRI>)
1623priority, to ensure that they are being run before any other watchers 1628priority, to ensure that they are being run before any other watchers
1624after the poll. Also, C<ev_check> watchers (and C<ev_prepare> watchers, 1629after the poll. Also, C<ev_check> watchers (and C<ev_prepare> watchers,
1625too) should not activate ("feed") events into libev. While libev fully 1630too) should not activate ("feed") events into libev. While libev fully
1626supports this, they will be called before other C<ev_check> watchers did 1631supports this, they will be called before other C<ev_check> watchers
1627their job. As C<ev_check> watchers are often used to embed other event 1632did their job. As C<ev_check> watchers are often used to embed other
1628loops those other event loops might be in an unusable state until their 1633(non-libev) event loops those other event loops might be in an unusable
1629C<ev_check> watcher ran (always remind yourself to coexist peacefully with 1634state until their C<ev_check> watcher ran (always remind yourself to
1630others). 1635coexist peacefully with others).
1631 1636
1632=head3 Watcher-Specific Functions and Data Members 1637=head3 Watcher-Specific Functions and Data Members
1633 1638
1634=over 4 1639=over 4
1635 1640
1774=head2 C<ev_embed> - when one backend isn't enough... 1779=head2 C<ev_embed> - when one backend isn't enough...
1775 1780
1776This is a rather advanced watcher type that lets you embed one event loop 1781This is a rather advanced watcher type that lets you embed one event loop
1777into another (currently only C<ev_io> events are supported in the embedded 1782into another (currently only C<ev_io> events are supported in the embedded
1778loop, other types of watchers might be handled in a delayed or incorrect 1783loop, other types of watchers might be handled in a delayed or incorrect
1779fashion and must not be used). (See portability notes, below). 1784fashion and must not be used).
1780 1785
1781There are primarily two reasons you would want that: work around bugs and 1786There are primarily two reasons you would want that: work around bugs and
1782prioritise I/O. 1787prioritise I/O.
1783 1788
1784As an example for a bug workaround, the kqueue backend might only support 1789As an example for a bug workaround, the kqueue backend might only support
1839 ev_embed_start (loop_hi, &embed); 1844 ev_embed_start (loop_hi, &embed);
1840 } 1845 }
1841 else 1846 else
1842 loop_lo = loop_hi; 1847 loop_lo = loop_hi;
1843 1848
1844=head2 Portability notes
1845
1846Kqueue is nominally embeddable, but this is broken on all BSDs that I
1847tried, in various ways. Usually the embedded event loop will simply never
1848receive events, sometimes it will only trigger a few times, sometimes in a
1849loop. Epoll is also nominally embeddable, but many Linux kernel versions
1850will always eport the epoll fd as ready, even when no events are pending.
1851
1852While libev allows embedding these backends (they are contained in
1853C<ev_embeddable_backends ()>), take extreme care that it will actually
1854work.
1855
1856When in doubt, create a dynamic event loop forced to use sockets (this
1857usually works) and possibly another thread and a pipe or so to report to
1858your main event loop.
1859
1860=head3 Watcher-Specific Functions and Data Members 1849=head3 Watcher-Specific Functions and Data Members
1861 1850
1862=over 4 1851=over 4
1863 1852
1864=item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop) 1853=item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines