1 | .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) |
1 | .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) |
2 | .\" |
2 | .\" |
3 | .\" Standard preamble: |
3 | .\" Standard preamble: |
4 | .\" ======================================================================== |
4 | .\" ======================================================================== |
5 | .de Sp \" Vertical space (when we can't use .PP) |
5 | .de Sp \" Vertical space (when we can't use .PP) |
6 | .if t .sp .5v |
6 | .if t .sp .5v |
… | |
… | |
44 | .\" |
44 | .\" |
45 | .\" Escape single quotes in literal strings from groff's Unicode transform. |
45 | .\" Escape single quotes in literal strings from groff's Unicode transform. |
46 | .ie \n(.g .ds Aq \(aq |
46 | .ie \n(.g .ds Aq \(aq |
47 | .el .ds Aq ' |
47 | .el .ds Aq ' |
48 | .\" |
48 | .\" |
49 | .\" If the F register is turned on, we'll generate index entries on stderr for |
49 | .\" If the F register is >0, we'll generate index entries on stderr for |
50 | .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
50 | .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
51 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
51 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
52 | .\" output yourself in some meaningful fashion. |
52 | .\" output yourself in some meaningful fashion. |
53 | .\" |
53 | .\" |
54 | .\" Avoid warning from groff about undefined register 'F'. |
54 | .\" Avoid warning from groff about undefined register 'F'. |
55 | .de IX |
55 | .de IX |
56 | .. |
56 | .. |
57 | .nr rF 0 |
57 | .nr rF 0 |
58 | .if \n(.g .if rF .nr rF 1 |
58 | .if \n(.g .if rF .nr rF 1 |
59 | .if (\n(rF:(\n(.g==0)) \{ |
59 | .if (\n(rF:(\n(.g==0)) \{\ |
60 | . if \nF \{ |
60 | . if \nF \{\ |
61 | . de IX |
61 | . de IX |
62 | . tm Index:\\$1\t\\n%\t"\\$2" |
62 | . tm Index:\\$1\t\\n%\t"\\$2" |
63 | .. |
63 | .. |
64 | . if !\nF==2 \{ |
64 | . if !\nF==2 \{\ |
65 | . nr % 0 |
65 | . nr % 0 |
66 | . nr F 2 |
66 | . nr F 2 |
67 | . \} |
67 | . \} |
68 | . \} |
68 | . \} |
69 | .\} |
69 | .\} |
… | |
… | |
131 | .\} |
131 | .\} |
132 | .rm #[ #] #H #V #F C |
132 | .rm #[ #] #H #V #F C |
133 | .\" ======================================================================== |
133 | .\" ======================================================================== |
134 | .\" |
134 | .\" |
135 | .IX Title "LIBEV 3" |
135 | .IX Title "LIBEV 3" |
136 | .TH LIBEV 3 "2018-12-21" "libev-4.25" "libev - high performance full featured event loop" |
136 | .TH LIBEV 3 "2023-05-15" "libev-4.33" "libev - high performance full featured event loop" |
137 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
137 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
138 | .\" way too many mistakes in technical documents. |
138 | .\" way too many mistakes in technical documents. |
139 | .if n .ad l |
139 | .if n .ad l |
140 | .nh |
140 | .nh |
141 | .SH "NAME" |
141 | .SH "NAME" |
… | |
… | |
240 | watchers\fR, which are relatively small C structures you initialise with the |
240 | watchers\fR, which are relatively small C structures you initialise with the |
241 | details of the event, and then hand it over to libev by \fIstarting\fR the |
241 | details of the event, and then hand it over to libev by \fIstarting\fR the |
242 | watcher. |
242 | watcher. |
243 | .SS "\s-1FEATURES\s0" |
243 | .SS "\s-1FEATURES\s0" |
244 | .IX Subsection "FEATURES" |
244 | .IX Subsection "FEATURES" |
245 | Libev supports \f(CW\*(C`select\*(C'\fR, \f(CW\*(C`poll\*(C'\fR, the Linux-specific \f(CW\*(C`epoll\*(C'\fR, the |
245 | Libev supports \f(CW\*(C`select\*(C'\fR, \f(CW\*(C`poll\*(C'\fR, the Linux-specific aio and \f(CW\*(C`epoll\*(C'\fR |
246 | BSD-specific \f(CW\*(C`kqueue\*(C'\fR and the Solaris-specific event port mechanisms |
246 | interfaces, the BSD-specific \f(CW\*(C`kqueue\*(C'\fR and the Solaris-specific event port |
247 | for file descriptor events (\f(CW\*(C`ev_io\*(C'\fR), the Linux \f(CW\*(C`inotify\*(C'\fR interface |
247 | mechanisms for file descriptor events (\f(CW\*(C`ev_io\*(C'\fR), the Linux \f(CW\*(C`inotify\*(C'\fR |
248 | (for \f(CW\*(C`ev_stat\*(C'\fR), Linux eventfd/signalfd (for faster and cleaner |
248 | interface (for \f(CW\*(C`ev_stat\*(C'\fR), Linux eventfd/signalfd (for faster and cleaner |
249 | inter-thread wakeup (\f(CW\*(C`ev_async\*(C'\fR)/signal handling (\f(CW\*(C`ev_signal\*(C'\fR)) relative |
249 | inter-thread wakeup (\f(CW\*(C`ev_async\*(C'\fR)/signal handling (\f(CW\*(C`ev_signal\*(C'\fR)) relative |
250 | timers (\f(CW\*(C`ev_timer\*(C'\fR), absolute timers with customised rescheduling |
250 | timers (\f(CW\*(C`ev_timer\*(C'\fR), absolute timers with customised rescheduling |
251 | (\f(CW\*(C`ev_periodic\*(C'\fR), synchronous signals (\f(CW\*(C`ev_signal\*(C'\fR), process status |
251 | (\f(CW\*(C`ev_periodic\*(C'\fR), synchronous signals (\f(CW\*(C`ev_signal\*(C'\fR), process status |
252 | change events (\f(CW\*(C`ev_child\*(C'\fR), and event watchers dealing with the event |
252 | change events (\f(CW\*(C`ev_child\*(C'\fR), and event watchers dealing with the event |
253 | loop mechanism itself (\f(CW\*(C`ev_idle\*(C'\fR, \f(CW\*(C`ev_embed\*(C'\fR, \f(CW\*(C`ev_prepare\*(C'\fR and |
253 | loop mechanism itself (\f(CW\*(C`ev_idle\*(C'\fR, \f(CW\*(C`ev_embed\*(C'\fR, \f(CW\*(C`ev_prepare\*(C'\fR and |
… | |
… | |
291 | When libev detects a usage error such as a negative timer interval, then |
291 | When libev detects a usage error such as a negative timer interval, then |
292 | it will print a diagnostic message and abort (via the \f(CW\*(C`assert\*(C'\fR mechanism, |
292 | it will print a diagnostic message and abort (via the \f(CW\*(C`assert\*(C'\fR mechanism, |
293 | so \f(CW\*(C`NDEBUG\*(C'\fR will disable this checking): these are programming errors in |
293 | so \f(CW\*(C`NDEBUG\*(C'\fR will disable this checking): these are programming errors in |
294 | the libev caller and need to be fixed there. |
294 | the libev caller and need to be fixed there. |
295 | .PP |
295 | .PP |
|
|
296 | Via the \f(CW\*(C`EV_FREQUENT\*(C'\fR macro you can compile in and/or enable extensive |
|
|
297 | consistency checking code inside libev that can be used to check for |
|
|
298 | internal inconsistencies, suually caused by application bugs. |
|
|
299 | .PP |
296 | Libev also has a few internal error-checking \f(CW\*(C`assert\*(C'\fRions, and also has |
300 | Libev also has a few internal error-checking \f(CW\*(C`assert\*(C'\fRions. These do not |
297 | extensive consistency checking code. These do not trigger under normal |
|
|
298 | circumstances, as they indicate either a bug in libev or worse. |
301 | trigger under normal circumstances, as they indicate either a bug in libev |
|
|
302 | or worse. |
299 | .SH "GLOBAL FUNCTIONS" |
303 | .SH "GLOBAL FUNCTIONS" |
300 | .IX Header "GLOBAL FUNCTIONS" |
304 | .IX Header "GLOBAL FUNCTIONS" |
301 | These functions can be called anytime, even before initialising the |
305 | These functions can be called anytime, even before initialising the |
302 | library in any way. |
306 | library in any way. |
303 | .IP "ev_tstamp ev_time ()" 4 |
307 | .IP "ev_tstamp ev_time ()" 4 |
… | |
… | |
392 | .Sp |
396 | .Sp |
393 | You could override this function in high-availability programs to, say, |
397 | You could override this function in high-availability programs to, say, |
394 | free some memory if it cannot allocate memory, to use a special allocator, |
398 | free some memory if it cannot allocate memory, to use a special allocator, |
395 | or even to sleep a while and retry until some memory is available. |
399 | or even to sleep a while and retry until some memory is available. |
396 | .Sp |
400 | .Sp |
|
|
401 | Example: The following is the \f(CW\*(C`realloc\*(C'\fR function that libev itself uses |
|
|
402 | which should work with \f(CW\*(C`realloc\*(C'\fR and \f(CW\*(C`free\*(C'\fR functions of all kinds and |
|
|
403 | is probably a good basis for your own implementation. |
|
|
404 | .Sp |
|
|
405 | .Vb 5 |
|
|
406 | \& static void * |
|
|
407 | \& ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
|
|
408 | \& { |
|
|
409 | \& if (size) |
|
|
410 | \& return realloc (ptr, size); |
|
|
411 | \& |
|
|
412 | \& free (ptr); |
|
|
413 | \& return 0; |
|
|
414 | \& } |
|
|
415 | .Ve |
|
|
416 | .Sp |
397 | Example: Replace the libev allocator with one that waits a bit and then |
417 | Example: Replace the libev allocator with one that waits a bit and then |
398 | retries (example requires a standards-compliant \f(CW\*(C`realloc\*(C'\fR). |
418 | retries. |
399 | .Sp |
419 | .Sp |
400 | .Vb 6 |
420 | .Vb 8 |
401 | \& static void * |
421 | \& static void * |
402 | \& persistent_realloc (void *ptr, size_t size) |
422 | \& persistent_realloc (void *ptr, size_t size) |
403 | \& { |
423 | \& { |
|
|
424 | \& if (!size) |
|
|
425 | \& { |
|
|
426 | \& free (ptr); |
|
|
427 | \& return 0; |
|
|
428 | \& } |
|
|
429 | \& |
404 | \& for (;;) |
430 | \& for (;;) |
405 | \& { |
431 | \& { |
406 | \& void *newptr = realloc (ptr, size); |
432 | \& void *newptr = realloc (ptr, size); |
407 | \& |
433 | \& |
408 | \& if (newptr) |
434 | \& if (newptr) |
… | |
… | |
580 | want to handle signals only in specific threads and want to avoid libev |
606 | want to handle signals only in specific threads and want to avoid libev |
581 | unblocking the signals. |
607 | unblocking the signals. |
582 | .Sp |
608 | .Sp |
583 | It's also required by \s-1POSIX\s0 in a threaded program, as libev calls |
609 | It's also required by \s-1POSIX\s0 in a threaded program, as libev calls |
584 | \&\f(CW\*(C`sigprocmask\*(C'\fR, whose behaviour is officially unspecified. |
610 | \&\f(CW\*(C`sigprocmask\*(C'\fR, whose behaviour is officially unspecified. |
|
|
611 | .ie n .IP """EVFLAG_NOTIMERFD""" 4 |
|
|
612 | .el .IP "\f(CWEVFLAG_NOTIMERFD\fR" 4 |
|
|
613 | .IX Item "EVFLAG_NOTIMERFD" |
|
|
614 | When this flag is specified, the libev will avoid using a \f(CW\*(C`timerfd\*(C'\fR to |
|
|
615 | detect time jumps. It will still be able to detect time jumps, but takes |
|
|
616 | longer and has a lower accuracy in doing so, but saves a file descriptor |
|
|
617 | per loop. |
585 | .Sp |
618 | .Sp |
586 | This flag's behaviour will become the default in future versions of libev. |
619 | The current implementation only tries to use a \f(CW\*(C`timerfd\*(C'\fR when the first |
|
|
620 | \&\f(CW\*(C`ev_periodic\*(C'\fR watcher is started and falls back on other methods if it |
|
|
621 | cannot be created, but this behaviour might change in the future. |
587 | .ie n .IP """EVBACKEND_SELECT"" (value 1, portable select backend)" 4 |
622 | .ie n .IP """EVBACKEND_SELECT"" (value 1, portable select backend)" 4 |
588 | .el .IP "\f(CWEVBACKEND_SELECT\fR (value 1, portable select backend)" 4 |
623 | .el .IP "\f(CWEVBACKEND_SELECT\fR (value 1, portable select backend)" 4 |
589 | .IX Item "EVBACKEND_SELECT (value 1, portable select backend)" |
624 | .IX Item "EVBACKEND_SELECT (value 1, portable select backend)" |
590 | This is your standard \fIselect\fR\|(2) backend. Not \fIcompletely\fR standard, as |
625 | This is your standard \fBselect\fR\|(2) backend. Not \fIcompletely\fR standard, as |
591 | libev tries to roll its own fd_set with no limits on the number of fds, |
626 | libev tries to roll its own fd_set with no limits on the number of fds, |
592 | but if that fails, expect a fairly low limit on the number of fds when |
627 | but if that fails, expect a fairly low limit on the number of fds when |
593 | using this backend. It doesn't scale too well (O(highest_fd)), but its |
628 | using this backend. It doesn't scale too well (O(highest_fd)), but its |
594 | usually the fastest backend for a low number of (low-numbered :) fds. |
629 | usually the fastest backend for a low number of (low-numbered :) fds. |
595 | .Sp |
630 | .Sp |
… | |
… | |
604 | \&\f(CW\*(C`writefds\*(C'\fR set (and to work around Microsoft Windows bugs, also onto the |
639 | \&\f(CW\*(C`writefds\*(C'\fR set (and to work around Microsoft Windows bugs, also onto the |
605 | \&\f(CW\*(C`exceptfds\*(C'\fR set on that platform). |
640 | \&\f(CW\*(C`exceptfds\*(C'\fR set on that platform). |
606 | .ie n .IP """EVBACKEND_POLL"" (value 2, poll backend, available everywhere except on windows)" 4 |
641 | .ie n .IP """EVBACKEND_POLL"" (value 2, poll backend, available everywhere except on windows)" 4 |
607 | .el .IP "\f(CWEVBACKEND_POLL\fR (value 2, poll backend, available everywhere except on windows)" 4 |
642 | .el .IP "\f(CWEVBACKEND_POLL\fR (value 2, poll backend, available everywhere except on windows)" 4 |
608 | .IX Item "EVBACKEND_POLL (value 2, poll backend, available everywhere except on windows)" |
643 | .IX Item "EVBACKEND_POLL (value 2, poll backend, available everywhere except on windows)" |
609 | And this is your standard \fIpoll\fR\|(2) backend. It's more complicated |
644 | And this is your standard \fBpoll\fR\|(2) backend. It's more complicated |
610 | than select, but handles sparse fds better and has no artificial |
645 | than select, but handles sparse fds better and has no artificial |
611 | limit on the number of fds you can use (except it will slow down |
646 | limit on the number of fds you can use (except it will slow down |
612 | considerably with a lot of inactive fds). It scales similarly to select, |
647 | considerably with a lot of inactive fds). It scales similarly to select, |
613 | i.e. O(total_fds). See the entry for \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR, above, for |
648 | i.e. O(total_fds). See the entry for \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR, above, for |
614 | performance tips. |
649 | performance tips. |
… | |
… | |
616 | This backend maps \f(CW\*(C`EV_READ\*(C'\fR to \f(CW\*(C`POLLIN | POLLERR | POLLHUP\*(C'\fR, and |
651 | This backend maps \f(CW\*(C`EV_READ\*(C'\fR to \f(CW\*(C`POLLIN | POLLERR | POLLHUP\*(C'\fR, and |
617 | \&\f(CW\*(C`EV_WRITE\*(C'\fR to \f(CW\*(C`POLLOUT | POLLERR | POLLHUP\*(C'\fR. |
652 | \&\f(CW\*(C`EV_WRITE\*(C'\fR to \f(CW\*(C`POLLOUT | POLLERR | POLLHUP\*(C'\fR. |
618 | .ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4 |
653 | .ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4 |
619 | .el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4 |
654 | .el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4 |
620 | .IX Item "EVBACKEND_EPOLL (value 4, Linux)" |
655 | .IX Item "EVBACKEND_EPOLL (value 4, Linux)" |
621 | Use the linux-specific \fIepoll\fR\|(7) interface (for both pre\- and post\-2.6.9 |
656 | Use the Linux-specific \fBepoll\fR\|(7) interface (for both pre\- and post\-2.6.9 |
622 | kernels). |
657 | kernels). |
623 | .Sp |
658 | .Sp |
624 | For few fds, this backend is a bit little slower than poll and select, but |
659 | For few fds, this backend is a bit little slower than poll and select, but |
625 | it scales phenomenally better. While poll and select usually scale like |
660 | it scales phenomenally better. While poll and select usually scale like |
626 | O(total_fds) where total_fds is the total number of fds (or the highest |
661 | O(total_fds) where total_fds is the total number of fds (or the highest |
… | |
… | |
672 | All this means that, in practice, \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR can be as fast or |
707 | All this means that, in practice, \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR can be as fast or |
673 | faster than epoll for maybe up to a hundred file descriptors, depending on |
708 | faster than epoll for maybe up to a hundred file descriptors, depending on |
674 | the usage. So sad. |
709 | the usage. So sad. |
675 | .Sp |
710 | .Sp |
676 | While nominally embeddable in other event loops, this feature is broken in |
711 | While nominally embeddable in other event loops, this feature is broken in |
677 | all kernel versions tested so far. |
712 | a lot of kernel revisions, but probably(!) works in current versions. |
|
|
713 | .Sp |
|
|
714 | This backend maps \f(CW\*(C`EV_READ\*(C'\fR and \f(CW\*(C`EV_WRITE\*(C'\fR in the same way as |
|
|
715 | \&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
|
|
716 | .ie n .IP """EVBACKEND_LINUXAIO"" (value 64, Linux)" 4 |
|
|
717 | .el .IP "\f(CWEVBACKEND_LINUXAIO\fR (value 64, Linux)" 4 |
|
|
718 | .IX Item "EVBACKEND_LINUXAIO (value 64, Linux)" |
|
|
719 | Use the Linux-specific Linux \s-1AIO\s0 (\fInot\fR \f(CWaio(7)\fR but \f(CWio_submit(2)\fR) event interface available in post\-4.18 kernels (but libev |
|
|
720 | only tries to use it in 4.19+). |
|
|
721 | .Sp |
|
|
722 | This is another Linux train wreck of an event interface. |
|
|
723 | .Sp |
|
|
724 | If this backend works for you (as of this writing, it was very |
|
|
725 | experimental), it is the best event interface available on Linux and might |
|
|
726 | be well worth enabling it \- if it isn't available in your kernel this will |
|
|
727 | be detected and this backend will be skipped. |
|
|
728 | .Sp |
|
|
729 | This backend can batch oneshot requests and supports a user-space ring |
|
|
730 | buffer to receive events. It also doesn't suffer from most of the design |
|
|
731 | problems of epoll (such as not being able to remove event sources from |
|
|
732 | the epoll set), and generally sounds too good to be true. Because, this |
|
|
733 | being the Linux kernel, of course it suffers from a whole new set of |
|
|
734 | limitations, forcing you to fall back to epoll, inheriting all its design |
|
|
735 | issues. |
|
|
736 | .Sp |
|
|
737 | For one, it is not easily embeddable (but probably could be done using |
|
|
738 | an event fd at some extra overhead). It also is subject to a system wide |
|
|
739 | limit that can be configured in \fI/proc/sys/fs/aio\-max\-nr\fR. If no \s-1AIO\s0 |
|
|
740 | requests are left, this backend will be skipped during initialisation, and |
|
|
741 | will switch to epoll when the loop is active. |
|
|
742 | .Sp |
|
|
743 | Most problematic in practice, however, is that not all file descriptors |
|
|
744 | work with it. For example, in Linux 5.1, \s-1TCP\s0 sockets, pipes, event fds, |
|
|
745 | files, \fI/dev/null\fR and many others are supported, but ttys do not work |
|
|
746 | properly (a known bug that the kernel developers don't care about, see |
|
|
747 | <https://lore.kernel.org/patchwork/patch/1047453/>), so this is not |
|
|
748 | (yet?) a generic event polling interface. |
|
|
749 | .Sp |
|
|
750 | Overall, it seems the Linux developers just don't want it to have a |
|
|
751 | generic event handling mechanism other than \f(CW\*(C`select\*(C'\fR or \f(CW\*(C`poll\*(C'\fR. |
|
|
752 | .Sp |
|
|
753 | To work around all these problem, the current version of libev uses its |
|
|
754 | epoll backend as a fallback for file descriptor types that do not work. Or |
|
|
755 | falls back completely to epoll if the kernel acts up. |
678 | .Sp |
756 | .Sp |
679 | This backend maps \f(CW\*(C`EV_READ\*(C'\fR and \f(CW\*(C`EV_WRITE\*(C'\fR in the same way as |
757 | This backend maps \f(CW\*(C`EV_READ\*(C'\fR and \f(CW\*(C`EV_WRITE\*(C'\fR in the same way as |
680 | \&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
758 | \&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
681 | .ie n .IP """EVBACKEND_KQUEUE"" (value 8, most \s-1BSD\s0 clones)" 4 |
759 | .ie n .IP """EVBACKEND_KQUEUE"" (value 8, most \s-1BSD\s0 clones)" 4 |
682 | .el .IP "\f(CWEVBACKEND_KQUEUE\fR (value 8, most \s-1BSD\s0 clones)" 4 |
760 | .el .IP "\f(CWEVBACKEND_KQUEUE\fR (value 8, most \s-1BSD\s0 clones)" 4 |
683 | .IX Item "EVBACKEND_KQUEUE (value 8, most BSD clones)" |
761 | .IX Item "EVBACKEND_KQUEUE (value 8, most BSD clones)" |
684 | Kqueue deserves special mention, as at the time of this writing, it |
762 | Kqueue deserves special mention, as at the time this backend was |
685 | was broken on all BSDs except NetBSD (usually it doesn't work reliably |
763 | implemented, it was broken on all BSDs except NetBSD (usually it doesn't |
686 | with anything but sockets and pipes, except on Darwin, where of course |
764 | work reliably with anything but sockets and pipes, except on Darwin, |
687 | it's completely useless). Unlike epoll, however, whose brokenness |
765 | where of course it's completely useless). Unlike epoll, however, whose |
688 | is by design, these kqueue bugs can (and eventually will) be fixed |
766 | brokenness is by design, these kqueue bugs can be (and mostly have been) |
689 | without \s-1API\s0 changes to existing programs. For this reason it's not being |
767 | fixed without \s-1API\s0 changes to existing programs. For this reason it's not |
690 | \&\*(L"auto-detected\*(R" unless you explicitly specify it in the flags (i.e. using |
768 | being \*(L"auto-detected\*(R" on all platforms unless you explicitly specify it |
691 | \&\f(CW\*(C`EVBACKEND_KQUEUE\*(C'\fR) or libev was compiled on a known-to-be-good (\-enough) |
769 | in the flags (i.e. using \f(CW\*(C`EVBACKEND_KQUEUE\*(C'\fR) or libev was compiled on a |
692 | system like NetBSD. |
770 | known-to-be-good (\-enough) system like NetBSD. |
693 | .Sp |
771 | .Sp |
694 | You still can embed kqueue into a normal poll or select backend and use it |
772 | You still can embed kqueue into a normal poll or select backend and use it |
695 | only for sockets (after having made sure that sockets work with kqueue on |
773 | only for sockets (after having made sure that sockets work with kqueue on |
696 | the target platform). See \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. |
774 | the target platform). See \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. |
697 | .Sp |
775 | .Sp |
698 | It scales in the same way as the epoll backend, but the interface to the |
776 | It scales in the same way as the epoll backend, but the interface to the |
699 | kernel is more efficient (which says nothing about its actual speed, of |
777 | kernel is more efficient (which says nothing about its actual speed, of |
700 | course). While stopping, setting and starting an I/O watcher does never |
778 | course). While stopping, setting and starting an I/O watcher does never |
701 | cause an extra system call as with \f(CW\*(C`EVBACKEND_EPOLL\*(C'\fR, it still adds up to |
779 | cause an extra system call as with \f(CW\*(C`EVBACKEND_EPOLL\*(C'\fR, it still adds up to |
702 | two event changes per incident. Support for \f(CW\*(C`fork ()\*(C'\fR is very bad (you |
780 | two event changes per incident. Support for \f(CW\*(C`fork ()\*(C'\fR is very bad (you |
703 | might have to leak fd's on fork, but it's more sane than epoll) and it |
781 | might have to leak fds on fork, but it's more sane than epoll) and it |
704 | drops fds silently in similarly hard-to-detect cases. |
782 | drops fds silently in similarly hard-to-detect cases. |
705 | .Sp |
783 | .Sp |
706 | This backend usually performs well under most conditions. |
784 | This backend usually performs well under most conditions. |
707 | .Sp |
785 | .Sp |
708 | While nominally embeddable in other event loops, this doesn't work |
786 | While nominally embeddable in other event loops, this doesn't work |
… | |
… | |
723 | and is not embeddable, which would limit the usefulness of this backend |
801 | and is not embeddable, which would limit the usefulness of this backend |
724 | immensely. |
802 | immensely. |
725 | .ie n .IP """EVBACKEND_PORT"" (value 32, Solaris 10)" 4 |
803 | .ie n .IP """EVBACKEND_PORT"" (value 32, Solaris 10)" 4 |
726 | .el .IP "\f(CWEVBACKEND_PORT\fR (value 32, Solaris 10)" 4 |
804 | .el .IP "\f(CWEVBACKEND_PORT\fR (value 32, Solaris 10)" 4 |
727 | .IX Item "EVBACKEND_PORT (value 32, Solaris 10)" |
805 | .IX Item "EVBACKEND_PORT (value 32, Solaris 10)" |
728 | This uses the Solaris 10 event port mechanism. As with everything on Solaris, |
806 | This uses the Solaris 10 event port mechanism. As with everything on |
729 | it's really slow, but it still scales very well (O(active_fds)). |
807 | Solaris, it's really slow, but it still scales very well (O(active_fds)). |
730 | .Sp |
808 | .Sp |
731 | While this backend scales well, it requires one system call per active |
809 | While this backend scales well, it requires one system call per active |
732 | file descriptor per loop iteration. For small and medium numbers of file |
810 | file descriptor per loop iteration. For small and medium numbers of file |
733 | descriptors a \*(L"slow\*(R" \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR backend |
811 | descriptors a \*(L"slow\*(R" \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR backend |
734 | might perform better. |
812 | might perform better. |
… | |
… | |
785 | Example: Use whatever libev has to offer, but make sure that kqueue is |
863 | Example: Use whatever libev has to offer, but make sure that kqueue is |
786 | used if available. |
864 | used if available. |
787 | .Sp |
865 | .Sp |
788 | .Vb 1 |
866 | .Vb 1 |
789 | \& struct ev_loop *loop = ev_loop_new (ev_recommended_backends () | EVBACKEND_KQUEUE); |
867 | \& struct ev_loop *loop = ev_loop_new (ev_recommended_backends () | EVBACKEND_KQUEUE); |
|
|
868 | .Ve |
|
|
869 | .Sp |
|
|
870 | Example: Similarly, on linux, you mgiht want to take advantage of the |
|
|
871 | linux aio backend if possible, but fall back to something else if that |
|
|
872 | isn't available. |
|
|
873 | .Sp |
|
|
874 | .Vb 1 |
|
|
875 | \& struct ev_loop *loop = ev_loop_new (ev_recommended_backends () | EVBACKEND_LINUXAIO); |
790 | .Ve |
876 | .Ve |
791 | .RE |
877 | .RE |
792 | .IP "ev_loop_destroy (loop)" 4 |
878 | .IP "ev_loop_destroy (loop)" 4 |
793 | .IX Item "ev_loop_destroy (loop)" |
879 | .IX Item "ev_loop_destroy (loop)" |
794 | Destroys an event loop object (frees all memory and kernel state |
880 | Destroys an event loop object (frees all memory and kernel state |
… | |
… | |
1001 | \& \- Queue all expired timers. |
1087 | \& \- Queue all expired timers. |
1002 | \& \- Queue all expired periodics. |
1088 | \& \- Queue all expired periodics. |
1003 | \& \- Queue all idle watchers with priority higher than that of pending events. |
1089 | \& \- Queue all idle watchers with priority higher than that of pending events. |
1004 | \& \- Queue all check watchers. |
1090 | \& \- Queue all check watchers. |
1005 | \& \- Call all queued watchers in reverse order (i.e. check watchers first). |
1091 | \& \- Call all queued watchers in reverse order (i.e. check watchers first). |
1006 | \& Signals and child watchers are implemented as I/O watchers, and will |
1092 | \& Signals, async and child watchers are implemented as I/O watchers, and |
1007 | \& be handled here by queueing them when their watcher gets executed. |
1093 | \& will be handled here by queueing them when their watcher gets executed. |
1008 | \& \- If ev_break has been called, or EVRUN_ONCE or EVRUN_NOWAIT |
1094 | \& \- If ev_break has been called, or EVRUN_ONCE or EVRUN_NOWAIT |
1009 | \& were used, or there are no active watchers, goto FINISH, otherwise |
1095 | \& were used, or there are no active watchers, goto FINISH, otherwise |
1010 | \& continue with step LOOP. |
1096 | \& continue with step LOOP. |
1011 | \& FINISH: |
1097 | \& FINISH: |
1012 | \& \- Reset the ev_break status iff it was EVBREAK_ONE. |
1098 | \& \- Reset the ev_break status iff it was EVBREAK_ONE. |
… | |
… | |
1263 | with a watcher-specific start function (\f(CW\*(C`ev_TYPE_start (loop, watcher |
1349 | with a watcher-specific start function (\f(CW\*(C`ev_TYPE_start (loop, watcher |
1264 | *)\*(C'\fR), and you can stop watching for events at any time by calling the |
1350 | *)\*(C'\fR), and you can stop watching for events at any time by calling the |
1265 | corresponding stop function (\f(CW\*(C`ev_TYPE_stop (loop, watcher *)\*(C'\fR. |
1351 | corresponding stop function (\f(CW\*(C`ev_TYPE_stop (loop, watcher *)\*(C'\fR. |
1266 | .PP |
1352 | .PP |
1267 | As long as your watcher is active (has been started but not stopped) you |
1353 | As long as your watcher is active (has been started but not stopped) you |
1268 | must not touch the values stored in it. Most specifically you must never |
1354 | must not touch the values stored in it except when explicitly documented |
1269 | reinitialise it or call its \f(CW\*(C`ev_TYPE_set\*(C'\fR macro. |
1355 | otherwise. Most specifically you must never reinitialise it or call its |
|
|
1356 | \&\f(CW\*(C`ev_TYPE_set\*(C'\fR macro. |
1270 | .PP |
1357 | .PP |
1271 | Each and every callback receives the event loop pointer as first, the |
1358 | Each and every callback receives the event loop pointer as first, the |
1272 | registered watcher structure as second, and a bitset of received events as |
1359 | registered watcher structure as second, and a bitset of received events as |
1273 | third argument. |
1360 | third argument. |
1274 | .PP |
1361 | .PP |
… | |
… | |
1365 | bug in your program. |
1452 | bug in your program. |
1366 | .Sp |
1453 | .Sp |
1367 | Libev will usually signal a few \*(L"dummy\*(R" events together with an error, for |
1454 | Libev will usually signal a few \*(L"dummy\*(R" events together with an error, for |
1368 | example it might indicate that a fd is readable or writable, and if your |
1455 | example it might indicate that a fd is readable or writable, and if your |
1369 | callbacks is well-written it can just attempt the operation and cope with |
1456 | callbacks is well-written it can just attempt the operation and cope with |
1370 | the error from \fIread()\fR or \fIwrite()\fR. This will not work in multi-threaded |
1457 | the error from \fBread()\fR or \fBwrite()\fR. This will not work in multi-threaded |
1371 | programs, though, as the fd could already be closed and reused for another |
1458 | programs, though, as the fd could already be closed and reused for another |
1372 | thing, so beware. |
1459 | thing, so beware. |
1373 | .SS "\s-1GENERIC WATCHER FUNCTIONS\s0" |
1460 | .SS "\s-1GENERIC WATCHER FUNCTIONS\s0" |
1374 | .IX Subsection "GENERIC WATCHER FUNCTIONS" |
1461 | .IX Subsection "GENERIC WATCHER FUNCTIONS" |
1375 | .ie n .IP """ev_init"" (ev_TYPE *watcher, callback)" 4 |
1462 | .ie n .IP """ev_init"" (ev_TYPE *watcher, callback)" 4 |
… | |
… | |
1445 | therefore a good idea to always call its \f(CW\*(C`ev_TYPE_stop\*(C'\fR function. |
1532 | therefore a good idea to always call its \f(CW\*(C`ev_TYPE_stop\*(C'\fR function. |
1446 | .IP "bool ev_is_active (ev_TYPE *watcher)" 4 |
1533 | .IP "bool ev_is_active (ev_TYPE *watcher)" 4 |
1447 | .IX Item "bool ev_is_active (ev_TYPE *watcher)" |
1534 | .IX Item "bool ev_is_active (ev_TYPE *watcher)" |
1448 | Returns a true value iff the watcher is active (i.e. it has been started |
1535 | Returns a true value iff the watcher is active (i.e. it has been started |
1449 | and not yet been stopped). As long as a watcher is active you must not modify |
1536 | and not yet been stopped). As long as a watcher is active you must not modify |
1450 | it. |
1537 | it unless documented otherwise. |
|
|
1538 | .Sp |
|
|
1539 | Obviously, it is safe to call this on an active watcher, or actually any |
|
|
1540 | watcher that is initialised. |
1451 | .IP "bool ev_is_pending (ev_TYPE *watcher)" 4 |
1541 | .IP "bool ev_is_pending (ev_TYPE *watcher)" 4 |
1452 | .IX Item "bool ev_is_pending (ev_TYPE *watcher)" |
1542 | .IX Item "bool ev_is_pending (ev_TYPE *watcher)" |
1453 | Returns a true value iff the watcher is pending, (i.e. it has outstanding |
1543 | Returns a true value iff the watcher is pending, (i.e. it has outstanding |
1454 | events but its callback has not yet been invoked). As long as a watcher |
1544 | events but its callback has not yet been invoked). As long as a watcher |
1455 | is pending (but not active) you must not call an init function on it (but |
1545 | is pending (but not active) you must not call an init function on it (but |
1456 | \&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe), you must not change its priority, and you must |
1546 | \&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe), you must not change its priority, and you must |
1457 | make sure the watcher is available to libev (e.g. you cannot \f(CW\*(C`free ()\*(C'\fR |
1547 | make sure the watcher is available to libev (e.g. you cannot \f(CW\*(C`free ()\*(C'\fR |
1458 | it). |
1548 | it). |
|
|
1549 | .Sp |
|
|
1550 | It is safe to call this on any watcher in any state as long as it is |
|
|
1551 | initialised. |
1459 | .IP "callback ev_cb (ev_TYPE *watcher)" 4 |
1552 | .IP "callback ev_cb (ev_TYPE *watcher)" 4 |
1460 | .IX Item "callback ev_cb (ev_TYPE *watcher)" |
1553 | .IX Item "callback ev_cb (ev_TYPE *watcher)" |
1461 | Returns the callback currently set on the watcher. |
1554 | Returns the callback currently set on the watcher. |
1462 | .IP "ev_set_cb (ev_TYPE *watcher, callback)" 4 |
1555 | .IP "ev_set_cb (ev_TYPE *watcher, callback)" 4 |
1463 | .IX Item "ev_set_cb (ev_TYPE *watcher, callback)" |
1556 | .IX Item "ev_set_cb (ev_TYPE *watcher, callback)" |
… | |
… | |
1476 | from being executed (except for \f(CW\*(C`ev_idle\*(C'\fR watchers). |
1569 | from being executed (except for \f(CW\*(C`ev_idle\*(C'\fR watchers). |
1477 | .Sp |
1570 | .Sp |
1478 | If you need to suppress invocation when higher priority events are pending |
1571 | If you need to suppress invocation when higher priority events are pending |
1479 | you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality. |
1572 | you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality. |
1480 | .Sp |
1573 | .Sp |
1481 | You \fImust not\fR change the priority of a watcher as long as it is active or |
1574 | You \fImust not\fR change the priority of a watcher as long as it is active |
1482 | pending. |
1575 | or pending. Reading the priority with \f(CW\*(C`ev_priority\*(C'\fR is fine in any state. |
1483 | .Sp |
1576 | .Sp |
1484 | Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is |
1577 | Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is |
1485 | fine, as long as you do not mind that the priority value you query might |
1578 | fine, as long as you do not mind that the priority value you query might |
1486 | or might not have been clamped to the valid range. |
1579 | or might not have been clamped to the valid range. |
1487 | .Sp |
1580 | .Sp |
… | |
… | |
1506 | callback to be invoked, which can be accomplished with this function. |
1599 | callback to be invoked, which can be accomplished with this function. |
1507 | .IP "ev_feed_event (loop, ev_TYPE *watcher, int revents)" 4 |
1600 | .IP "ev_feed_event (loop, ev_TYPE *watcher, int revents)" 4 |
1508 | .IX Item "ev_feed_event (loop, ev_TYPE *watcher, int revents)" |
1601 | .IX Item "ev_feed_event (loop, ev_TYPE *watcher, int revents)" |
1509 | Feeds the given event set into the event loop, as if the specified event |
1602 | Feeds the given event set into the event loop, as if the specified event |
1510 | had happened for the specified watcher (which must be a pointer to an |
1603 | had happened for the specified watcher (which must be a pointer to an |
1511 | initialised but not necessarily started event watcher). Obviously you must |
1604 | initialised but not necessarily started event watcher, though it can be |
1512 | not free the watcher as long as it has pending events. |
1605 | active). Obviously you must not free the watcher as long as it has pending |
|
|
1606 | events. |
1513 | .Sp |
1607 | .Sp |
1514 | Stopping the watcher, letting libev invoke it, or calling |
1608 | Stopping the watcher, letting libev invoke it, or calling |
1515 | \&\f(CW\*(C`ev_clear_pending\*(C'\fR will clear the pending event, even if the watcher was |
1609 | \&\f(CW\*(C`ev_clear_pending\*(C'\fR will clear the pending event, even if the watcher was |
1516 | not started in the first place. |
1610 | not started in the first place. |
1517 | .Sp |
1611 | .Sp |
… | |
… | |
1538 | \&\f(CW\*(C`ev_TYPE_init\*(C'\fR again. |
1632 | \&\f(CW\*(C`ev_TYPE_init\*(C'\fR again. |
1539 | .IP "started/running/active" 4 |
1633 | .IP "started/running/active" 4 |
1540 | .IX Item "started/running/active" |
1634 | .IX Item "started/running/active" |
1541 | Once a watcher has been started with a call to \f(CW\*(C`ev_TYPE_start\*(C'\fR it becomes |
1635 | Once a watcher has been started with a call to \f(CW\*(C`ev_TYPE_start\*(C'\fR it becomes |
1542 | property of the event loop, and is actively waiting for events. While in |
1636 | property of the event loop, and is actively waiting for events. While in |
1543 | this state it cannot be accessed (except in a few documented ways), moved, |
1637 | this state it cannot be accessed (except in a few documented ways, such as |
1544 | freed or anything else \- the only legal thing is to keep a pointer to it, |
1638 | stoping it), moved, freed or anything else \- the only legal thing is to |
1545 | and call libev functions on it that are documented to work on active watchers. |
1639 | keep a pointer to it, and call libev functions on it that are documented |
|
|
1640 | to work on active watchers. |
|
|
1641 | .Sp |
|
|
1642 | As a rule of thumb, before accessing a member or calling any function on |
|
|
1643 | a watcher, it should be stopped (or freshly initialised). If that is not |
|
|
1644 | convenient, you can check the documentation for that function or member to |
|
|
1645 | see if it is safe to use on an active watcher. |
1546 | .IP "pending" 4 |
1646 | .IP "pending" 4 |
1547 | .IX Item "pending" |
1647 | .IX Item "pending" |
1548 | If a watcher is active and libev determines that an event it is interested |
1648 | If a watcher is active and libev determines that an event it is interested |
1549 | in has occurred (such as a timer expiring), it will become pending. It will |
1649 | in has occurred (such as a timer expiring), it will become pending. It |
1550 | stay in this pending state until either it is stopped or its callback is |
1650 | will stay in this pending state until either it is explicitly stopped or |
1551 | about to be invoked, so it is not normally pending inside the watcher |
1651 | its callback is about to be invoked, so it is not normally pending inside |
1552 | callback. |
1652 | the watcher callback. |
1553 | .Sp |
1653 | .Sp |
1554 | The watcher might or might not be active while it is pending (for example, |
1654 | Generally, the watcher might or might not be active while it is pending |
1555 | an expired non-repeating timer can be pending but no longer active). If it |
1655 | (for example, an expired non-repeating timer can be pending but no longer |
1556 | is stopped, it can be freely accessed (e.g. by calling \f(CW\*(C`ev_TYPE_set\*(C'\fR), |
1656 | active). If it is pending but not active, it can be freely accessed (e.g. |
1557 | but it is still property of the event loop at this time, so cannot be |
1657 | by calling \f(CW\*(C`ev_TYPE_set\*(C'\fR), but it is still property of the event loop at |
1558 | moved, freed or reused. And if it is active the rules described in the |
1658 | this time, so cannot be moved, freed or reused. And if it is active the |
1559 | previous item still apply. |
1659 | rules described in the previous item still apply. |
|
|
1660 | .Sp |
|
|
1661 | Explicitly stopping a watcher will also clear the pending state |
|
|
1662 | unconditionally, so it is safe to stop a watcher and then free it. |
1560 | .Sp |
1663 | .Sp |
1561 | It is also possible to feed an event on a watcher that is not active (e.g. |
1664 | It is also possible to feed an event on a watcher that is not active (e.g. |
1562 | via \f(CW\*(C`ev_feed_event\*(C'\fR), in which case it becomes pending without being |
1665 | via \f(CW\*(C`ev_feed_event\*(C'\fR), in which case it becomes pending without being |
1563 | active. |
1666 | active. |
1564 | .IP "stopped" 4 |
1667 | .IP "stopped" 4 |
… | |
… | |
1577 | .IX Subsection "WATCHER PRIORITY MODELS" |
1680 | .IX Subsection "WATCHER PRIORITY MODELS" |
1578 | Many event loops support \fIwatcher priorities\fR, which are usually small |
1681 | Many event loops support \fIwatcher priorities\fR, which are usually small |
1579 | integers that influence the ordering of event callback invocation |
1682 | integers that influence the ordering of event callback invocation |
1580 | between watchers in some way, all else being equal. |
1683 | between watchers in some way, all else being equal. |
1581 | .PP |
1684 | .PP |
1582 | In libev, Watcher priorities can be set using \f(CW\*(C`ev_set_priority\*(C'\fR. See its |
1685 | In libev, watcher priorities can be set using \f(CW\*(C`ev_set_priority\*(C'\fR. See its |
1583 | description for the more technical details such as the actual priority |
1686 | description for the more technical details such as the actual priority |
1584 | range. |
1687 | range. |
1585 | .PP |
1688 | .PP |
1586 | There are two common ways how these these priorities are being interpreted |
1689 | There are two common ways how these these priorities are being interpreted |
1587 | by event loops: |
1690 | by event loops: |
… | |
… | |
1681 | .IX Header "WATCHER TYPES" |
1784 | .IX Header "WATCHER TYPES" |
1682 | This section describes each watcher in detail, but will not repeat |
1785 | This section describes each watcher in detail, but will not repeat |
1683 | information given in the last section. Any initialisation/set macros, |
1786 | information given in the last section. Any initialisation/set macros, |
1684 | functions and members specific to the watcher type are explained. |
1787 | functions and members specific to the watcher type are explained. |
1685 | .PP |
1788 | .PP |
1686 | Members are additionally marked with either \fI[read\-only]\fR, meaning that, |
1789 | Most members are additionally marked with either \fI[read\-only]\fR, meaning |
1687 | while the watcher is active, you can look at the member and expect some |
1790 | that, while the watcher is active, you can look at the member and expect |
1688 | sensible content, but you must not modify it (you can modify it while the |
1791 | some sensible content, but you must not modify it (you can modify it while |
1689 | watcher is stopped to your hearts content), or \fI[read\-write]\fR, which |
1792 | the watcher is stopped to your hearts content), or \fI[read\-write]\fR, which |
1690 | means you can expect it to have some sensible content while the watcher |
1793 | means you can expect it to have some sensible content while the watcher is |
1691 | is active, but you can also modify it. Modifying it may not do something |
1794 | active, but you can also modify it (within the same thread as the event |
|
|
1795 | loop, i.e. without creating data races). Modifying it may not do something |
1692 | sensible or take immediate effect (or do anything at all), but libev will |
1796 | sensible or take immediate effect (or do anything at all), but libev will |
1693 | not crash or malfunction in any way. |
1797 | not crash or malfunction in any way. |
|
|
1798 | .PP |
|
|
1799 | In any case, the documentation for each member will explain what the |
|
|
1800 | effects are, and if there are any additional access restrictions. |
1694 | .ie n .SS """ev_io"" \- is this file descriptor readable or writable?" |
1801 | .ie n .SS """ev_io"" \- is this file descriptor readable or writable?" |
1695 | .el .SS "\f(CWev_io\fP \- is this file descriptor readable or writable?" |
1802 | .el .SS "\f(CWev_io\fP \- is this file descriptor readable or writable?" |
1696 | .IX Subsection "ev_io - is this file descriptor readable or writable?" |
1803 | .IX Subsection "ev_io - is this file descriptor readable or writable?" |
1697 | I/O watchers check whether a file descriptor is readable or writable |
1804 | I/O watchers check whether a file descriptor is readable or writable |
1698 | in each iteration of the event loop, or, more precisely, when reading |
1805 | in each iteration of the event loop, or, more precisely, when reading |
… | |
… | |
1726 | But really, best use non-blocking mode. |
1833 | But really, best use non-blocking mode. |
1727 | .PP |
1834 | .PP |
1728 | \fIThe special problem of disappearing file descriptors\fR |
1835 | \fIThe special problem of disappearing file descriptors\fR |
1729 | .IX Subsection "The special problem of disappearing file descriptors" |
1836 | .IX Subsection "The special problem of disappearing file descriptors" |
1730 | .PP |
1837 | .PP |
1731 | Some backends (e.g. kqueue, epoll) need to be told about closing a file |
1838 | Some backends (e.g. kqueue, epoll, linuxaio) need to be told about closing |
1732 | descriptor (either due to calling \f(CW\*(C`close\*(C'\fR explicitly or any other means, |
1839 | a file descriptor (either due to calling \f(CW\*(C`close\*(C'\fR explicitly or any other |
1733 | such as \f(CW\*(C`dup2\*(C'\fR). The reason is that you register interest in some file |
1840 | means, such as \f(CW\*(C`dup2\*(C'\fR). The reason is that you register interest in some |
1734 | descriptor, but when it goes away, the operating system will silently drop |
1841 | file descriptor, but when it goes away, the operating system will silently |
1735 | this interest. If another file descriptor with the same number then is |
1842 | drop this interest. If another file descriptor with the same number then |
1736 | registered with libev, there is no efficient way to see that this is, in |
1843 | is registered with libev, there is no efficient way to see that this is, |
1737 | fact, a different file descriptor. |
1844 | in fact, a different file descriptor. |
1738 | .PP |
1845 | .PP |
1739 | To avoid having to explicitly tell libev about such cases, libev follows |
1846 | To avoid having to explicitly tell libev about such cases, libev follows |
1740 | the following policy: Each time \f(CW\*(C`ev_io_set\*(C'\fR is being called, libev |
1847 | the following policy: Each time \f(CW\*(C`ev_io_set\*(C'\fR is being called, libev |
1741 | will assume that this is potentially a new file descriptor, otherwise |
1848 | will assume that this is potentially a new file descriptor, otherwise |
1742 | it is assumed that the file descriptor stays the same. That means that |
1849 | it is assumed that the file descriptor stays the same. That means that |
… | |
… | |
1794 | reuse the same code path. |
1901 | reuse the same code path. |
1795 | .PP |
1902 | .PP |
1796 | \fIThe special problem of fork\fR |
1903 | \fIThe special problem of fork\fR |
1797 | .IX Subsection "The special problem of fork" |
1904 | .IX Subsection "The special problem of fork" |
1798 | .PP |
1905 | .PP |
1799 | Some backends (epoll, kqueue) do not support \f(CW\*(C`fork ()\*(C'\fR at all or exhibit |
1906 | Some backends (epoll, kqueue, linuxaio, iouring) do not support \f(CW\*(C`fork ()\*(C'\fR |
1800 | useless behaviour. Libev fully supports fork, but needs to be told about |
1907 | at all or exhibit useless behaviour. Libev fully supports fork, but needs |
1801 | it in the child if you want to continue to use it in the child. |
1908 | to be told about it in the child if you want to continue to use it in the |
|
|
1909 | child. |
1802 | .PP |
1910 | .PP |
1803 | To support fork in your child processes, you have to call \f(CW\*(C`ev_loop_fork |
1911 | To support fork in your child processes, you have to call \f(CW\*(C`ev_loop_fork |
1804 | ()\*(C'\fR after a fork in the child, enable \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR, or resort to |
1912 | ()\*(C'\fR after a fork in the child, enable \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR, or resort to |
1805 | \&\f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
1913 | \&\f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
1806 | .PP |
1914 | .PP |
… | |
… | |
1811 | when writing to a pipe whose other end has been closed, your program gets |
1919 | when writing to a pipe whose other end has been closed, your program gets |
1812 | sent a \s-1SIGPIPE,\s0 which, by default, aborts your program. For most programs |
1920 | sent a \s-1SIGPIPE,\s0 which, by default, aborts your program. For most programs |
1813 | this is sensible behaviour, for daemons, this is usually undesirable. |
1921 | this is sensible behaviour, for daemons, this is usually undesirable. |
1814 | .PP |
1922 | .PP |
1815 | So when you encounter spurious, unexplained daemon exits, make sure you |
1923 | So when you encounter spurious, unexplained daemon exits, make sure you |
1816 | ignore \s-1SIGPIPE \s0(and maybe make sure you log the exit status of your daemon |
1924 | ignore \s-1SIGPIPE\s0 (and maybe make sure you log the exit status of your daemon |
1817 | somewhere, as that would have given you a big clue). |
1925 | somewhere, as that would have given you a big clue). |
1818 | .PP |
1926 | .PP |
1819 | \fIThe special problem of \fIaccept()\fIing when you can't\fR |
1927 | \fIThe special problem of \f(BIaccept()\fIing when you can't\fR |
1820 | .IX Subsection "The special problem of accept()ing when you can't" |
1928 | .IX Subsection "The special problem of accept()ing when you can't" |
1821 | .PP |
1929 | .PP |
1822 | Many implementations of the \s-1POSIX \s0\f(CW\*(C`accept\*(C'\fR function (for example, |
1930 | Many implementations of the \s-1POSIX\s0 \f(CW\*(C`accept\*(C'\fR function (for example, |
1823 | found in post\-2004 Linux) have the peculiar behaviour of not removing a |
1931 | found in post\-2004 Linux) have the peculiar behaviour of not removing a |
1824 | connection from the pending queue in all error cases. |
1932 | connection from the pending queue in all error cases. |
1825 | .PP |
1933 | .PP |
1826 | For example, larger servers often run out of file descriptors (because |
1934 | For example, larger servers often run out of file descriptors (because |
1827 | of resource limits), causing \f(CW\*(C`accept\*(C'\fR to fail with \f(CW\*(C`ENFILE\*(C'\fR but not |
1935 | of resource limits), causing \f(CW\*(C`accept\*(C'\fR to fail with \f(CW\*(C`ENFILE\*(C'\fR but not |
… | |
… | |
1863 | .PD 0 |
1971 | .PD 0 |
1864 | .IP "ev_io_set (ev_io *, int fd, int events)" 4 |
1972 | .IP "ev_io_set (ev_io *, int fd, int events)" 4 |
1865 | .IX Item "ev_io_set (ev_io *, int fd, int events)" |
1973 | .IX Item "ev_io_set (ev_io *, int fd, int events)" |
1866 | .PD |
1974 | .PD |
1867 | Configures an \f(CW\*(C`ev_io\*(C'\fR watcher. The \f(CW\*(C`fd\*(C'\fR is the file descriptor to |
1975 | Configures an \f(CW\*(C`ev_io\*(C'\fR watcher. The \f(CW\*(C`fd\*(C'\fR is the file descriptor to |
1868 | receive events for and \f(CW\*(C`events\*(C'\fR is either \f(CW\*(C`EV_READ\*(C'\fR, \f(CW\*(C`EV_WRITE\*(C'\fR or |
1976 | receive events for and \f(CW\*(C`events\*(C'\fR is either \f(CW\*(C`EV_READ\*(C'\fR, \f(CW\*(C`EV_WRITE\*(C'\fR, both |
1869 | \&\f(CW\*(C`EV_READ | EV_WRITE\*(C'\fR, to express the desire to receive the given events. |
1977 | \&\f(CW\*(C`EV_READ | EV_WRITE\*(C'\fR or \f(CW0\fR, to express the desire to receive the given |
|
|
1978 | events. |
|
|
1979 | .Sp |
|
|
1980 | Note that setting the \f(CW\*(C`events\*(C'\fR to \f(CW0\fR and starting the watcher is |
|
|
1981 | supported, but not specially optimized \- if your program sometimes happens |
|
|
1982 | to generate this combination this is fine, but if it is easy to avoid |
|
|
1983 | starting an io watcher watching for no events you should do so. |
|
|
1984 | .IP "ev_io_modify (ev_io *, int events)" 4 |
|
|
1985 | .IX Item "ev_io_modify (ev_io *, int events)" |
|
|
1986 | Similar to \f(CW\*(C`ev_io_set\*(C'\fR, but only changes the requested events. Using this |
|
|
1987 | might be faster with some backends, as libev can assume that the \f(CW\*(C`fd\*(C'\fR |
|
|
1988 | still refers to the same underlying file description, something it cannot |
|
|
1989 | do when using \f(CW\*(C`ev_io_set\*(C'\fR. |
1870 | .IP "int fd [read\-only]" 4 |
1990 | .IP "int fd [no\-modify]" 4 |
1871 | .IX Item "int fd [read-only]" |
1991 | .IX Item "int fd [no-modify]" |
1872 | The file descriptor being watched. |
1992 | The file descriptor being watched. While it can be read at any time, you |
|
|
1993 | must not modify this member even when the watcher is stopped \- always use |
|
|
1994 | \&\f(CW\*(C`ev_io_set\*(C'\fR for that. |
1873 | .IP "int events [read\-only]" 4 |
1995 | .IP "int events [no\-modify]" 4 |
1874 | .IX Item "int events [read-only]" |
1996 | .IX Item "int events [no-modify]" |
1875 | The events being watched. |
1997 | The set of events the fd is being watched for, among other flags. Remember |
|
|
1998 | that this is a bit set \- to test for \f(CW\*(C`EV_READ\*(C'\fR, use \f(CW\*(C`w\->events & |
|
|
1999 | EV_READ\*(C'\fR, and similarly for \f(CW\*(C`EV_WRITE\*(C'\fR. |
|
|
2000 | .Sp |
|
|
2001 | As with \f(CW\*(C`fd\*(C'\fR, you must not modify this member even when the watcher is |
|
|
2002 | stopped, always use \f(CW\*(C`ev_io_set\*(C'\fR or \f(CW\*(C`ev_io_modify\*(C'\fR for that. |
1876 | .PP |
2003 | .PP |
1877 | \fIExamples\fR |
2004 | \fIExamples\fR |
1878 | .IX Subsection "Examples" |
2005 | .IX Subsection "Examples" |
1879 | .PP |
2006 | .PP |
1880 | Example: Call \f(CW\*(C`stdin_readable_cb\*(C'\fR when \s-1STDIN_FILENO\s0 has become, well |
2007 | Example: Call \f(CW\*(C`stdin_readable_cb\*(C'\fR when \s-1STDIN_FILENO\s0 has become, well |
… | |
… | |
2434 | In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`offset\*(C'\fR are both being |
2561 | In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`offset\*(C'\fR are both being |
2435 | ignored. Instead, each time the periodic watcher gets scheduled, the |
2562 | ignored. Instead, each time the periodic watcher gets scheduled, the |
2436 | reschedule callback will be called with the watcher as first, and the |
2563 | reschedule callback will be called with the watcher as first, and the |
2437 | current time as second argument. |
2564 | current time as second argument. |
2438 | .Sp |
2565 | .Sp |
2439 | \&\s-1NOTE: \s0\fIThis callback \s-1MUST NOT\s0 stop or destroy any periodic watcher, ever, |
2566 | \&\s-1NOTE:\s0 \fIThis callback \s-1MUST NOT\s0 stop or destroy any periodic watcher, ever, |
2440 | or make \s-1ANY\s0 other event loop modifications whatsoever, unless explicitly |
2567 | or make \s-1ANY\s0 other event loop modifications whatsoever, unless explicitly |
2441 | allowed by documentation here\fR. |
2568 | allowed by documentation here\fR. |
2442 | .Sp |
2569 | .Sp |
2443 | If you need to stop it, return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop |
2570 | If you need to stop it, return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop |
2444 | it afterwards (e.g. by starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is the |
2571 | it afterwards (e.g. by starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is the |
… | |
… | |
2458 | It must return the next time to trigger, based on the passed time value |
2585 | It must return the next time to trigger, based on the passed time value |
2459 | (that is, the lowest time value larger than to the second argument). It |
2586 | (that is, the lowest time value larger than to the second argument). It |
2460 | will usually be called just before the callback will be triggered, but |
2587 | will usually be called just before the callback will be triggered, but |
2461 | might be called at other times, too. |
2588 | might be called at other times, too. |
2462 | .Sp |
2589 | .Sp |
2463 | \&\s-1NOTE: \s0\fIThis callback must always return a time that is higher than or |
2590 | \&\s-1NOTE:\s0 \fIThis callback must always return a time that is higher than or |
2464 | equal to the passed \f(CI\*(C`now\*(C'\fI value\fR. |
2591 | equal to the passed \f(CI\*(C`now\*(C'\fI value\fR. |
2465 | .Sp |
2592 | .Sp |
2466 | This can be used to create very complex timers, such as a timer that |
2593 | This can be used to create very complex timers, such as a timer that |
2467 | triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate |
2594 | triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate |
2468 | the next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for |
2595 | the next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for |
… | |
… | |
2613 | The simplest way to ensure that the signal mask is reset in the child is |
2740 | The simplest way to ensure that the signal mask is reset in the child is |
2614 | to install a fork handler with \f(CW\*(C`pthread_atfork\*(C'\fR that resets it. That will |
2741 | to install a fork handler with \f(CW\*(C`pthread_atfork\*(C'\fR that resets it. That will |
2615 | catch fork calls done by libraries (such as the libc) as well. |
2742 | catch fork calls done by libraries (such as the libc) as well. |
2616 | .PP |
2743 | .PP |
2617 | In current versions of libev, the signal will not be blocked indefinitely |
2744 | In current versions of libev, the signal will not be blocked indefinitely |
2618 | unless you use the \f(CW\*(C`signalfd\*(C'\fR \s-1API \s0(\f(CW\*(C`EV_SIGNALFD\*(C'\fR). While this reduces |
2745 | unless you use the \f(CW\*(C`signalfd\*(C'\fR \s-1API\s0 (\f(CW\*(C`EV_SIGNALFD\*(C'\fR). While this reduces |
2619 | the window of opportunity for problems, it will not go away, as libev |
2746 | the window of opportunity for problems, it will not go away, as libev |
2620 | \&\fIhas\fR to modify the signal mask, at least temporarily. |
2747 | \&\fIhas\fR to modify the signal mask, at least temporarily. |
2621 | .PP |
2748 | .PP |
2622 | So I can't stress this enough: \fIIf you do not reset your signal mask when |
2749 | So I can't stress this enough: \fIIf you do not reset your signal mask when |
2623 | you expect it to be empty, you have a race condition in your code\fR. This |
2750 | you expect it to be empty, you have a race condition in your code\fR. This |
… | |
… | |
3891 | .PP |
4018 | .PP |
3892 | First, you need to associate some data with the event loop: |
4019 | First, you need to associate some data with the event loop: |
3893 | .PP |
4020 | .PP |
3894 | .Vb 6 |
4021 | .Vb 6 |
3895 | \& typedef struct { |
4022 | \& typedef struct { |
3896 | \& mutex_t lock; /* global loop lock */ |
4023 | \& pthread_mutex_t lock; /* global loop lock */ |
|
|
4024 | \& pthread_t tid; |
|
|
4025 | \& pthread_cond_t invoke_cv; |
3897 | \& ev_async async_w; |
4026 | \& ev_async async_w; |
3898 | \& thread_t tid; |
|
|
3899 | \& cond_t invoke_cv; |
|
|
3900 | \& } userdata; |
4027 | \& } userdata; |
3901 | \& |
4028 | \& |
3902 | \& void prepare_loop (EV_P) |
4029 | \& void prepare_loop (EV_P) |
3903 | \& { |
4030 | \& { |
3904 | \& // for simplicity, we use a static userdata struct. |
4031 | \& // for simplicity, we use a static userdata struct. |
3905 | \& static userdata u; |
4032 | \& static userdata u; |
3906 | \& |
4033 | \& |
3907 | \& ev_async_init (&u\->async_w, async_cb); |
4034 | \& ev_async_init (&u.async_w, async_cb); |
3908 | \& ev_async_start (EV_A_ &u\->async_w); |
4035 | \& ev_async_start (EV_A_ &u.async_w); |
3909 | \& |
4036 | \& |
3910 | \& pthread_mutex_init (&u\->lock, 0); |
4037 | \& pthread_mutex_init (&u.lock, 0); |
3911 | \& pthread_cond_init (&u\->invoke_cv, 0); |
4038 | \& pthread_cond_init (&u.invoke_cv, 0); |
3912 | \& |
4039 | \& |
3913 | \& // now associate this with the loop |
4040 | \& // now associate this with the loop |
3914 | \& ev_set_userdata (EV_A_ u); |
4041 | \& ev_set_userdata (EV_A_ &u); |
3915 | \& ev_set_invoke_pending_cb (EV_A_ l_invoke); |
4042 | \& ev_set_invoke_pending_cb (EV_A_ l_invoke); |
3916 | \& ev_set_loop_release_cb (EV_A_ l_release, l_acquire); |
4043 | \& ev_set_loop_release_cb (EV_A_ l_release, l_acquire); |
3917 | \& |
4044 | \& |
3918 | \& // then create the thread running ev_run |
4045 | \& // then create the thread running ev_run |
3919 | \& pthread_create (&u\->tid, 0, l_run, EV_A); |
4046 | \& pthread_create (&u.tid, 0, l_run, EV_A); |
3920 | \& } |
4047 | \& } |
3921 | .Ve |
4048 | .Ve |
3922 | .PP |
4049 | .PP |
3923 | The callback for the \f(CW\*(C`ev_async\*(C'\fR watcher does nothing: the watcher is used |
4050 | The callback for the \f(CW\*(C`ev_async\*(C'\fR watcher does nothing: the watcher is used |
3924 | solely to wake up the event loop so it takes notice of any new watchers |
4051 | solely to wake up the event loop so it takes notice of any new watchers |
… | |
… | |
4308 | gets automatically stopped and restarted when reconfiguring it with this |
4435 | gets automatically stopped and restarted when reconfiguring it with this |
4309 | method. |
4436 | method. |
4310 | .Sp |
4437 | .Sp |
4311 | For \f(CW\*(C`ev::embed\*(C'\fR watchers this method is called \f(CW\*(C`set_embed\*(C'\fR, to avoid |
4438 | For \f(CW\*(C`ev::embed\*(C'\fR watchers this method is called \f(CW\*(C`set_embed\*(C'\fR, to avoid |
4312 | clashing with the \f(CW\*(C`set (loop)\*(C'\fR method. |
4439 | clashing with the \f(CW\*(C`set (loop)\*(C'\fR method. |
|
|
4440 | .Sp |
|
|
4441 | For \f(CW\*(C`ev::io\*(C'\fR watchers there is an additional \f(CW\*(C`set\*(C'\fR method that acepts a |
|
|
4442 | new event mask only, and internally calls \f(CW\*(C`ev_io_modify\*(C'\fR. |
4313 | .IP "w\->start ()" 4 |
4443 | .IP "w\->start ()" 4 |
4314 | .IX Item "w->start ()" |
4444 | .IX Item "w->start ()" |
4315 | Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the |
4445 | Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the |
4316 | constructor already stores the event loop. |
4446 | constructor already stores the event loop. |
4317 | .IP "w\->start ([arguments])" 4 |
4447 | .IP "w\->start ([arguments])" 4 |
… | |
… | |
4518 | \& #include "ev.c" |
4648 | \& #include "ev.c" |
4519 | .Ve |
4649 | .Ve |
4520 | .PP |
4650 | .PP |
4521 | This will automatically include \fIev.h\fR, too, and should be done in a |
4651 | This will automatically include \fIev.h\fR, too, and should be done in a |
4522 | single C source file only to provide the function implementations. To use |
4652 | single C source file only to provide the function implementations. To use |
4523 | it, do the same for \fIev.h\fR in all files wishing to use this \s-1API \s0(best |
4653 | it, do the same for \fIev.h\fR in all files wishing to use this \s-1API\s0 (best |
4524 | done by writing a wrapper around \fIev.h\fR that you can include instead and |
4654 | done by writing a wrapper around \fIev.h\fR that you can include instead and |
4525 | where you can put other configuration options): |
4655 | where you can put other configuration options): |
4526 | .PP |
4656 | .PP |
4527 | .Vb 2 |
4657 | .Vb 2 |
4528 | \& #define EV_STANDALONE 1 |
4658 | \& #define EV_STANDALONE 1 |
… | |
… | |
4545 | \& ev_win32.c required on win32 platforms only |
4675 | \& ev_win32.c required on win32 platforms only |
4546 | \& |
4676 | \& |
4547 | \& ev_select.c only when select backend is enabled |
4677 | \& ev_select.c only when select backend is enabled |
4548 | \& ev_poll.c only when poll backend is enabled |
4678 | \& ev_poll.c only when poll backend is enabled |
4549 | \& ev_epoll.c only when the epoll backend is enabled |
4679 | \& ev_epoll.c only when the epoll backend is enabled |
|
|
4680 | \& ev_linuxaio.c only when the linux aio backend is enabled |
|
|
4681 | \& ev_iouring.c only when the linux io_uring backend is enabled |
4550 | \& ev_kqueue.c only when the kqueue backend is enabled |
4682 | \& ev_kqueue.c only when the kqueue backend is enabled |
4551 | \& ev_port.c only when the solaris port backend is enabled |
4683 | \& ev_port.c only when the solaris port backend is enabled |
4552 | .Ve |
4684 | .Ve |
4553 | .PP |
4685 | .PP |
4554 | \&\fIev.c\fR includes the backend files directly when enabled, so you only need |
4686 | \&\fIev.c\fR includes the backend files directly when enabled, so you only need |
… | |
… | |
4601 | values when compiling libev vs. including \fIev.h\fR, so it is permissible |
4733 | values when compiling libev vs. including \fIev.h\fR, so it is permissible |
4602 | to redefine them before including \fIev.h\fR without breaking compatibility |
4734 | to redefine them before including \fIev.h\fR without breaking compatibility |
4603 | to a compiled library. All other symbols change the \s-1ABI,\s0 which means all |
4735 | to a compiled library. All other symbols change the \s-1ABI,\s0 which means all |
4604 | users of libev and the libev code itself must be compiled with compatible |
4736 | users of libev and the libev code itself must be compiled with compatible |
4605 | settings. |
4737 | settings. |
4606 | .IP "\s-1EV_COMPAT3 \s0(h)" 4 |
4738 | .IP "\s-1EV_COMPAT3\s0 (h)" 4 |
4607 | .IX Item "EV_COMPAT3 (h)" |
4739 | .IX Item "EV_COMPAT3 (h)" |
4608 | Backwards compatibility is a major concern for libev. This is why this |
4740 | Backwards compatibility is a major concern for libev. This is why this |
4609 | release of libev comes with wrappers for the functions and symbols that |
4741 | release of libev comes with wrappers for the functions and symbols that |
4610 | have been renamed between libev version 3 and 4. |
4742 | have been renamed between libev version 3 and 4. |
4611 | .Sp |
4743 | .Sp |
… | |
… | |
4616 | typedef in that case. |
4748 | typedef in that case. |
4617 | .Sp |
4749 | .Sp |
4618 | In some future version, the default for \f(CW\*(C`EV_COMPAT3\*(C'\fR will become \f(CW0\fR, |
4750 | In some future version, the default for \f(CW\*(C`EV_COMPAT3\*(C'\fR will become \f(CW0\fR, |
4619 | and in some even more future version the compatibility code will be |
4751 | and in some even more future version the compatibility code will be |
4620 | removed completely. |
4752 | removed completely. |
4621 | .IP "\s-1EV_STANDALONE \s0(h)" 4 |
4753 | .IP "\s-1EV_STANDALONE\s0 (h)" 4 |
4622 | .IX Item "EV_STANDALONE (h)" |
4754 | .IX Item "EV_STANDALONE (h)" |
4623 | Must always be \f(CW1\fR if you do not use autoconf configuration, which |
4755 | Must always be \f(CW1\fR if you do not use autoconf configuration, which |
4624 | keeps libev from including \fIconfig.h\fR, and it also defines dummy |
4756 | keeps libev from including \fIconfig.h\fR, and it also defines dummy |
4625 | implementations for some libevent functions (such as logging, which is not |
4757 | implementations for some libevent functions (such as logging, which is not |
4626 | supported). It will also not define any of the structs usually found in |
4758 | supported). It will also not define any of the structs usually found in |
… | |
… | |
4667 | higher, as it simplifies linking (no need for \f(CW\*(C`\-lrt\*(C'\fR). |
4799 | higher, as it simplifies linking (no need for \f(CW\*(C`\-lrt\*(C'\fR). |
4668 | .IP "\s-1EV_USE_NANOSLEEP\s0" 4 |
4800 | .IP "\s-1EV_USE_NANOSLEEP\s0" 4 |
4669 | .IX Item "EV_USE_NANOSLEEP" |
4801 | .IX Item "EV_USE_NANOSLEEP" |
4670 | If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available |
4802 | If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available |
4671 | and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR. |
4803 | and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR. |
|
|
4804 | .IP "\s-1EV_USE_EVENTFD\s0" 4 |
|
|
4805 | .IX Item "EV_USE_EVENTFD" |
|
|
4806 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is |
|
|
4807 | available and will probe for kernel support at runtime. This will improve |
|
|
4808 | \&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption. |
|
|
4809 | If undefined, it will be enabled if the headers indicate GNU/Linux + Glibc |
|
|
4810 | 2.7 or newer, otherwise disabled. |
|
|
4811 | .IP "\s-1EV_USE_SIGNALFD\s0" 4 |
|
|
4812 | .IX Item "EV_USE_SIGNALFD" |
|
|
4813 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`signalfd ()\*(C'\fR is |
|
|
4814 | available and will probe for kernel support at runtime. This enables |
|
|
4815 | the use of \s-1EVFLAG_SIGNALFD\s0 for faster and simpler signal handling. If |
|
|
4816 | undefined, it will be enabled if the headers indicate GNU/Linux + Glibc |
|
|
4817 | 2.7 or newer, otherwise disabled. |
|
|
4818 | .IP "\s-1EV_USE_TIMERFD\s0" 4 |
|
|
4819 | .IX Item "EV_USE_TIMERFD" |
|
|
4820 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`timerfd ()\*(C'\fR is |
|
|
4821 | available and will probe for kernel support at runtime. This allows |
|
|
4822 | libev to detect time jumps accurately. If undefined, it will be enabled |
|
|
4823 | if the headers indicate GNU/Linux + Glibc 2.8 or newer and define |
|
|
4824 | \&\f(CW\*(C`TFD_TIMER_CANCEL_ON_SET\*(C'\fR, otherwise disabled. |
4672 | .IP "\s-1EV_USE_EVENTFD\s0" 4 |
4825 | .IP "\s-1EV_USE_EVENTFD\s0" 4 |
4673 | .IX Item "EV_USE_EVENTFD" |
4826 | .IX Item "EV_USE_EVENTFD" |
4674 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is |
4827 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is |
4675 | available and will probe for kernel support at runtime. This will improve |
4828 | available and will probe for kernel support at runtime. This will improve |
4676 | \&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption. |
4829 | \&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption. |
… | |
… | |
4735 | If defined to be \f(CW1\fR, libev will compile in support for the Linux |
4888 | If defined to be \f(CW1\fR, libev will compile in support for the Linux |
4736 | \&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime, |
4889 | \&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime, |
4737 | otherwise another method will be used as fallback. This is the preferred |
4890 | otherwise another method will be used as fallback. This is the preferred |
4738 | backend for GNU/Linux systems. If undefined, it will be enabled if the |
4891 | backend for GNU/Linux systems. If undefined, it will be enabled if the |
4739 | headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. |
4892 | headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. |
|
|
4893 | .IP "\s-1EV_USE_LINUXAIO\s0" 4 |
|
|
4894 | .IX Item "EV_USE_LINUXAIO" |
|
|
4895 | If defined to be \f(CW1\fR, libev will compile in support for the Linux aio |
|
|
4896 | backend (\f(CW\*(C`EV_USE_EPOLL\*(C'\fR must also be enabled). If undefined, it will be |
|
|
4897 | enabled on linux, otherwise disabled. |
|
|
4898 | .IP "\s-1EV_USE_IOURING\s0" 4 |
|
|
4899 | .IX Item "EV_USE_IOURING" |
|
|
4900 | If defined to be \f(CW1\fR, libev will compile in support for the Linux |
|
|
4901 | io_uring backend (\f(CW\*(C`EV_USE_EPOLL\*(C'\fR must also be enabled). Due to it's |
|
|
4902 | current limitations it has to be requested explicitly. If undefined, it |
|
|
4903 | will be enabled on linux, otherwise disabled. |
4740 | .IP "\s-1EV_USE_KQUEUE\s0" 4 |
4904 | .IP "\s-1EV_USE_KQUEUE\s0" 4 |
4741 | .IX Item "EV_USE_KQUEUE" |
4905 | .IX Item "EV_USE_KQUEUE" |
4742 | If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style |
4906 | If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style |
4743 | \&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime, |
4907 | \&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime, |
4744 | otherwise another method will be used as fallback. This is the preferred |
4908 | otherwise another method will be used as fallback. This is the preferred |
… | |
… | |
4784 | handler \*(L"locking\*(R" as well as for signal and thread safety in \f(CW\*(C`ev_async\*(C'\fR |
4948 | handler \*(L"locking\*(R" as well as for signal and thread safety in \f(CW\*(C`ev_async\*(C'\fR |
4785 | watchers. |
4949 | watchers. |
4786 | .Sp |
4950 | .Sp |
4787 | In the absence of this define, libev will use \f(CW\*(C`sig_atomic_t volatile\*(C'\fR |
4951 | In the absence of this define, libev will use \f(CW\*(C`sig_atomic_t volatile\*(C'\fR |
4788 | (from \fIsignal.h\fR), which is usually good enough on most platforms. |
4952 | (from \fIsignal.h\fR), which is usually good enough on most platforms. |
4789 | .IP "\s-1EV_H \s0(h)" 4 |
4953 | .IP "\s-1EV_H\s0 (h)" 4 |
4790 | .IX Item "EV_H (h)" |
4954 | .IX Item "EV_H (h)" |
4791 | The name of the \fIev.h\fR header file used to include it. The default if |
4955 | The name of the \fIev.h\fR header file used to include it. The default if |
4792 | undefined is \f(CW"ev.h"\fR in \fIevent.h\fR, \fIev.c\fR and \fIev++.h\fR. This can be |
4956 | undefined is \f(CW"ev.h"\fR in \fIevent.h\fR, \fIev.c\fR and \fIev++.h\fR. This can be |
4793 | used to virtually rename the \fIev.h\fR header file in case of conflicts. |
4957 | used to virtually rename the \fIev.h\fR header file in case of conflicts. |
4794 | .IP "\s-1EV_CONFIG_H \s0(h)" 4 |
4958 | .IP "\s-1EV_CONFIG_H\s0 (h)" 4 |
4795 | .IX Item "EV_CONFIG_H (h)" |
4959 | .IX Item "EV_CONFIG_H (h)" |
4796 | If \f(CW\*(C`EV_STANDALONE\*(C'\fR isn't \f(CW1\fR, this variable can be used to override |
4960 | If \f(CW\*(C`EV_STANDALONE\*(C'\fR isn't \f(CW1\fR, this variable can be used to override |
4797 | \&\fIev.c\fR's idea of where to find the \fIconfig.h\fR file, similarly to |
4961 | \&\fIev.c\fR's idea of where to find the \fIconfig.h\fR file, similarly to |
4798 | \&\f(CW\*(C`EV_H\*(C'\fR, above. |
4962 | \&\f(CW\*(C`EV_H\*(C'\fR, above. |
4799 | .IP "\s-1EV_EVENT_H \s0(h)" 4 |
4963 | .IP "\s-1EV_EVENT_H\s0 (h)" 4 |
4800 | .IX Item "EV_EVENT_H (h)" |
4964 | .IX Item "EV_EVENT_H (h)" |
4801 | Similarly to \f(CW\*(C`EV_H\*(C'\fR, this macro can be used to override \fIevent.c\fR's idea |
4965 | Similarly to \f(CW\*(C`EV_H\*(C'\fR, this macro can be used to override \fIevent.c\fR's idea |
4802 | of how the \fIevent.h\fR header can be found, the default is \f(CW"event.h"\fR. |
4966 | of how the \fIevent.h\fR header can be found, the default is \f(CW"event.h"\fR. |
4803 | .IP "\s-1EV_PROTOTYPES \s0(h)" 4 |
4967 | .IP "\s-1EV_PROTOTYPES\s0 (h)" 4 |
4804 | .IX Item "EV_PROTOTYPES (h)" |
4968 | .IX Item "EV_PROTOTYPES (h)" |
4805 | If defined to be \f(CW0\fR, then \fIev.h\fR will not define any function |
4969 | If defined to be \f(CW0\fR, then \fIev.h\fR will not define any function |
4806 | prototypes, but still define all the structs and other symbols. This is |
4970 | prototypes, but still define all the structs and other symbols. This is |
4807 | occasionally useful if you want to provide your own wrapper functions |
4971 | occasionally useful if you want to provide your own wrapper functions |
4808 | around libev functions. |
4972 | around libev functions. |
… | |
… | |
5001 | called. If set to \f(CW2\fR, then the internal verification code will be |
5165 | called. If set to \f(CW2\fR, then the internal verification code will be |
5002 | called once per loop, which can slow down libev. If set to \f(CW3\fR, then the |
5166 | called once per loop, which can slow down libev. If set to \f(CW3\fR, then the |
5003 | verification code will be called very frequently, which will slow down |
5167 | verification code will be called very frequently, which will slow down |
5004 | libev considerably. |
5168 | libev considerably. |
5005 | .Sp |
5169 | .Sp |
|
|
5170 | Verification errors are reported via C's \f(CW\*(C`assert\*(C'\fR mechanism, so if you |
|
|
5171 | disable that (e.g. by defining \f(CW\*(C`NDEBUG\*(C'\fR) then no errors will be reported. |
|
|
5172 | .Sp |
5006 | The default is \f(CW1\fR, unless \f(CW\*(C`EV_FEATURES\*(C'\fR overrides it, in which case it |
5173 | The default is \f(CW1\fR, unless \f(CW\*(C`EV_FEATURES\*(C'\fR overrides it, in which case it |
5007 | will be \f(CW0\fR. |
5174 | will be \f(CW0\fR. |
5008 | .IP "\s-1EV_COMMON\s0" 4 |
5175 | .IP "\s-1EV_COMMON\s0" 4 |
5009 | .IX Item "EV_COMMON" |
5176 | .IX Item "EV_COMMON" |
5010 | By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining |
5177 | By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining |
… | |
… | |
5017 | .Vb 3 |
5184 | .Vb 3 |
5018 | \& #define EV_COMMON \e |
5185 | \& #define EV_COMMON \e |
5019 | \& SV *self; /* contains this struct */ \e |
5186 | \& SV *self; /* contains this struct */ \e |
5020 | \& SV *cb_sv, *fh /* note no trailing ";" */ |
5187 | \& SV *cb_sv, *fh /* note no trailing ";" */ |
5021 | .Ve |
5188 | .Ve |
5022 | .IP "\s-1EV_CB_DECLARE \s0(type)" 4 |
5189 | .IP "\s-1EV_CB_DECLARE\s0 (type)" 4 |
5023 | .IX Item "EV_CB_DECLARE (type)" |
5190 | .IX Item "EV_CB_DECLARE (type)" |
5024 | .PD 0 |
5191 | .PD 0 |
5025 | .IP "\s-1EV_CB_INVOKE \s0(watcher, revents)" 4 |
5192 | .IP "\s-1EV_CB_INVOKE\s0 (watcher, revents)" 4 |
5026 | .IX Item "EV_CB_INVOKE (watcher, revents)" |
5193 | .IX Item "EV_CB_INVOKE (watcher, revents)" |
5027 | .IP "ev_set_cb (ev, cb)" 4 |
5194 | .IP "ev_set_cb (ev, cb)" 4 |
5028 | .IX Item "ev_set_cb (ev, cb)" |
5195 | .IX Item "ev_set_cb (ev, cb)" |
5029 | .PD |
5196 | .PD |
5030 | Can be used to change the callback member declaration in each watcher, |
5197 | Can be used to change the callback member declaration in each watcher, |
… | |
… | |
5033 | their default definitions. One possible use for overriding these is to |
5200 | their default definitions. One possible use for overriding these is to |
5034 | avoid the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument in all cases, or to use |
5201 | avoid the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument in all cases, or to use |
5035 | method calls instead of plain function calls in \*(C+. |
5202 | method calls instead of plain function calls in \*(C+. |
5036 | .SS "\s-1EXPORTED API SYMBOLS\s0" |
5203 | .SS "\s-1EXPORTED API SYMBOLS\s0" |
5037 | .IX Subsection "EXPORTED API SYMBOLS" |
5204 | .IX Subsection "EXPORTED API SYMBOLS" |
5038 | If you need to re-export the \s-1API \s0(e.g. via a \s-1DLL\s0) and you need a list of |
5205 | If you need to re-export the \s-1API\s0 (e.g. via a \s-1DLL\s0) and you need a list of |
5039 | exported symbols, you can use the provided \fISymbol.*\fR files which list |
5206 | exported symbols, you can use the provided \fISymbol.*\fR files which list |
5040 | all public symbols, one per line: |
5207 | all public symbols, one per line: |
5041 | .PP |
5208 | .PP |
5042 | .Vb 2 |
5209 | .Vb 2 |
5043 | \& Symbols.ev for libev proper |
5210 | \& Symbols.ev for libev proper |
… | |
… | |
5275 | .PP |
5442 | .PP |
5276 | \fI\f(CI\*(C`select\*(C'\fI is buggy\fR |
5443 | \fI\f(CI\*(C`select\*(C'\fI is buggy\fR |
5277 | .IX Subsection "select is buggy" |
5444 | .IX Subsection "select is buggy" |
5278 | .PP |
5445 | .PP |
5279 | All that's left is \f(CW\*(C`select\*(C'\fR, and of course Apple found a way to fuck this |
5446 | All that's left is \f(CW\*(C`select\*(C'\fR, and of course Apple found a way to fuck this |
5280 | one up as well: On \s-1OS/X, \s0\f(CW\*(C`select\*(C'\fR actively limits the number of file |
5447 | one up as well: On \s-1OS/X,\s0 \f(CW\*(C`select\*(C'\fR actively limits the number of file |
5281 | descriptors you can pass in to 1024 \- your program suddenly crashes when |
5448 | descriptors you can pass in to 1024 \- your program suddenly crashes when |
5282 | you use more. |
5449 | you use more. |
5283 | .PP |
5450 | .PP |
5284 | There is an undocumented \*(L"workaround\*(R" for this \- defining |
5451 | There is an undocumented \*(L"workaround\*(R" for this \- defining |
5285 | \&\f(CW\*(C`_DARWIN_UNLIMITED_SELECT\*(C'\fR, which libev tries to use, so select \fIshould\fR |
5452 | \&\f(CW\*(C`_DARWIN_UNLIMITED_SELECT\*(C'\fR, which libev tries to use, so select \fIshould\fR |