1 | .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.30) |
1 | .\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) |
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 "2016-02-18" "libev-4.22" "libev - high performance full featured event loop" |
136 | .TH LIBEV 3 "2020-07-12" "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) |
… | |
… | |
536 | make libev check for a fork in each iteration by enabling this flag. |
562 | make libev check for a fork in each iteration by enabling this flag. |
537 | .Sp |
563 | .Sp |
538 | This works by calling \f(CW\*(C`getpid ()\*(C'\fR on every iteration of the loop, |
564 | This works by calling \f(CW\*(C`getpid ()\*(C'\fR on every iteration of the loop, |
539 | and thus this might slow down your event loop if you do a lot of loop |
565 | and thus this might slow down your event loop if you do a lot of loop |
540 | iterations and little real work, but is usually not noticeable (on my |
566 | iterations and little real work, but is usually not noticeable (on my |
541 | GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn sequence |
567 | GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn |
542 | without a system call and thus \fIvery\fR fast, but my GNU/Linux system also has |
568 | sequence without a system call and thus \fIvery\fR fast, but my GNU/Linux |
543 | \&\f(CW\*(C`pthread_atfork\*(C'\fR which is even faster). |
569 | system also has \f(CW\*(C`pthread_atfork\*(C'\fR which is even faster). (Update: glibc |
|
|
570 | versions 2.25 apparently removed the \f(CW\*(C`getpid\*(C'\fR optimisation again). |
544 | .Sp |
571 | .Sp |
545 | The big advantage of this flag is that you can forget about fork (and |
572 | The big advantage of this flag is that you can forget about fork (and |
546 | forget about forgetting to tell libev about forking, although you still |
573 | forget about forgetting to tell libev about forking, although you still |
547 | have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR) when you use this flag. |
574 | have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR) when you use this flag. |
548 | .Sp |
575 | .Sp |
… | |
… | |
579 | 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 |
580 | unblocking the signals. |
607 | unblocking the signals. |
581 | .Sp |
608 | .Sp |
582 | 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 |
583 | \&\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. |
584 | .Sp |
618 | .Sp |
585 | 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. |
586 | .ie n .IP """EVBACKEND_SELECT"" (value 1, portable select backend)" 4 |
622 | .ie n .IP """EVBACKEND_SELECT"" (value 1, portable select backend)" 4 |
587 | .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 |
588 | .IX Item "EVBACKEND_SELECT (value 1, portable select backend)" |
624 | .IX Item "EVBACKEND_SELECT (value 1, portable select backend)" |
589 | 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 |
590 | 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, |
591 | 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 |
592 | 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 |
593 | 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. |
594 | .Sp |
630 | .Sp |
… | |
… | |
603 | \&\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 |
604 | \&\f(CW\*(C`exceptfds\*(C'\fR set on that platform). |
640 | \&\f(CW\*(C`exceptfds\*(C'\fR set on that platform). |
605 | .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 |
606 | .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 |
607 | .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)" |
608 | 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 |
609 | than select, but handles sparse fds better and has no artificial |
645 | than select, but handles sparse fds better and has no artificial |
610 | 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 |
611 | 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, |
612 | 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 |
613 | performance tips. |
649 | performance tips. |
… | |
… | |
615 | 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 |
616 | \&\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. |
617 | .ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4 |
653 | .ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4 |
618 | .el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4 |
654 | .el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4 |
619 | .IX Item "EVBACKEND_EPOLL (value 4, Linux)" |
655 | .IX Item "EVBACKEND_EPOLL (value 4, Linux)" |
620 | 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 |
621 | kernels). |
657 | kernels). |
622 | .Sp |
658 | .Sp |
623 | 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 |
624 | it scales phenomenally better. While poll and select usually scale like |
660 | it scales phenomenally better. While poll and select usually scale like |
625 | 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 |
… | |
… | |
671 | 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 |
672 | 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 |
673 | the usage. So sad. |
709 | the usage. So sad. |
674 | .Sp |
710 | .Sp |
675 | 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 |
676 | 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. |
677 | .Sp |
756 | .Sp |
678 | 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 |
679 | \&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
758 | \&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
680 | .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 |
681 | .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 |
682 | .IX Item "EVBACKEND_KQUEUE (value 8, most BSD clones)" |
761 | .IX Item "EVBACKEND_KQUEUE (value 8, most BSD clones)" |
683 | Kqueue deserves special mention, as at the time of this writing, it |
762 | Kqueue deserves special mention, as at the time this backend was |
684 | 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 |
685 | with anything but sockets and pipes, except on Darwin, where of course |
764 | work reliably with anything but sockets and pipes, except on Darwin, |
686 | it's completely useless). Unlike epoll, however, whose brokenness |
765 | where of course it's completely useless). Unlike epoll, however, whose |
687 | 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) |
688 | 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 |
689 | \&\*(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 |
690 | \&\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 |
691 | system like NetBSD. |
770 | known-to-be-good (\-enough) system like NetBSD. |
692 | .Sp |
771 | .Sp |
693 | 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 |
694 | 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 |
695 | 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. |
696 | .Sp |
775 | .Sp |
697 | 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 |
698 | 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 |
699 | 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 |
700 | 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 |
701 | 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 |
702 | 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 |
703 | drops fds silently in similarly hard-to-detect cases. |
782 | drops fds silently in similarly hard-to-detect cases. |
704 | .Sp |
783 | .Sp |
705 | This backend usually performs well under most conditions. |
784 | This backend usually performs well under most conditions. |
706 | .Sp |
785 | .Sp |
707 | While nominally embeddable in other event loops, this doesn't work |
786 | While nominally embeddable in other event loops, this doesn't work |
… | |
… | |
784 | 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 |
785 | used if available. |
864 | used if available. |
786 | .Sp |
865 | .Sp |
787 | .Vb 1 |
866 | .Vb 1 |
788 | \& 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); |
789 | .Ve |
876 | .Ve |
790 | .RE |
877 | .RE |
791 | .IP "ev_loop_destroy (loop)" 4 |
878 | .IP "ev_loop_destroy (loop)" 4 |
792 | .IX Item "ev_loop_destroy (loop)" |
879 | .IX Item "ev_loop_destroy (loop)" |
793 | Destroys an event loop object (frees all memory and kernel state |
880 | Destroys an event loop object (frees all memory and kernel state |
… | |
… | |
1262 | 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 |
1263 | *)\*(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 |
1264 | 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. |
1265 | .PP |
1352 | .PP |
1266 | 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 |
1267 | 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 |
1268 | 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. |
1269 | .PP |
1357 | .PP |
1270 | 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 |
1271 | 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 |
1272 | third argument. |
1360 | third argument. |
1273 | .PP |
1361 | .PP |
… | |
… | |
1364 | bug in your program. |
1452 | bug in your program. |
1365 | .Sp |
1453 | .Sp |
1366 | 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 |
1367 | 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 |
1368 | 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 |
1369 | 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 |
1370 | 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 |
1371 | thing, so beware. |
1459 | thing, so beware. |
1372 | .SS "\s-1GENERIC WATCHER FUNCTIONS\s0" |
1460 | .SS "\s-1GENERIC WATCHER FUNCTIONS\s0" |
1373 | .IX Subsection "GENERIC WATCHER FUNCTIONS" |
1461 | .IX Subsection "GENERIC WATCHER FUNCTIONS" |
1374 | .ie n .IP """ev_init"" (ev_TYPE *watcher, callback)" 4 |
1462 | .ie n .IP """ev_init"" (ev_TYPE *watcher, callback)" 4 |
… | |
… | |
1444 | 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. |
1445 | .IP "bool ev_is_active (ev_TYPE *watcher)" 4 |
1533 | .IP "bool ev_is_active (ev_TYPE *watcher)" 4 |
1446 | .IX Item "bool ev_is_active (ev_TYPE *watcher)" |
1534 | .IX Item "bool ev_is_active (ev_TYPE *watcher)" |
1447 | 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 |
1448 | 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 |
1449 | it. |
1537 | it unless documented otherwise. |
1450 | .IP "bool ev_is_pending (ev_TYPE *watcher)" 4 |
1538 | .IP "bool ev_is_pending (ev_TYPE *watcher)" 4 |
1451 | .IX Item "bool ev_is_pending (ev_TYPE *watcher)" |
1539 | .IX Item "bool ev_is_pending (ev_TYPE *watcher)" |
1452 | Returns a true value iff the watcher is pending, (i.e. it has outstanding |
1540 | Returns a true value iff the watcher is pending, (i.e. it has outstanding |
1453 | events but its callback has not yet been invoked). As long as a watcher |
1541 | events but its callback has not yet been invoked). As long as a watcher |
1454 | is pending (but not active) you must not call an init function on it (but |
1542 | is pending (but not active) you must not call an init function on it (but |
… | |
… | |
1576 | .IX Subsection "WATCHER PRIORITY MODELS" |
1664 | .IX Subsection "WATCHER PRIORITY MODELS" |
1577 | Many event loops support \fIwatcher priorities\fR, which are usually small |
1665 | Many event loops support \fIwatcher priorities\fR, which are usually small |
1578 | integers that influence the ordering of event callback invocation |
1666 | integers that influence the ordering of event callback invocation |
1579 | between watchers in some way, all else being equal. |
1667 | between watchers in some way, all else being equal. |
1580 | .PP |
1668 | .PP |
1581 | In libev, Watcher priorities can be set using \f(CW\*(C`ev_set_priority\*(C'\fR. See its |
1669 | In libev, watcher priorities can be set using \f(CW\*(C`ev_set_priority\*(C'\fR. See its |
1582 | description for the more technical details such as the actual priority |
1670 | description for the more technical details such as the actual priority |
1583 | range. |
1671 | range. |
1584 | .PP |
1672 | .PP |
1585 | There are two common ways how these these priorities are being interpreted |
1673 | There are two common ways how these these priorities are being interpreted |
1586 | by event loops: |
1674 | by event loops: |
… | |
… | |
1680 | .IX Header "WATCHER TYPES" |
1768 | .IX Header "WATCHER TYPES" |
1681 | This section describes each watcher in detail, but will not repeat |
1769 | This section describes each watcher in detail, but will not repeat |
1682 | information given in the last section. Any initialisation/set macros, |
1770 | information given in the last section. Any initialisation/set macros, |
1683 | functions and members specific to the watcher type are explained. |
1771 | functions and members specific to the watcher type are explained. |
1684 | .PP |
1772 | .PP |
1685 | Members are additionally marked with either \fI[read\-only]\fR, meaning that, |
1773 | Most members are additionally marked with either \fI[read\-only]\fR, meaning |
1686 | while the watcher is active, you can look at the member and expect some |
1774 | that, while the watcher is active, you can look at the member and expect |
1687 | sensible content, but you must not modify it (you can modify it while the |
1775 | some sensible content, but you must not modify it (you can modify it while |
1688 | watcher is stopped to your hearts content), or \fI[read\-write]\fR, which |
1776 | the watcher is stopped to your hearts content), or \fI[read\-write]\fR, which |
1689 | means you can expect it to have some sensible content while the watcher |
1777 | means you can expect it to have some sensible content while the watcher is |
1690 | is active, but you can also modify it. Modifying it may not do something |
1778 | active, but you can also modify it (within the same thread as the event |
|
|
1779 | loop, i.e. without creating data races). Modifying it may not do something |
1691 | sensible or take immediate effect (or do anything at all), but libev will |
1780 | sensible or take immediate effect (or do anything at all), but libev will |
1692 | not crash or malfunction in any way. |
1781 | not crash or malfunction in any way. |
|
|
1782 | .PP |
|
|
1783 | In any case, the documentation for each member will explain what the |
|
|
1784 | effects are, and if there are any additional access restrictions. |
1693 | .ie n .SS """ev_io"" \- is this file descriptor readable or writable?" |
1785 | .ie n .SS """ev_io"" \- is this file descriptor readable or writable?" |
1694 | .el .SS "\f(CWev_io\fP \- is this file descriptor readable or writable?" |
1786 | .el .SS "\f(CWev_io\fP \- is this file descriptor readable or writable?" |
1695 | .IX Subsection "ev_io - is this file descriptor readable or writable?" |
1787 | .IX Subsection "ev_io - is this file descriptor readable or writable?" |
1696 | I/O watchers check whether a file descriptor is readable or writable |
1788 | I/O watchers check whether a file descriptor is readable or writable |
1697 | in each iteration of the event loop, or, more precisely, when reading |
1789 | in each iteration of the event loop, or, more precisely, when reading |
… | |
… | |
1725 | But really, best use non-blocking mode. |
1817 | But really, best use non-blocking mode. |
1726 | .PP |
1818 | .PP |
1727 | \fIThe special problem of disappearing file descriptors\fR |
1819 | \fIThe special problem of disappearing file descriptors\fR |
1728 | .IX Subsection "The special problem of disappearing file descriptors" |
1820 | .IX Subsection "The special problem of disappearing file descriptors" |
1729 | .PP |
1821 | .PP |
1730 | Some backends (e.g. kqueue, epoll) need to be told about closing a file |
1822 | Some backends (e.g. kqueue, epoll, linuxaio) need to be told about closing |
1731 | descriptor (either due to calling \f(CW\*(C`close\*(C'\fR explicitly or any other means, |
1823 | a file descriptor (either due to calling \f(CW\*(C`close\*(C'\fR explicitly or any other |
1732 | such as \f(CW\*(C`dup2\*(C'\fR). The reason is that you register interest in some file |
1824 | means, such as \f(CW\*(C`dup2\*(C'\fR). The reason is that you register interest in some |
1733 | descriptor, but when it goes away, the operating system will silently drop |
1825 | file descriptor, but when it goes away, the operating system will silently |
1734 | this interest. If another file descriptor with the same number then is |
1826 | drop this interest. If another file descriptor with the same number then |
1735 | registered with libev, there is no efficient way to see that this is, in |
1827 | is registered with libev, there is no efficient way to see that this is, |
1736 | fact, a different file descriptor. |
1828 | in fact, a different file descriptor. |
1737 | .PP |
1829 | .PP |
1738 | To avoid having to explicitly tell libev about such cases, libev follows |
1830 | To avoid having to explicitly tell libev about such cases, libev follows |
1739 | the following policy: Each time \f(CW\*(C`ev_io_set\*(C'\fR is being called, libev |
1831 | the following policy: Each time \f(CW\*(C`ev_io_set\*(C'\fR is being called, libev |
1740 | will assume that this is potentially a new file descriptor, otherwise |
1832 | will assume that this is potentially a new file descriptor, otherwise |
1741 | it is assumed that the file descriptor stays the same. That means that |
1833 | it is assumed that the file descriptor stays the same. That means that |
… | |
… | |
1793 | reuse the same code path. |
1885 | reuse the same code path. |
1794 | .PP |
1886 | .PP |
1795 | \fIThe special problem of fork\fR |
1887 | \fIThe special problem of fork\fR |
1796 | .IX Subsection "The special problem of fork" |
1888 | .IX Subsection "The special problem of fork" |
1797 | .PP |
1889 | .PP |
1798 | Some backends (epoll, kqueue) do not support \f(CW\*(C`fork ()\*(C'\fR at all or exhibit |
1890 | Some backends (epoll, kqueue, linuxaio, iouring) do not support \f(CW\*(C`fork ()\*(C'\fR |
1799 | useless behaviour. Libev fully supports fork, but needs to be told about |
1891 | at all or exhibit useless behaviour. Libev fully supports fork, but needs |
1800 | it in the child if you want to continue to use it in the child. |
1892 | to be told about it in the child if you want to continue to use it in the |
|
|
1893 | child. |
1801 | .PP |
1894 | .PP |
1802 | To support fork in your child processes, you have to call \f(CW\*(C`ev_loop_fork |
1895 | To support fork in your child processes, you have to call \f(CW\*(C`ev_loop_fork |
1803 | ()\*(C'\fR after a fork in the child, enable \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR, or resort to |
1896 | ()\*(C'\fR after a fork in the child, enable \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR, or resort to |
1804 | \&\f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
1897 | \&\f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
1805 | .PP |
1898 | .PP |
… | |
… | |
1810 | when writing to a pipe whose other end has been closed, your program gets |
1903 | when writing to a pipe whose other end has been closed, your program gets |
1811 | sent a \s-1SIGPIPE,\s0 which, by default, aborts your program. For most programs |
1904 | sent a \s-1SIGPIPE,\s0 which, by default, aborts your program. For most programs |
1812 | this is sensible behaviour, for daemons, this is usually undesirable. |
1905 | this is sensible behaviour, for daemons, this is usually undesirable. |
1813 | .PP |
1906 | .PP |
1814 | So when you encounter spurious, unexplained daemon exits, make sure you |
1907 | So when you encounter spurious, unexplained daemon exits, make sure you |
1815 | ignore \s-1SIGPIPE \s0(and maybe make sure you log the exit status of your daemon |
1908 | ignore \s-1SIGPIPE\s0 (and maybe make sure you log the exit status of your daemon |
1816 | somewhere, as that would have given you a big clue). |
1909 | somewhere, as that would have given you a big clue). |
1817 | .PP |
1910 | .PP |
1818 | \fIThe special problem of \fIaccept()\fIing when you can't\fR |
1911 | \fIThe special problem of \f(BIaccept()\fIing when you can't\fR |
1819 | .IX Subsection "The special problem of accept()ing when you can't" |
1912 | .IX Subsection "The special problem of accept()ing when you can't" |
1820 | .PP |
1913 | .PP |
1821 | Many implementations of the \s-1POSIX \s0\f(CW\*(C`accept\*(C'\fR function (for example, |
1914 | Many implementations of the \s-1POSIX\s0 \f(CW\*(C`accept\*(C'\fR function (for example, |
1822 | found in post\-2004 Linux) have the peculiar behaviour of not removing a |
1915 | found in post\-2004 Linux) have the peculiar behaviour of not removing a |
1823 | connection from the pending queue in all error cases. |
1916 | connection from the pending queue in all error cases. |
1824 | .PP |
1917 | .PP |
1825 | For example, larger servers often run out of file descriptors (because |
1918 | For example, larger servers often run out of file descriptors (because |
1826 | of resource limits), causing \f(CW\*(C`accept\*(C'\fR to fail with \f(CW\*(C`ENFILE\*(C'\fR but not |
1919 | of resource limits), causing \f(CW\*(C`accept\*(C'\fR to fail with \f(CW\*(C`ENFILE\*(C'\fR but not |
… | |
… | |
1862 | .PD 0 |
1955 | .PD 0 |
1863 | .IP "ev_io_set (ev_io *, int fd, int events)" 4 |
1956 | .IP "ev_io_set (ev_io *, int fd, int events)" 4 |
1864 | .IX Item "ev_io_set (ev_io *, int fd, int events)" |
1957 | .IX Item "ev_io_set (ev_io *, int fd, int events)" |
1865 | .PD |
1958 | .PD |
1866 | Configures an \f(CW\*(C`ev_io\*(C'\fR watcher. The \f(CW\*(C`fd\*(C'\fR is the file descriptor to |
1959 | Configures an \f(CW\*(C`ev_io\*(C'\fR watcher. The \f(CW\*(C`fd\*(C'\fR is the file descriptor to |
1867 | 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 |
1960 | 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 |
1868 | \&\f(CW\*(C`EV_READ | EV_WRITE\*(C'\fR, to express the desire to receive the given events. |
1961 | \&\f(CW\*(C`EV_READ | EV_WRITE\*(C'\fR or \f(CW0\fR, to express the desire to receive the given |
|
|
1962 | events. |
|
|
1963 | .Sp |
|
|
1964 | Note that setting the \f(CW\*(C`events\*(C'\fR to \f(CW0\fR and starting the watcher is |
|
|
1965 | supported, but not specially optimized \- if your program sometimes happens |
|
|
1966 | to generate this combination this is fine, but if it is easy to avoid |
|
|
1967 | starting an io watcher watching for no events you should do so. |
|
|
1968 | .IP "ev_io_modify (ev_io *, int events)" 4 |
|
|
1969 | .IX Item "ev_io_modify (ev_io *, int events)" |
|
|
1970 | Similar to \f(CW\*(C`ev_io_set\*(C'\fR, but only changes the requested events. Using this |
|
|
1971 | might be faster with some backends, as libev can assume that the \f(CW\*(C`fd\*(C'\fR |
|
|
1972 | still refers to the same underlying file description, something it cannot |
|
|
1973 | do when using \f(CW\*(C`ev_io_set\*(C'\fR. |
1869 | .IP "int fd [read\-only]" 4 |
1974 | .IP "int fd [no\-modify]" 4 |
1870 | .IX Item "int fd [read-only]" |
1975 | .IX Item "int fd [no-modify]" |
1871 | The file descriptor being watched. |
1976 | The file descriptor being watched. While it can be read at any time, you |
|
|
1977 | must not modify this member even when the watcher is stopped \- always use |
|
|
1978 | \&\f(CW\*(C`ev_io_set\*(C'\fR for that. |
1872 | .IP "int events [read\-only]" 4 |
1979 | .IP "int events [no\-modify]" 4 |
1873 | .IX Item "int events [read-only]" |
1980 | .IX Item "int events [no-modify]" |
1874 | The events being watched. |
1981 | The set of events the fd is being watched for, among other flags. Remember |
|
|
1982 | that this is a bit set \- to test for \f(CW\*(C`EV_READ\*(C'\fR, use \f(CW\*(C`w\->events & |
|
|
1983 | EV_READ\*(C'\fR, and similarly for \f(CW\*(C`EV_WRITE\*(C'\fR. |
|
|
1984 | .Sp |
|
|
1985 | As with \f(CW\*(C`fd\*(C'\fR, you must not modify this member even when the watcher is |
|
|
1986 | stopped, always use \f(CW\*(C`ev_io_set\*(C'\fR or \f(CW\*(C`ev_io_modify\*(C'\fR for that. |
1875 | .PP |
1987 | .PP |
1876 | \fIExamples\fR |
1988 | \fIExamples\fR |
1877 | .IX Subsection "Examples" |
1989 | .IX Subsection "Examples" |
1878 | .PP |
1990 | .PP |
1879 | Example: Call \f(CW\*(C`stdin_readable_cb\*(C'\fR when \s-1STDIN_FILENO\s0 has become, well |
1991 | Example: Call \f(CW\*(C`stdin_readable_cb\*(C'\fR when \s-1STDIN_FILENO\s0 has become, well |
… | |
… | |
2250 | .IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" |
2362 | .IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" |
2251 | .PD 0 |
2363 | .PD 0 |
2252 | .IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4 |
2364 | .IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4 |
2253 | .IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" |
2365 | .IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" |
2254 | .PD |
2366 | .PD |
2255 | Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds. If \f(CW\*(C`repeat\*(C'\fR |
2367 | Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds (fractional and |
2256 | is \f(CW0.\fR, then it will automatically be stopped once the timeout is |
2368 | negative values are supported). If \f(CW\*(C`repeat\*(C'\fR is \f(CW0.\fR, then it will |
2257 | reached. If it is positive, then the timer will automatically be |
2369 | automatically be stopped once the timeout is reached. If it is positive, |
2258 | configured to trigger again \f(CW\*(C`repeat\*(C'\fR seconds later, again, and again, |
2370 | then the timer will automatically be configured to trigger again \f(CW\*(C`repeat\*(C'\fR |
2259 | until stopped manually. |
2371 | seconds later, again, and again, until stopped manually. |
2260 | .Sp |
2372 | .Sp |
2261 | The timer itself will do a best-effort at avoiding drift, that is, if |
2373 | The timer itself will do a best-effort at avoiding drift, that is, if |
2262 | you configure a timer to trigger every 10 seconds, then it will normally |
2374 | you configure a timer to trigger every 10 seconds, then it will normally |
2263 | trigger at exactly 10 second intervals. If, however, your program cannot |
2375 | trigger at exactly 10 second intervals. If, however, your program cannot |
2264 | keep up with the timer (because it takes longer than those 10 seconds to |
2376 | keep up with the timer (because it takes longer than those 10 seconds to |
… | |
… | |
2361 | \&\f(CW\*(C`ev_timer\*(C'\fR, which would still trigger roughly 10 seconds after starting |
2473 | \&\f(CW\*(C`ev_timer\*(C'\fR, which would still trigger roughly 10 seconds after starting |
2362 | it, as it uses a relative timeout). |
2474 | it, as it uses a relative timeout). |
2363 | .PP |
2475 | .PP |
2364 | \&\f(CW\*(C`ev_periodic\*(C'\fR watchers can also be used to implement vastly more complex |
2476 | \&\f(CW\*(C`ev_periodic\*(C'\fR watchers can also be used to implement vastly more complex |
2365 | timers, such as triggering an event on each \*(L"midnight, local time\*(R", or |
2477 | timers, such as triggering an event on each \*(L"midnight, local time\*(R", or |
2366 | other complicated rules. This cannot be done with \f(CW\*(C`ev_timer\*(C'\fR watchers, as |
2478 | other complicated rules. This cannot easily be done with \f(CW\*(C`ev_timer\*(C'\fR |
2367 | those cannot react to time jumps. |
2479 | watchers, as those cannot react to time jumps. |
2368 | .PP |
2480 | .PP |
2369 | As with timers, the callback is guaranteed to be invoked only when the |
2481 | As with timers, the callback is guaranteed to be invoked only when the |
2370 | point in time where it is supposed to trigger has passed. If multiple |
2482 | point in time where it is supposed to trigger has passed. If multiple |
2371 | timers become ready during the same loop iteration then the ones with |
2483 | timers become ready during the same loop iteration then the ones with |
2372 | earlier time-out values are invoked before ones with later time-out values |
2484 | earlier time-out values are invoked before ones with later time-out values |
… | |
… | |
2433 | In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`offset\*(C'\fR are both being |
2545 | In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`offset\*(C'\fR are both being |
2434 | ignored. Instead, each time the periodic watcher gets scheduled, the |
2546 | ignored. Instead, each time the periodic watcher gets scheduled, the |
2435 | reschedule callback will be called with the watcher as first, and the |
2547 | reschedule callback will be called with the watcher as first, and the |
2436 | current time as second argument. |
2548 | current time as second argument. |
2437 | .Sp |
2549 | .Sp |
2438 | \&\s-1NOTE: \s0\fIThis callback \s-1MUST NOT\s0 stop or destroy any periodic watcher, ever, |
2550 | \&\s-1NOTE:\s0 \fIThis callback \s-1MUST NOT\s0 stop or destroy any periodic watcher, ever, |
2439 | or make \s-1ANY\s0 other event loop modifications whatsoever, unless explicitly |
2551 | or make \s-1ANY\s0 other event loop modifications whatsoever, unless explicitly |
2440 | allowed by documentation here\fR. |
2552 | allowed by documentation here\fR. |
2441 | .Sp |
2553 | .Sp |
2442 | If you need to stop it, return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop |
2554 | If you need to stop it, return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop |
2443 | it afterwards (e.g. by starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is the |
2555 | it afterwards (e.g. by starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is the |
… | |
… | |
2457 | It must return the next time to trigger, based on the passed time value |
2569 | It must return the next time to trigger, based on the passed time value |
2458 | (that is, the lowest time value larger than to the second argument). It |
2570 | (that is, the lowest time value larger than to the second argument). It |
2459 | will usually be called just before the callback will be triggered, but |
2571 | will usually be called just before the callback will be triggered, but |
2460 | might be called at other times, too. |
2572 | might be called at other times, too. |
2461 | .Sp |
2573 | .Sp |
2462 | \&\s-1NOTE: \s0\fIThis callback must always return a time that is higher than or |
2574 | \&\s-1NOTE:\s0 \fIThis callback must always return a time that is higher than or |
2463 | equal to the passed \f(CI\*(C`now\*(C'\fI value\fR. |
2575 | equal to the passed \f(CI\*(C`now\*(C'\fI value\fR. |
2464 | .Sp |
2576 | .Sp |
2465 | This can be used to create very complex timers, such as a timer that |
2577 | This can be used to create very complex timers, such as a timer that |
2466 | triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate the |
2578 | triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate |
2467 | next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for this. How |
2579 | the next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for |
2468 | you do this is, again, up to you (but it is not trivial, which is the main |
2580 | this. Here is a (completely untested, no error checking) example on how to |
2469 | reason I omitted it as an example). |
2581 | do this: |
|
|
2582 | .Sp |
|
|
2583 | .Vb 1 |
|
|
2584 | \& #include <time.h> |
|
|
2585 | \& |
|
|
2586 | \& static ev_tstamp |
|
|
2587 | \& my_rescheduler (ev_periodic *w, ev_tstamp now) |
|
|
2588 | \& { |
|
|
2589 | \& time_t tnow = (time_t)now; |
|
|
2590 | \& struct tm tm; |
|
|
2591 | \& localtime_r (&tnow, &tm); |
|
|
2592 | \& |
|
|
2593 | \& tm.tm_sec = tm.tm_min = tm.tm_hour = 0; // midnight current day |
|
|
2594 | \& ++tm.tm_mday; // midnight next day |
|
|
2595 | \& |
|
|
2596 | \& return mktime (&tm); |
|
|
2597 | \& } |
|
|
2598 | .Ve |
|
|
2599 | .Sp |
|
|
2600 | Note: this code might run into trouble on days that have more then two |
|
|
2601 | midnights (beginning and end). |
2470 | .RE |
2602 | .RE |
2471 | .RS 4 |
2603 | .RS 4 |
2472 | .RE |
2604 | .RE |
2473 | .IP "ev_periodic_again (loop, ev_periodic *)" 4 |
2605 | .IP "ev_periodic_again (loop, ev_periodic *)" 4 |
2474 | .IX Item "ev_periodic_again (loop, ev_periodic *)" |
2606 | .IX Item "ev_periodic_again (loop, ev_periodic *)" |
… | |
… | |
2592 | The simplest way to ensure that the signal mask is reset in the child is |
2724 | The simplest way to ensure that the signal mask is reset in the child is |
2593 | to install a fork handler with \f(CW\*(C`pthread_atfork\*(C'\fR that resets it. That will |
2725 | to install a fork handler with \f(CW\*(C`pthread_atfork\*(C'\fR that resets it. That will |
2594 | catch fork calls done by libraries (such as the libc) as well. |
2726 | catch fork calls done by libraries (such as the libc) as well. |
2595 | .PP |
2727 | .PP |
2596 | In current versions of libev, the signal will not be blocked indefinitely |
2728 | In current versions of libev, the signal will not be blocked indefinitely |
2597 | unless you use the \f(CW\*(C`signalfd\*(C'\fR \s-1API \s0(\f(CW\*(C`EV_SIGNALFD\*(C'\fR). While this reduces |
2729 | unless you use the \f(CW\*(C`signalfd\*(C'\fR \s-1API\s0 (\f(CW\*(C`EV_SIGNALFD\*(C'\fR). While this reduces |
2598 | the window of opportunity for problems, it will not go away, as libev |
2730 | the window of opportunity for problems, it will not go away, as libev |
2599 | \&\fIhas\fR to modify the signal mask, at least temporarily. |
2731 | \&\fIhas\fR to modify the signal mask, at least temporarily. |
2600 | .PP |
2732 | .PP |
2601 | So I can't stress this enough: \fIIf you do not reset your signal mask when |
2733 | So I can't stress this enough: \fIIf you do not reset your signal mask when |
2602 | you expect it to be empty, you have a race condition in your code\fR. This |
2734 | you expect it to be empty, you have a race condition in your code\fR. This |
… | |
… | |
3644 | is a time window between the event loop checking and resetting the async |
3776 | is a time window between the event loop checking and resetting the async |
3645 | notification, and the callback being invoked. |
3777 | notification, and the callback being invoked. |
3646 | .SH "OTHER FUNCTIONS" |
3778 | .SH "OTHER FUNCTIONS" |
3647 | .IX Header "OTHER FUNCTIONS" |
3779 | .IX Header "OTHER FUNCTIONS" |
3648 | There are some other functions of possible interest. Described. Here. Now. |
3780 | There are some other functions of possible interest. Described. Here. Now. |
3649 | .IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4 |
3781 | .IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback, arg)" 4 |
3650 | .IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" |
3782 | .IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback, arg)" |
3651 | This function combines a simple timer and an I/O watcher, calls your |
3783 | This function combines a simple timer and an I/O watcher, calls your |
3652 | callback on whichever event happens first and automatically stops both |
3784 | callback on whichever event happens first and automatically stops both |
3653 | watchers. This is useful if you want to wait for a single event on an fd |
3785 | watchers. This is useful if you want to wait for a single event on an fd |
3654 | or timeout without having to allocate/configure/start/stop/free one or |
3786 | or timeout without having to allocate/configure/start/stop/free one or |
3655 | more watchers yourself. |
3787 | more watchers yourself. |
… | |
… | |
3870 | .PP |
4002 | .PP |
3871 | First, you need to associate some data with the event loop: |
4003 | First, you need to associate some data with the event loop: |
3872 | .PP |
4004 | .PP |
3873 | .Vb 6 |
4005 | .Vb 6 |
3874 | \& typedef struct { |
4006 | \& typedef struct { |
3875 | \& mutex_t lock; /* global loop lock */ |
4007 | \& pthread_mutex_t lock; /* global loop lock */ |
|
|
4008 | \& pthread_t tid; |
|
|
4009 | \& pthread_cond_t invoke_cv; |
3876 | \& ev_async async_w; |
4010 | \& ev_async async_w; |
3877 | \& thread_t tid; |
|
|
3878 | \& cond_t invoke_cv; |
|
|
3879 | \& } userdata; |
4011 | \& } userdata; |
3880 | \& |
4012 | \& |
3881 | \& void prepare_loop (EV_P) |
4013 | \& void prepare_loop (EV_P) |
3882 | \& { |
4014 | \& { |
3883 | \& // for simplicity, we use a static userdata struct. |
4015 | \& // for simplicity, we use a static userdata struct. |
3884 | \& static userdata u; |
4016 | \& static userdata u; |
3885 | \& |
4017 | \& |
3886 | \& ev_async_init (&u\->async_w, async_cb); |
4018 | \& ev_async_init (&u.async_w, async_cb); |
3887 | \& ev_async_start (EV_A_ &u\->async_w); |
4019 | \& ev_async_start (EV_A_ &u.async_w); |
3888 | \& |
4020 | \& |
3889 | \& pthread_mutex_init (&u\->lock, 0); |
4021 | \& pthread_mutex_init (&u.lock, 0); |
3890 | \& pthread_cond_init (&u\->invoke_cv, 0); |
4022 | \& pthread_cond_init (&u.invoke_cv, 0); |
3891 | \& |
4023 | \& |
3892 | \& // now associate this with the loop |
4024 | \& // now associate this with the loop |
3893 | \& ev_set_userdata (EV_A_ u); |
4025 | \& ev_set_userdata (EV_A_ &u); |
3894 | \& ev_set_invoke_pending_cb (EV_A_ l_invoke); |
4026 | \& ev_set_invoke_pending_cb (EV_A_ l_invoke); |
3895 | \& ev_set_loop_release_cb (EV_A_ l_release, l_acquire); |
4027 | \& ev_set_loop_release_cb (EV_A_ l_release, l_acquire); |
3896 | \& |
4028 | \& |
3897 | \& // then create the thread running ev_run |
4029 | \& // then create the thread running ev_run |
3898 | \& pthread_create (&u\->tid, 0, l_run, EV_A); |
4030 | \& pthread_create (&u.tid, 0, l_run, EV_A); |
3899 | \& } |
4031 | \& } |
3900 | .Ve |
4032 | .Ve |
3901 | .PP |
4033 | .PP |
3902 | The callback for the \f(CW\*(C`ev_async\*(C'\fR watcher does nothing: the watcher is used |
4034 | The callback for the \f(CW\*(C`ev_async\*(C'\fR watcher does nothing: the watcher is used |
3903 | solely to wake up the event loop so it takes notice of any new watchers |
4035 | solely to wake up the event loop so it takes notice of any new watchers |
… | |
… | |
4105 | The normal C \s-1API\s0 should work fine when used from \*(C+: both ev.h and the |
4237 | The normal C \s-1API\s0 should work fine when used from \*(C+: both ev.h and the |
4106 | libev sources can be compiled as \*(C+. Therefore, code that uses the C \s-1API\s0 |
4238 | libev sources can be compiled as \*(C+. Therefore, code that uses the C \s-1API\s0 |
4107 | will work fine. |
4239 | will work fine. |
4108 | .PP |
4240 | .PP |
4109 | Proper exception specifications might have to be added to callbacks passed |
4241 | Proper exception specifications might have to be added to callbacks passed |
4110 | to libev: exceptions may be thrown only from watcher callbacks, all |
4242 | to libev: exceptions may be thrown only from watcher callbacks, all other |
4111 | other callbacks (allocator, syserr, loop acquire/release and periodic |
4243 | callbacks (allocator, syserr, loop acquire/release and periodic reschedule |
4112 | reschedule callbacks) must not throw exceptions, and might need a \f(CW\*(C`throw |
4244 | callbacks) must not throw exceptions, and might need a \f(CW\*(C`noexcept\*(C'\fR |
4113 | ()\*(C'\fR specification. If you have code that needs to be compiled as both C |
4245 | specification. If you have code that needs to be compiled as both C and |
4114 | and \*(C+ you can use the \f(CW\*(C`EV_THROW\*(C'\fR macro for this: |
4246 | \&\*(C+ you can use the \f(CW\*(C`EV_NOEXCEPT\*(C'\fR macro for this: |
4115 | .PP |
4247 | .PP |
4116 | .Vb 6 |
4248 | .Vb 6 |
4117 | \& static void |
4249 | \& static void |
4118 | \& fatal_error (const char *msg) EV_THROW |
4250 | \& fatal_error (const char *msg) EV_NOEXCEPT |
4119 | \& { |
4251 | \& { |
4120 | \& perror (msg); |
4252 | \& perror (msg); |
4121 | \& abort (); |
4253 | \& abort (); |
4122 | \& } |
4254 | \& } |
4123 | \& |
4255 | \& |
… | |
… | |
4287 | gets automatically stopped and restarted when reconfiguring it with this |
4419 | gets automatically stopped and restarted when reconfiguring it with this |
4288 | method. |
4420 | method. |
4289 | .Sp |
4421 | .Sp |
4290 | For \f(CW\*(C`ev::embed\*(C'\fR watchers this method is called \f(CW\*(C`set_embed\*(C'\fR, to avoid |
4422 | For \f(CW\*(C`ev::embed\*(C'\fR watchers this method is called \f(CW\*(C`set_embed\*(C'\fR, to avoid |
4291 | clashing with the \f(CW\*(C`set (loop)\*(C'\fR method. |
4423 | clashing with the \f(CW\*(C`set (loop)\*(C'\fR method. |
|
|
4424 | .Sp |
|
|
4425 | For \f(CW\*(C`ev::io\*(C'\fR watchers there is an additional \f(CW\*(C`set\*(C'\fR method that acepts a |
|
|
4426 | new event mask only, and internally calls \f(CW\*(C`ev_io_modfify\*(C'\fR. |
4292 | .IP "w\->start ()" 4 |
4427 | .IP "w\->start ()" 4 |
4293 | .IX Item "w->start ()" |
4428 | .IX Item "w->start ()" |
4294 | Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the |
4429 | Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the |
4295 | constructor already stores the event loop. |
4430 | constructor already stores the event loop. |
4296 | .IP "w\->start ([arguments])" 4 |
4431 | .IP "w\->start ([arguments])" 4 |
… | |
… | |
4497 | \& #include "ev.c" |
4632 | \& #include "ev.c" |
4498 | .Ve |
4633 | .Ve |
4499 | .PP |
4634 | .PP |
4500 | This will automatically include \fIev.h\fR, too, and should be done in a |
4635 | This will automatically include \fIev.h\fR, too, and should be done in a |
4501 | single C source file only to provide the function implementations. To use |
4636 | single C source file only to provide the function implementations. To use |
4502 | it, do the same for \fIev.h\fR in all files wishing to use this \s-1API \s0(best |
4637 | it, do the same for \fIev.h\fR in all files wishing to use this \s-1API\s0 (best |
4503 | done by writing a wrapper around \fIev.h\fR that you can include instead and |
4638 | done by writing a wrapper around \fIev.h\fR that you can include instead and |
4504 | where you can put other configuration options): |
4639 | where you can put other configuration options): |
4505 | .PP |
4640 | .PP |
4506 | .Vb 2 |
4641 | .Vb 2 |
4507 | \& #define EV_STANDALONE 1 |
4642 | \& #define EV_STANDALONE 1 |
… | |
… | |
4521 | \& ev_vars.h |
4656 | \& ev_vars.h |
4522 | \& ev_wrap.h |
4657 | \& ev_wrap.h |
4523 | \& |
4658 | \& |
4524 | \& ev_win32.c required on win32 platforms only |
4659 | \& ev_win32.c required on win32 platforms only |
4525 | \& |
4660 | \& |
4526 | \& ev_select.c only when select backend is enabled (which is enabled by default) |
4661 | \& ev_select.c only when select backend is enabled |
4527 | \& ev_poll.c only when poll backend is enabled (disabled by default) |
4662 | \& ev_poll.c only when poll backend is enabled |
4528 | \& ev_epoll.c only when the epoll backend is enabled (disabled by default) |
4663 | \& ev_epoll.c only when the epoll backend is enabled |
|
|
4664 | \& ev_linuxaio.c only when the linux aio backend is enabled |
|
|
4665 | \& ev_iouring.c only when the linux io_uring backend is enabled |
4529 | \& ev_kqueue.c only when the kqueue backend is enabled (disabled by default) |
4666 | \& ev_kqueue.c only when the kqueue backend is enabled |
4530 | \& ev_port.c only when the solaris port backend is enabled (disabled by default) |
4667 | \& ev_port.c only when the solaris port backend is enabled |
4531 | .Ve |
4668 | .Ve |
4532 | .PP |
4669 | .PP |
4533 | \&\fIev.c\fR includes the backend files directly when enabled, so you only need |
4670 | \&\fIev.c\fR includes the backend files directly when enabled, so you only need |
4534 | to compile this single file. |
4671 | to compile this single file. |
4535 | .PP |
4672 | .PP |
… | |
… | |
4580 | values when compiling libev vs. including \fIev.h\fR, so it is permissible |
4717 | values when compiling libev vs. including \fIev.h\fR, so it is permissible |
4581 | to redefine them before including \fIev.h\fR without breaking compatibility |
4718 | to redefine them before including \fIev.h\fR without breaking compatibility |
4582 | to a compiled library. All other symbols change the \s-1ABI,\s0 which means all |
4719 | to a compiled library. All other symbols change the \s-1ABI,\s0 which means all |
4583 | users of libev and the libev code itself must be compiled with compatible |
4720 | users of libev and the libev code itself must be compiled with compatible |
4584 | settings. |
4721 | settings. |
4585 | .IP "\s-1EV_COMPAT3 \s0(h)" 4 |
4722 | .IP "\s-1EV_COMPAT3\s0 (h)" 4 |
4586 | .IX Item "EV_COMPAT3 (h)" |
4723 | .IX Item "EV_COMPAT3 (h)" |
4587 | Backwards compatibility is a major concern for libev. This is why this |
4724 | Backwards compatibility is a major concern for libev. This is why this |
4588 | release of libev comes with wrappers for the functions and symbols that |
4725 | release of libev comes with wrappers for the functions and symbols that |
4589 | have been renamed between libev version 3 and 4. |
4726 | have been renamed between libev version 3 and 4. |
4590 | .Sp |
4727 | .Sp |
… | |
… | |
4595 | typedef in that case. |
4732 | typedef in that case. |
4596 | .Sp |
4733 | .Sp |
4597 | In some future version, the default for \f(CW\*(C`EV_COMPAT3\*(C'\fR will become \f(CW0\fR, |
4734 | In some future version, the default for \f(CW\*(C`EV_COMPAT3\*(C'\fR will become \f(CW0\fR, |
4598 | and in some even more future version the compatibility code will be |
4735 | and in some even more future version the compatibility code will be |
4599 | removed completely. |
4736 | removed completely. |
4600 | .IP "\s-1EV_STANDALONE \s0(h)" 4 |
4737 | .IP "\s-1EV_STANDALONE\s0 (h)" 4 |
4601 | .IX Item "EV_STANDALONE (h)" |
4738 | .IX Item "EV_STANDALONE (h)" |
4602 | Must always be \f(CW1\fR if you do not use autoconf configuration, which |
4739 | Must always be \f(CW1\fR if you do not use autoconf configuration, which |
4603 | keeps libev from including \fIconfig.h\fR, and it also defines dummy |
4740 | keeps libev from including \fIconfig.h\fR, and it also defines dummy |
4604 | implementations for some libevent functions (such as logging, which is not |
4741 | implementations for some libevent functions (such as logging, which is not |
4605 | supported). It will also not define any of the structs usually found in |
4742 | supported). It will also not define any of the structs usually found in |
… | |
… | |
4646 | higher, as it simplifies linking (no need for \f(CW\*(C`\-lrt\*(C'\fR). |
4783 | higher, as it simplifies linking (no need for \f(CW\*(C`\-lrt\*(C'\fR). |
4647 | .IP "\s-1EV_USE_NANOSLEEP\s0" 4 |
4784 | .IP "\s-1EV_USE_NANOSLEEP\s0" 4 |
4648 | .IX Item "EV_USE_NANOSLEEP" |
4785 | .IX Item "EV_USE_NANOSLEEP" |
4649 | If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available |
4786 | If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available |
4650 | and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR. |
4787 | and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR. |
|
|
4788 | .IP "\s-1EV_USE_EVENTFD\s0" 4 |
|
|
4789 | .IX Item "EV_USE_EVENTFD" |
|
|
4790 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is |
|
|
4791 | available and will probe for kernel support at runtime. This will improve |
|
|
4792 | \&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption. |
|
|
4793 | If undefined, it will be enabled if the headers indicate GNU/Linux + Glibc |
|
|
4794 | 2.7 or newer, otherwise disabled. |
|
|
4795 | .IP "\s-1EV_USE_SIGNALFD\s0" 4 |
|
|
4796 | .IX Item "EV_USE_SIGNALFD" |
|
|
4797 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`signalfd ()\*(C'\fR is |
|
|
4798 | available and will probe for kernel support at runtime. This enables |
|
|
4799 | the use of \s-1EVFLAG_SIGNALFD\s0 for faster and simpler signal handling. If |
|
|
4800 | undefined, it will be enabled if the headers indicate GNU/Linux + Glibc |
|
|
4801 | 2.7 or newer, otherwise disabled. |
|
|
4802 | .IP "\s-1EV_USE_TIMERFD\s0" 4 |
|
|
4803 | .IX Item "EV_USE_TIMERFD" |
|
|
4804 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`timerfd ()\*(C'\fR is |
|
|
4805 | available and will probe for kernel support at runtime. This allows |
|
|
4806 | libev to detect time jumps accurately. If undefined, it will be enabled |
|
|
4807 | if the headers indicate GNU/Linux + Glibc 2.8 or newer and define |
|
|
4808 | \&\f(CW\*(C`TFD_TIMER_CANCEL_ON_SET\*(C'\fR, otherwise disabled. |
4651 | .IP "\s-1EV_USE_EVENTFD\s0" 4 |
4809 | .IP "\s-1EV_USE_EVENTFD\s0" 4 |
4652 | .IX Item "EV_USE_EVENTFD" |
4810 | .IX Item "EV_USE_EVENTFD" |
4653 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is |
4811 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is |
4654 | available and will probe for kernel support at runtime. This will improve |
4812 | available and will probe for kernel support at runtime. This will improve |
4655 | \&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption. |
4813 | \&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption. |
… | |
… | |
4714 | If defined to be \f(CW1\fR, libev will compile in support for the Linux |
4872 | If defined to be \f(CW1\fR, libev will compile in support for the Linux |
4715 | \&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime, |
4873 | \&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime, |
4716 | otherwise another method will be used as fallback. This is the preferred |
4874 | otherwise another method will be used as fallback. This is the preferred |
4717 | backend for GNU/Linux systems. If undefined, it will be enabled if the |
4875 | backend for GNU/Linux systems. If undefined, it will be enabled if the |
4718 | headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. |
4876 | headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. |
|
|
4877 | .IP "\s-1EV_USE_LINUXAIO\s0" 4 |
|
|
4878 | .IX Item "EV_USE_LINUXAIO" |
|
|
4879 | If defined to be \f(CW1\fR, libev will compile in support for the Linux aio |
|
|
4880 | backend (\f(CW\*(C`EV_USE_EPOLL\*(C'\fR must also be enabled). If undefined, it will be |
|
|
4881 | enabled on linux, otherwise disabled. |
|
|
4882 | .IP "\s-1EV_USE_IOURING\s0" 4 |
|
|
4883 | .IX Item "EV_USE_IOURING" |
|
|
4884 | If defined to be \f(CW1\fR, libev will compile in support for the Linux |
|
|
4885 | io_uring backend (\f(CW\*(C`EV_USE_EPOLL\*(C'\fR must also be enabled). Due to it's |
|
|
4886 | current limitations it has to be requested explicitly. If undefined, it |
|
|
4887 | will be enabled on linux, otherwise disabled. |
4719 | .IP "\s-1EV_USE_KQUEUE\s0" 4 |
4888 | .IP "\s-1EV_USE_KQUEUE\s0" 4 |
4720 | .IX Item "EV_USE_KQUEUE" |
4889 | .IX Item "EV_USE_KQUEUE" |
4721 | If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style |
4890 | If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style |
4722 | \&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime, |
4891 | \&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime, |
4723 | otherwise another method will be used as fallback. This is the preferred |
4892 | otherwise another method will be used as fallback. This is the preferred |
… | |
… | |
4763 | handler \*(L"locking\*(R" as well as for signal and thread safety in \f(CW\*(C`ev_async\*(C'\fR |
4932 | handler \*(L"locking\*(R" as well as for signal and thread safety in \f(CW\*(C`ev_async\*(C'\fR |
4764 | watchers. |
4933 | watchers. |
4765 | .Sp |
4934 | .Sp |
4766 | In the absence of this define, libev will use \f(CW\*(C`sig_atomic_t volatile\*(C'\fR |
4935 | In the absence of this define, libev will use \f(CW\*(C`sig_atomic_t volatile\*(C'\fR |
4767 | (from \fIsignal.h\fR), which is usually good enough on most platforms. |
4936 | (from \fIsignal.h\fR), which is usually good enough on most platforms. |
4768 | .IP "\s-1EV_H \s0(h)" 4 |
4937 | .IP "\s-1EV_H\s0 (h)" 4 |
4769 | .IX Item "EV_H (h)" |
4938 | .IX Item "EV_H (h)" |
4770 | The name of the \fIev.h\fR header file used to include it. The default if |
4939 | The name of the \fIev.h\fR header file used to include it. The default if |
4771 | undefined is \f(CW"ev.h"\fR in \fIevent.h\fR, \fIev.c\fR and \fIev++.h\fR. This can be |
4940 | undefined is \f(CW"ev.h"\fR in \fIevent.h\fR, \fIev.c\fR and \fIev++.h\fR. This can be |
4772 | used to virtually rename the \fIev.h\fR header file in case of conflicts. |
4941 | used to virtually rename the \fIev.h\fR header file in case of conflicts. |
4773 | .IP "\s-1EV_CONFIG_H \s0(h)" 4 |
4942 | .IP "\s-1EV_CONFIG_H\s0 (h)" 4 |
4774 | .IX Item "EV_CONFIG_H (h)" |
4943 | .IX Item "EV_CONFIG_H (h)" |
4775 | If \f(CW\*(C`EV_STANDALONE\*(C'\fR isn't \f(CW1\fR, this variable can be used to override |
4944 | If \f(CW\*(C`EV_STANDALONE\*(C'\fR isn't \f(CW1\fR, this variable can be used to override |
4776 | \&\fIev.c\fR's idea of where to find the \fIconfig.h\fR file, similarly to |
4945 | \&\fIev.c\fR's idea of where to find the \fIconfig.h\fR file, similarly to |
4777 | \&\f(CW\*(C`EV_H\*(C'\fR, above. |
4946 | \&\f(CW\*(C`EV_H\*(C'\fR, above. |
4778 | .IP "\s-1EV_EVENT_H \s0(h)" 4 |
4947 | .IP "\s-1EV_EVENT_H\s0 (h)" 4 |
4779 | .IX Item "EV_EVENT_H (h)" |
4948 | .IX Item "EV_EVENT_H (h)" |
4780 | Similarly to \f(CW\*(C`EV_H\*(C'\fR, this macro can be used to override \fIevent.c\fR's idea |
4949 | Similarly to \f(CW\*(C`EV_H\*(C'\fR, this macro can be used to override \fIevent.c\fR's idea |
4781 | of how the \fIevent.h\fR header can be found, the default is \f(CW"event.h"\fR. |
4950 | of how the \fIevent.h\fR header can be found, the default is \f(CW"event.h"\fR. |
4782 | .IP "\s-1EV_PROTOTYPES \s0(h)" 4 |
4951 | .IP "\s-1EV_PROTOTYPES\s0 (h)" 4 |
4783 | .IX Item "EV_PROTOTYPES (h)" |
4952 | .IX Item "EV_PROTOTYPES (h)" |
4784 | If defined to be \f(CW0\fR, then \fIev.h\fR will not define any function |
4953 | If defined to be \f(CW0\fR, then \fIev.h\fR will not define any function |
4785 | prototypes, but still define all the structs and other symbols. This is |
4954 | prototypes, but still define all the structs and other symbols. This is |
4786 | occasionally useful if you want to provide your own wrapper functions |
4955 | occasionally useful if you want to provide your own wrapper functions |
4787 | around libev functions. |
4956 | around libev functions. |
… | |
… | |
4980 | called. If set to \f(CW2\fR, then the internal verification code will be |
5149 | called. If set to \f(CW2\fR, then the internal verification code will be |
4981 | called once per loop, which can slow down libev. If set to \f(CW3\fR, then the |
5150 | called once per loop, which can slow down libev. If set to \f(CW3\fR, then the |
4982 | verification code will be called very frequently, which will slow down |
5151 | verification code will be called very frequently, which will slow down |
4983 | libev considerably. |
5152 | libev considerably. |
4984 | .Sp |
5153 | .Sp |
|
|
5154 | Verification errors are reported via C's \f(CW\*(C`assert\*(C'\fR mechanism, so if you |
|
|
5155 | disable that (e.g. by defining \f(CW\*(C`NDEBUG\*(C'\fR) then no errors will be reported. |
|
|
5156 | .Sp |
4985 | The default is \f(CW1\fR, unless \f(CW\*(C`EV_FEATURES\*(C'\fR overrides it, in which case it |
5157 | The default is \f(CW1\fR, unless \f(CW\*(C`EV_FEATURES\*(C'\fR overrides it, in which case it |
4986 | will be \f(CW0\fR. |
5158 | will be \f(CW0\fR. |
4987 | .IP "\s-1EV_COMMON\s0" 4 |
5159 | .IP "\s-1EV_COMMON\s0" 4 |
4988 | .IX Item "EV_COMMON" |
5160 | .IX Item "EV_COMMON" |
4989 | By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining |
5161 | By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining |
… | |
… | |
4996 | .Vb 3 |
5168 | .Vb 3 |
4997 | \& #define EV_COMMON \e |
5169 | \& #define EV_COMMON \e |
4998 | \& SV *self; /* contains this struct */ \e |
5170 | \& SV *self; /* contains this struct */ \e |
4999 | \& SV *cb_sv, *fh /* note no trailing ";" */ |
5171 | \& SV *cb_sv, *fh /* note no trailing ";" */ |
5000 | .Ve |
5172 | .Ve |
5001 | .IP "\s-1EV_CB_DECLARE \s0(type)" 4 |
5173 | .IP "\s-1EV_CB_DECLARE\s0 (type)" 4 |
5002 | .IX Item "EV_CB_DECLARE (type)" |
5174 | .IX Item "EV_CB_DECLARE (type)" |
5003 | .PD 0 |
5175 | .PD 0 |
5004 | .IP "\s-1EV_CB_INVOKE \s0(watcher, revents)" 4 |
5176 | .IP "\s-1EV_CB_INVOKE\s0 (watcher, revents)" 4 |
5005 | .IX Item "EV_CB_INVOKE (watcher, revents)" |
5177 | .IX Item "EV_CB_INVOKE (watcher, revents)" |
5006 | .IP "ev_set_cb (ev, cb)" 4 |
5178 | .IP "ev_set_cb (ev, cb)" 4 |
5007 | .IX Item "ev_set_cb (ev, cb)" |
5179 | .IX Item "ev_set_cb (ev, cb)" |
5008 | .PD |
5180 | .PD |
5009 | Can be used to change the callback member declaration in each watcher, |
5181 | Can be used to change the callback member declaration in each watcher, |
… | |
… | |
5012 | their default definitions. One possible use for overriding these is to |
5184 | their default definitions. One possible use for overriding these is to |
5013 | avoid the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument in all cases, or to use |
5185 | avoid the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument in all cases, or to use |
5014 | method calls instead of plain function calls in \*(C+. |
5186 | method calls instead of plain function calls in \*(C+. |
5015 | .SS "\s-1EXPORTED API SYMBOLS\s0" |
5187 | .SS "\s-1EXPORTED API SYMBOLS\s0" |
5016 | .IX Subsection "EXPORTED API SYMBOLS" |
5188 | .IX Subsection "EXPORTED API SYMBOLS" |
5017 | If you need to re-export the \s-1API \s0(e.g. via a \s-1DLL\s0) and you need a list of |
5189 | If you need to re-export the \s-1API\s0 (e.g. via a \s-1DLL\s0) and you need a list of |
5018 | exported symbols, you can use the provided \fISymbol.*\fR files which list |
5190 | exported symbols, you can use the provided \fISymbol.*\fR files which list |
5019 | all public symbols, one per line: |
5191 | all public symbols, one per line: |
5020 | .PP |
5192 | .PP |
5021 | .Vb 2 |
5193 | .Vb 2 |
5022 | \& Symbols.ev for libev proper |
5194 | \& Symbols.ev for libev proper |
… | |
… | |
5254 | .PP |
5426 | .PP |
5255 | \fI\f(CI\*(C`select\*(C'\fI is buggy\fR |
5427 | \fI\f(CI\*(C`select\*(C'\fI is buggy\fR |
5256 | .IX Subsection "select is buggy" |
5428 | .IX Subsection "select is buggy" |
5257 | .PP |
5429 | .PP |
5258 | All that's left is \f(CW\*(C`select\*(C'\fR, and of course Apple found a way to fuck this |
5430 | All that's left is \f(CW\*(C`select\*(C'\fR, and of course Apple found a way to fuck this |
5259 | one up as well: On \s-1OS/X, \s0\f(CW\*(C`select\*(C'\fR actively limits the number of file |
5431 | one up as well: On \s-1OS/X,\s0 \f(CW\*(C`select\*(C'\fR actively limits the number of file |
5260 | descriptors you can pass in to 1024 \- your program suddenly crashes when |
5432 | descriptors you can pass in to 1024 \- your program suddenly crashes when |
5261 | you use more. |
5433 | you use more. |
5262 | .PP |
5434 | .PP |
5263 | There is an undocumented \*(L"workaround\*(R" for this \- defining |
5435 | There is an undocumented \*(L"workaround\*(R" for this \- defining |
5264 | \&\f(CW\*(C`_DARWIN_UNLIMITED_SELECT\*(C'\fR, which libev tries to use, so select \fIshould\fR |
5436 | \&\f(CW\*(C`_DARWIN_UNLIMITED_SELECT\*(C'\fR, which libev tries to use, so select \fIshould\fR |
… | |
… | |
5412 | Libev assumes not only that all watcher pointers have the same internal |
5584 | Libev assumes not only that all watcher pointers have the same internal |
5413 | structure (guaranteed by \s-1POSIX\s0 but not by \s-1ISO C\s0 for example), but it also |
5585 | structure (guaranteed by \s-1POSIX\s0 but not by \s-1ISO C\s0 for example), but it also |
5414 | assumes that the same (machine) code can be used to call any watcher |
5586 | assumes that the same (machine) code can be used to call any watcher |
5415 | callback: The watcher callbacks have different type signatures, but libev |
5587 | callback: The watcher callbacks have different type signatures, but libev |
5416 | calls them using an \f(CW\*(C`ev_watcher *\*(C'\fR internally. |
5588 | calls them using an \f(CW\*(C`ev_watcher *\*(C'\fR internally. |
|
|
5589 | .IP "null pointers and integer zero are represented by 0 bytes" 4 |
|
|
5590 | .IX Item "null pointers and integer zero are represented by 0 bytes" |
|
|
5591 | Libev uses \f(CW\*(C`memset\*(C'\fR to initialise structs and arrays to \f(CW0\fR bytes, and |
|
|
5592 | relies on this setting pointers and integers to null. |
5417 | .IP "pointer accesses must be thread-atomic" 4 |
5593 | .IP "pointer accesses must be thread-atomic" 4 |
5418 | .IX Item "pointer accesses must be thread-atomic" |
5594 | .IX Item "pointer accesses must be thread-atomic" |
5419 | Accessing a pointer value must be atomic, it must both be readable and |
5595 | Accessing a pointer value must be atomic, it must both be readable and |
5420 | writable in one piece \- this is the case on all current architectures. |
5596 | writable in one piece \- this is the case on all current architectures. |
5421 | .ie n .IP """sig_atomic_t volatile"" must be thread-atomic as well" 4 |
5597 | .ie n .IP """sig_atomic_t volatile"" must be thread-atomic as well" 4 |