--- libev/ev.pod 2012/11/15 01:39:45 1.422 +++ libev/ev.pod 2023/06/03 08:53:03 1.469 @@ -1,3 +1,5 @@ +=encoding utf-8 + =head1 NAME libev - a high performance full-featured event loop written in C @@ -105,10 +107,10 @@ =head2 FEATURES -Libev supports C, C, the Linux-specific aio and C +interfaces, the BSD-specific C and the Solaris-specific event port +mechanisms for file descriptor events (C), the Linux C +interface (for C), Linux eventfd/signalfd (for faster and cleaner inter-thread wakeup (C)/signal handling (C)) relative timers (C), absolute timers with customised rescheduling (C), synchronous signals (C), process status @@ -159,9 +161,13 @@ so C will disable this checking): these are programming errors in the libev caller and need to be fixed there. -Libev also has a few internal error-checking Cions, and also has -extensive consistency checking code. These do not trigger under normal -circumstances, as they indicate either a bug in libev or worse. +Via the C macro you can compile in and/or enable extensive +consistency checking code inside libev that can be used to check for +internal inconsistencies, suually caused by application bugs. + +Libev also has a few internal error-checking Cions. These do not +trigger under normal circumstances, as they indicate either a bug in libev +or worse. =head1 GLOBAL FUNCTIONS @@ -265,12 +271,32 @@ free some memory if it cannot allocate memory, to use a special allocator, or even to sleep a while and retry until some memory is available. +Example: The following is the C function that libev itself uses +which should work with C and C functions of all kinds and +is probably a good basis for your own implementation. + + static void * + ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT + { + if (size) + return realloc (ptr, size); + + free (ptr); + return 0; + } + Example: Replace the libev allocator with one that waits a bit and then -retries (example requires a standards-compliant C). +retries. static void * persistent_realloc (void *ptr, size_t size) { + if (!size) + { + free (ptr); + return 0; + } + for (;;) { void *newptr = realloc (ptr, size); @@ -398,8 +424,10 @@ or setgid) then libev will I look at the environment variable C. Otherwise (the default), this environment variable will override the flags completely if it is found in the environment. This is -useful to try out specific backends to test their performance, or to work -around bugs. +useful to try out specific backends to test their performance, to work +around bugs, or to make libev threadsafe (accessing environment variables +cannot be done in a threadsafe way, but usually it works if no other +thread modifies them). =item C @@ -409,13 +437,14 @@ This works by calling C on every iteration of the loop, and thus this might slow down your event loop if you do a lot of loop iterations and little real work, but is usually not noticeable (on my -GNU/Linux system for example, C is actually a simple 5-insn sequence -without a system call and thus I fast, but my GNU/Linux system also has -C which is even faster). +GNU/Linux system for example, C is actually a simple 5-insn +sequence without a system call and thus I fast, but my GNU/Linux +system also has C which is even faster). (Update: glibc +versions 2.25 apparently removed the C optimisation again). The big advantage of this flag is that you can forget about fork (and -forget about forgetting to tell libev about forking) when you use this -flag. +forget about forgetting to tell libev about forking, although you still +have to ignore C) when you use this flag. This flag setting cannot be overridden or specified in the C environment variable. @@ -453,7 +482,16 @@ It's also required by POSIX in a threaded program, as libev calls C, whose behaviour is officially unspecified. -This flag's behaviour will become the default in future versions of libev. +=item C + +When this flag is specified, the libev will avoid using a C to +detect time jumps. It will still be able to detect time jumps, but takes +longer and has a lower accuracy in doing so, but saves a file descriptor +per loop. + +The current implementation only tries to use a C when the first +C watcher is started and falls back on other methods if it +cannot be created, but this behaviour might change in the future. =item C (value 1, portable select backend) @@ -488,7 +526,7 @@ =item C (value 4, Linux) -Use the linux-specific epoll(7) interface (for both pre- and post-2.6.9 +Use the Linux-specific epoll(7) interface (for both pre- and post-2.6.9 kernels). For few fds, this backend is a bit little slower than poll and select, but @@ -544,22 +582,66 @@ the usage. So sad. While nominally embeddable in other event loops, this feature is broken in -all kernel versions tested so far. +a lot of kernel revisions, but probably(!) works in current versions. + +This backend maps C and C in the same way as +C. + +=item C (value 64, Linux) + +Use the Linux-specific Linux AIO (I C<< aio(7) >> but C<< +io_submit(2) >>) event interface available in post-4.18 kernels (but libev +only tries to use it in 4.19+). + +This is another Linux train wreck of an event interface. + +If this backend works for you (as of this writing, it was very +experimental), it is the best event interface available on Linux and might +be well worth enabling it - if it isn't available in your kernel this will +be detected and this backend will be skipped. + +This backend can batch oneshot requests and supports a user-space ring +buffer to receive events. It also doesn't suffer from most of the design +problems of epoll (such as not being able to remove event sources from +the epoll set), and generally sounds too good to be true. Because, this +being the Linux kernel, of course it suffers from a whole new set of +limitations, forcing you to fall back to epoll, inheriting all its design +issues. + +For one, it is not easily embeddable (but probably could be done using +an event fd at some extra overhead). It also is subject to a system wide +limit that can be configured in F. If no AIO +requests are left, this backend will be skipped during initialisation, and +will switch to epoll when the loop is active. + +Most problematic in practice, however, is that not all file descriptors +work with it. For example, in Linux 5.1, TCP sockets, pipes, event fds, +files, F and many others are supported, but ttys do not work +properly (a known bug that the kernel developers don't care about, see +L), so this is not +(yet?) a generic event polling interface. + +Overall, it seems the Linux developers just don't want it to have a +generic event handling mechanism other than C