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