… | |
… | |
77 | on event-based programming, nor will it introduce event-based programming |
77 | on event-based programming, nor will it introduce event-based programming |
78 | with libev. |
78 | with libev. |
79 | |
79 | |
80 | Familiarity with event based programming techniques in general is assumed |
80 | Familiarity with event based programming techniques in general is assumed |
81 | throughout this document. |
81 | throughout this document. |
|
|
82 | |
|
|
83 | =head1 WHAT TO READ WHEN IN A HURRY |
|
|
84 | |
|
|
85 | This manual tries to be very detailed, but unfortunately, this also makes |
|
|
86 | it very long. If you just want to know the basics of libev, I suggest |
|
|
87 | reading L<ANATOMY OF A WATCHER>, then the L<EXAMPLE PROGRAM> above and |
|
|
88 | look up the missing functions in L<GLOBAL FUNCTIONS> and the C<ev_io> and |
|
|
89 | C<ev_timer> sections in L<WATCHER TYPES>. |
82 | |
90 | |
83 | =head1 ABOUT LIBEV |
91 | =head1 ABOUT LIBEV |
84 | |
92 | |
85 | Libev is an event loop: you register interest in certain events (such as a |
93 | Libev is an event loop: you register interest in certain events (such as a |
86 | file descriptor being readable or a timeout occurring), and it will manage |
94 | file descriptor being readable or a timeout occurring), and it will manage |
… | |
… | |
233 | the current system, you would need to look at C<ev_embeddable_backends () |
241 | the current system, you would need to look at C<ev_embeddable_backends () |
234 | & ev_supported_backends ()>, likewise for recommended ones. |
242 | & ev_supported_backends ()>, likewise for recommended ones. |
235 | |
243 | |
236 | See the description of C<ev_embed> watchers for more info. |
244 | See the description of C<ev_embed> watchers for more info. |
237 | |
245 | |
238 | =item ev_set_allocator (void *(*cb)(void *ptr, long size)) [NOT REENTRANT] |
246 | =item ev_set_allocator (void *(*cb)(void *ptr, long size)) |
239 | |
247 | |
240 | Sets the allocation function to use (the prototype is similar - the |
248 | Sets the allocation function to use (the prototype is similar - the |
241 | semantics are identical to the C<realloc> C89/SuS/POSIX function). It is |
249 | semantics are identical to the C<realloc> C89/SuS/POSIX function). It is |
242 | used to allocate and free memory (no surprises here). If it returns zero |
250 | used to allocate and free memory (no surprises here). If it returns zero |
243 | when memory needs to be allocated (C<size != 0>), the library might abort |
251 | when memory needs to be allocated (C<size != 0>), the library might abort |
… | |
… | |
269 | } |
277 | } |
270 | |
278 | |
271 | ... |
279 | ... |
272 | ev_set_allocator (persistent_realloc); |
280 | ev_set_allocator (persistent_realloc); |
273 | |
281 | |
274 | =item ev_set_syserr_cb (void (*cb)(const char *msg)); [NOT REENTRANT] |
282 | =item ev_set_syserr_cb (void (*cb)(const char *msg)) |
275 | |
283 | |
276 | Set the callback function to call on a retryable system call error (such |
284 | Set the callback function to call on a retryable system call error (such |
277 | as failed select, poll, epoll_wait). The message is a printable string |
285 | as failed select, poll, epoll_wait). The message is a printable string |
278 | indicating the system call or subsystem causing the problem. If this |
286 | indicating the system call or subsystem causing the problem. If this |
279 | callback is set, then libev will expect it to remedy the situation, no |
287 | callback is set, then libev will expect it to remedy the situation, no |
… | |
… | |
291 | } |
299 | } |
292 | |
300 | |
293 | ... |
301 | ... |
294 | ev_set_syserr_cb (fatal_error); |
302 | ev_set_syserr_cb (fatal_error); |
295 | |
303 | |
|
|
304 | =item ev_feed_signal (int signum) |
|
|
305 | |
|
|
306 | This function can be used to "simulate" a signal receive. It is completely |
|
|
307 | safe to call this function at any time, from any context, including signal |
|
|
308 | handlers or random threads. |
|
|
309 | |
|
|
310 | Its main use is to customise signal handling in your process, especially |
|
|
311 | in the presence of threads. For example, you could block signals |
|
|
312 | by default in all threads (and specifying C<EVFLAG_NOSIGMASK> when |
|
|
313 | creating any loops), and in one thread, use C<sigwait> or any other |
|
|
314 | mechanism to wait for signals, then "deliver" them to libev by calling |
|
|
315 | C<ev_feed_signal>. |
|
|
316 | |
296 | =back |
317 | =back |
297 | |
318 | |
298 | =head1 FUNCTIONS CONTROLLING EVENT LOOPS |
319 | =head1 FUNCTIONS CONTROLLING EVENT LOOPS |
299 | |
320 | |
300 | An event loop is described by a C<struct ev_loop *> (the C<struct> is |
321 | An event loop is described by a C<struct ev_loop *> (the C<struct> is |
301 | I<not> optional in this case unless libev 3 compatibility is disabled, as |
322 | I<not> optional in this case unless libev 3 compatibility is disabled, as |
302 | libev 3 had an C<ev_loop> function colliding with the struct name). |
323 | libev 3 had an C<ev_loop> function colliding with the struct name). |
303 | |
324 | |
304 | The library knows two types of such loops, the I<default> loop, which |
325 | The library knows two types of such loops, the I<default> loop, which |
305 | supports signals and child events, and dynamically created event loops |
326 | supports child process events, and dynamically created event loops which |
306 | which do not. |
327 | do not. |
307 | |
328 | |
308 | =over 4 |
329 | =over 4 |
309 | |
330 | |
310 | =item struct ev_loop *ev_default_loop (unsigned int flags) |
331 | =item struct ev_loop *ev_default_loop (unsigned int flags) |
311 | |
332 | |
… | |
… | |
347 | =item struct ev_loop *ev_loop_new (unsigned int flags) |
368 | =item struct ev_loop *ev_loop_new (unsigned int flags) |
348 | |
369 | |
349 | This will create and initialise a new event loop object. If the loop |
370 | This will create and initialise a new event loop object. If the loop |
350 | could not be initialised, returns false. |
371 | could not be initialised, returns false. |
351 | |
372 | |
352 | Note that this function I<is> thread-safe, and one common way to use |
373 | This function is thread-safe, and one common way to use libev with |
353 | libev with threads is indeed to create one loop per thread, and using the |
374 | threads is indeed to create one loop per thread, and using the default |
354 | default loop in the "main" or "initial" thread. |
375 | loop in the "main" or "initial" thread. |
355 | |
376 | |
356 | The flags argument can be used to specify special behaviour or specific |
377 | The flags argument can be used to specify special behaviour or specific |
357 | backends to use, and is usually specified as C<0> (or C<EVFLAG_AUTO>). |
378 | backends to use, and is usually specified as C<0> (or C<EVFLAG_AUTO>). |
358 | |
379 | |
359 | The following flags are supported: |
380 | The following flags are supported: |
… | |
… | |
394 | environment variable. |
415 | environment variable. |
395 | |
416 | |
396 | =item C<EVFLAG_NOINOTIFY> |
417 | =item C<EVFLAG_NOINOTIFY> |
397 | |
418 | |
398 | When this flag is specified, then libev will not attempt to use the |
419 | When this flag is specified, then libev will not attempt to use the |
399 | I<inotify> API for it's C<ev_stat> watchers. Apart from debugging and |
420 | I<inotify> API for its C<ev_stat> watchers. Apart from debugging and |
400 | testing, this flag can be useful to conserve inotify file descriptors, as |
421 | testing, this flag can be useful to conserve inotify file descriptors, as |
401 | otherwise each loop using C<ev_stat> watchers consumes one inotify handle. |
422 | otherwise each loop using C<ev_stat> watchers consumes one inotify handle. |
402 | |
423 | |
403 | =item C<EVFLAG_SIGNALFD> |
424 | =item C<EVFLAG_SIGNALFD> |
404 | |
425 | |
405 | When this flag is specified, then libev will attempt to use the |
426 | When this flag is specified, then libev will attempt to use the |
406 | I<signalfd> API for it's C<ev_signal> (and C<ev_child>) watchers. This API |
427 | I<signalfd> API for its C<ev_signal> (and C<ev_child>) watchers. This API |
407 | delivers signals synchronously, which makes it both faster and might make |
428 | delivers signals synchronously, which makes it both faster and might make |
408 | it possible to get the queued signal data. It can also simplify signal |
429 | it possible to get the queued signal data. It can also simplify signal |
409 | handling with threads, as long as you properly block signals in your |
430 | handling with threads, as long as you properly block signals in your |
410 | threads that are not interested in handling them. |
431 | threads that are not interested in handling them. |
411 | |
432 | |
412 | Signalfd will not be used by default as this changes your signal mask, and |
433 | Signalfd will not be used by default as this changes your signal mask, and |
413 | there are a lot of shoddy libraries and programs (glib's threadpool for |
434 | there are a lot of shoddy libraries and programs (glib's threadpool for |
414 | example) that can't properly initialise their signal masks. |
435 | example) that can't properly initialise their signal masks. |
|
|
436 | |
|
|
437 | =item C<EVFLAG_NOSIGMASK> |
|
|
438 | |
|
|
439 | When this flag is specified, then libev will avoid to modify the signal |
|
|
440 | mask. Specifically, this means you ahve to make sure signals are unblocked |
|
|
441 | when you want to receive them. |
|
|
442 | |
|
|
443 | This behaviour is useful when you want to do your own signal handling, or |
|
|
444 | want to handle signals only in specific threads and want to avoid libev |
|
|
445 | unblocking the signals. |
|
|
446 | |
|
|
447 | This flag's behaviour will become the default in future versions of libev. |
415 | |
448 | |
416 | =item C<EVBACKEND_SELECT> (value 1, portable select backend) |
449 | =item C<EVBACKEND_SELECT> (value 1, portable select backend) |
417 | |
450 | |
418 | This is your standard select(2) backend. Not I<completely> standard, as |
451 | This is your standard select(2) backend. Not I<completely> standard, as |
419 | libev tries to roll its own fd_set with no limits on the number of fds, |
452 | libev tries to roll its own fd_set with no limits on the number of fds, |
… | |
… | |
455 | epoll scales either O(1) or O(active_fds). |
488 | epoll scales either O(1) or O(active_fds). |
456 | |
489 | |
457 | The epoll mechanism deserves honorable mention as the most misdesigned |
490 | The epoll mechanism deserves honorable mention as the most misdesigned |
458 | of the more advanced event mechanisms: mere annoyances include silently |
491 | of the more advanced event mechanisms: mere annoyances include silently |
459 | dropping file descriptors, requiring a system call per change per file |
492 | dropping file descriptors, requiring a system call per change per file |
460 | descriptor (and unnecessary guessing of parameters), problems with dup and |
493 | descriptor (and unnecessary guessing of parameters), problems with dup, |
|
|
494 | returning before the timeout value, resulting in additional iterations |
|
|
495 | (and only giving 5ms accuracy while select on the same platform gives |
461 | so on. The biggest issue is fork races, however - if a program forks then |
496 | 0.1ms) and so on. The biggest issue is fork races, however - if a program |
462 | I<both> parent and child process have to recreate the epoll set, which can |
497 | forks then I<both> parent and child process have to recreate the epoll |
463 | take considerable time (one syscall per file descriptor) and is of course |
498 | set, which can take considerable time (one syscall per file descriptor) |
464 | hard to detect. |
499 | and is of course hard to detect. |
465 | |
500 | |
466 | Epoll is also notoriously buggy - embedding epoll fds I<should> work, but |
501 | Epoll is also notoriously buggy - embedding epoll fds I<should> work, but |
467 | of course I<doesn't>, and epoll just loves to report events for totally |
502 | of course I<doesn't>, and epoll just loves to report events for totally |
468 | I<different> file descriptors (even already closed ones, so one cannot |
503 | I<different> file descriptors (even already closed ones, so one cannot |
469 | even remove them from the set) than registered in the set (especially |
504 | even remove them from the set) than registered in the set (especially |
… | |
… | |
471 | employing an additional generation counter and comparing that against the |
506 | employing an additional generation counter and comparing that against the |
472 | events to filter out spurious ones, recreating the set when required. Last |
507 | events to filter out spurious ones, recreating the set when required. Last |
473 | not least, it also refuses to work with some file descriptors which work |
508 | not least, it also refuses to work with some file descriptors which work |
474 | perfectly fine with C<select> (files, many character devices...). |
509 | perfectly fine with C<select> (files, many character devices...). |
475 | |
510 | |
|
|
511 | Epoll is truly the train wreck analog among event poll mechanisms, |
|
|
512 | a frankenpoll, cobbled together in a hurry, no thought to design or |
|
|
513 | interaction with others. |
|
|
514 | |
476 | While stopping, setting and starting an I/O watcher in the same iteration |
515 | While stopping, setting and starting an I/O watcher in the same iteration |
477 | will result in some caching, there is still a system call per such |
516 | will result in some caching, there is still a system call per such |
478 | incident (because the same I<file descriptor> could point to a different |
517 | incident (because the same I<file descriptor> could point to a different |
479 | I<file description> now), so its best to avoid that. Also, C<dup ()>'ed |
518 | I<file description> now), so its best to avoid that. Also, C<dup ()>'ed |
480 | file descriptors might not work very well if you register events for both |
519 | file descriptors might not work very well if you register events for both |
… | |
… | |
545 | =item C<EVBACKEND_PORT> (value 32, Solaris 10) |
584 | =item C<EVBACKEND_PORT> (value 32, Solaris 10) |
546 | |
585 | |
547 | This uses the Solaris 10 event port mechanism. As with everything on Solaris, |
586 | This uses the Solaris 10 event port mechanism. As with everything on Solaris, |
548 | it's really slow, but it still scales very well (O(active_fds)). |
587 | it's really slow, but it still scales very well (O(active_fds)). |
549 | |
588 | |
550 | Please note that Solaris event ports can deliver a lot of spurious |
|
|
551 | notifications, so you need to use non-blocking I/O or other means to avoid |
|
|
552 | blocking when no data (or space) is available. |
|
|
553 | |
|
|
554 | While this backend scales well, it requires one system call per active |
589 | While this backend scales well, it requires one system call per active |
555 | file descriptor per loop iteration. For small and medium numbers of file |
590 | file descriptor per loop iteration. For small and medium numbers of file |
556 | descriptors a "slow" C<EVBACKEND_SELECT> or C<EVBACKEND_POLL> backend |
591 | descriptors a "slow" C<EVBACKEND_SELECT> or C<EVBACKEND_POLL> backend |
557 | might perform better. |
592 | might perform better. |
558 | |
593 | |
559 | On the positive side, with the exception of the spurious readiness |
594 | On the positive side, this backend actually performed fully to |
560 | notifications, this backend actually performed fully to specification |
|
|
561 | in all tests and is fully embeddable, which is a rare feat among the |
595 | specification in all tests and is fully embeddable, which is a rare feat |
562 | OS-specific backends (I vastly prefer correctness over speed hacks). |
596 | among the OS-specific backends (I vastly prefer correctness over speed |
|
|
597 | hacks). |
|
|
598 | |
|
|
599 | On the negative side, the interface is I<bizarre> - so bizarre that |
|
|
600 | even sun itself gets it wrong in their code examples: The event polling |
|
|
601 | function sometimes returning events to the caller even though an error |
|
|
602 | occurred, but with no indication whether it has done so or not (yes, it's |
|
|
603 | even documented that way) - deadly for edge-triggered interfaces where |
|
|
604 | you absolutely have to know whether an event occurred or not because you |
|
|
605 | have to re-arm the watcher. |
|
|
606 | |
|
|
607 | Fortunately libev seems to be able to work around these idiocies. |
563 | |
608 | |
564 | This backend maps C<EV_READ> and C<EV_WRITE> in the same way as |
609 | This backend maps C<EV_READ> and C<EV_WRITE> in the same way as |
565 | C<EVBACKEND_POLL>. |
610 | C<EVBACKEND_POLL>. |
566 | |
611 | |
567 | =item C<EVBACKEND_ALL> |
612 | =item C<EVBACKEND_ALL> |
568 | |
613 | |
569 | Try all backends (even potentially broken ones that wouldn't be tried |
614 | Try all backends (even potentially broken ones that wouldn't be tried |
570 | with C<EVFLAG_AUTO>). Since this is a mask, you can do stuff such as |
615 | with C<EVFLAG_AUTO>). Since this is a mask, you can do stuff such as |
571 | C<EVBACKEND_ALL & ~EVBACKEND_KQUEUE>. |
616 | C<EVBACKEND_ALL & ~EVBACKEND_KQUEUE>. |
572 | |
617 | |
573 | It is definitely not recommended to use this flag. |
618 | It is definitely not recommended to use this flag, use whatever |
|
|
619 | C<ev_recommended_backends ()> returns, or simply do not specify a backend |
|
|
620 | at all. |
|
|
621 | |
|
|
622 | =item C<EVBACKEND_MASK> |
|
|
623 | |
|
|
624 | Not a backend at all, but a mask to select all backend bits from a |
|
|
625 | C<flags> value, in case you want to mask out any backends from a flags |
|
|
626 | value (e.g. when modifying the C<LIBEV_FLAGS> environment variable). |
574 | |
627 | |
575 | =back |
628 | =back |
576 | |
629 | |
577 | If one or more of the backend flags are or'ed into the flags value, |
630 | If one or more of the backend flags are or'ed into the flags value, |
578 | then only these backends will be tried (in the reverse order as listed |
631 | then only these backends will be tried (in the reverse order as listed |
… | |
… | |
607 | This function is normally used on loop objects allocated by |
660 | This function is normally used on loop objects allocated by |
608 | C<ev_loop_new>, but it can also be used on the default loop returned by |
661 | C<ev_loop_new>, but it can also be used on the default loop returned by |
609 | C<ev_default_loop>, in which case it is not thread-safe. |
662 | C<ev_default_loop>, in which case it is not thread-safe. |
610 | |
663 | |
611 | Note that it is not advisable to call this function on the default loop |
664 | Note that it is not advisable to call this function on the default loop |
612 | except in the rare occasion where you really need to free it's resources. |
665 | except in the rare occasion where you really need to free its resources. |
613 | If you need dynamically allocated loops it is better to use C<ev_loop_new> |
666 | If you need dynamically allocated loops it is better to use C<ev_loop_new> |
614 | and C<ev_loop_destroy>. |
667 | and C<ev_loop_destroy>. |
615 | |
668 | |
616 | =item ev_loop_fork (loop) |
669 | =item ev_loop_fork (loop) |
617 | |
670 | |
… | |
… | |
665 | prepare and check phases. |
718 | prepare and check phases. |
666 | |
719 | |
667 | =item unsigned int ev_depth (loop) |
720 | =item unsigned int ev_depth (loop) |
668 | |
721 | |
669 | Returns the number of times C<ev_run> was entered minus the number of |
722 | Returns the number of times C<ev_run> was entered minus the number of |
670 | times C<ev_run> was exited, in other words, the recursion depth. |
723 | times C<ev_run> was exited normally, in other words, the recursion depth. |
671 | |
724 | |
672 | Outside C<ev_run>, this number is zero. In a callback, this number is |
725 | Outside C<ev_run>, this number is zero. In a callback, this number is |
673 | C<1>, unless C<ev_run> was invoked recursively (or from another thread), |
726 | C<1>, unless C<ev_run> was invoked recursively (or from another thread), |
674 | in which case it is higher. |
727 | in which case it is higher. |
675 | |
728 | |
676 | Leaving C<ev_run> abnormally (setjmp/longjmp, cancelling the thread |
729 | Leaving C<ev_run> abnormally (setjmp/longjmp, cancelling the thread, |
677 | etc.), doesn't count as "exit" - consider this as a hint to avoid such |
730 | throwing an exception etc.), doesn't count as "exit" - consider this |
678 | ungentleman-like behaviour unless it's really convenient. |
731 | as a hint to avoid such ungentleman-like behaviour unless it's really |
|
|
732 | convenient, in which case it is fully supported. |
679 | |
733 | |
680 | =item unsigned int ev_backend (loop) |
734 | =item unsigned int ev_backend (loop) |
681 | |
735 | |
682 | Returns one of the C<EVBACKEND_*> flags indicating the event backend in |
736 | Returns one of the C<EVBACKEND_*> flags indicating the event backend in |
683 | use. |
737 | use. |
… | |
… | |
744 | relying on all watchers to be stopped when deciding when a program has |
798 | relying on all watchers to be stopped when deciding when a program has |
745 | finished (especially in interactive programs), but having a program |
799 | finished (especially in interactive programs), but having a program |
746 | that automatically loops as long as it has to and no longer by virtue |
800 | that automatically loops as long as it has to and no longer by virtue |
747 | of relying on its watchers stopping correctly, that is truly a thing of |
801 | of relying on its watchers stopping correctly, that is truly a thing of |
748 | beauty. |
802 | beauty. |
|
|
803 | |
|
|
804 | This function is also I<mostly> exception-safe - you can break out of |
|
|
805 | a C<ev_run> call by calling C<longjmp> in a callback, throwing a C++ |
|
|
806 | exception and so on. This does not decrement the C<ev_depth> value, nor |
|
|
807 | will it clear any outstanding C<EVBREAK_ONE> breaks. |
749 | |
808 | |
750 | A flags value of C<EVRUN_NOWAIT> will look for new events, will handle |
809 | A flags value of C<EVRUN_NOWAIT> will look for new events, will handle |
751 | those events and any already outstanding ones, but will not wait and |
810 | those events and any already outstanding ones, but will not wait and |
752 | block your process in case there are no events and will return after one |
811 | block your process in case there are no events and will return after one |
753 | iteration of the loop. This is sometimes useful to poll and handle new |
812 | iteration of the loop. This is sometimes useful to poll and handle new |
… | |
… | |
815 | Can be used to make a call to C<ev_run> return early (but only after it |
874 | Can be used to make a call to C<ev_run> return early (but only after it |
816 | has processed all outstanding events). The C<how> argument must be either |
875 | has processed all outstanding events). The C<how> argument must be either |
817 | C<EVBREAK_ONE>, which will make the innermost C<ev_run> call return, or |
876 | C<EVBREAK_ONE>, which will make the innermost C<ev_run> call return, or |
818 | C<EVBREAK_ALL>, which will make all nested C<ev_run> calls return. |
877 | C<EVBREAK_ALL>, which will make all nested C<ev_run> calls return. |
819 | |
878 | |
820 | This "unloop state" will be cleared when entering C<ev_run> again. |
879 | This "break state" will be cleared on the next call to C<ev_run>. |
821 | |
880 | |
822 | It is safe to call C<ev_break> from outside any C<ev_run> calls. ##TODO## |
881 | It is safe to call C<ev_break> from outside any C<ev_run> calls, too, in |
|
|
882 | which case it will have no effect. |
823 | |
883 | |
824 | =item ev_ref (loop) |
884 | =item ev_ref (loop) |
825 | |
885 | |
826 | =item ev_unref (loop) |
886 | =item ev_unref (loop) |
827 | |
887 | |
… | |
… | |
848 | running when nothing else is active. |
908 | running when nothing else is active. |
849 | |
909 | |
850 | ev_signal exitsig; |
910 | ev_signal exitsig; |
851 | ev_signal_init (&exitsig, sig_cb, SIGINT); |
911 | ev_signal_init (&exitsig, sig_cb, SIGINT); |
852 | ev_signal_start (loop, &exitsig); |
912 | ev_signal_start (loop, &exitsig); |
853 | evf_unref (loop); |
913 | ev_unref (loop); |
854 | |
914 | |
855 | Example: For some weird reason, unregister the above signal handler again. |
915 | Example: For some weird reason, unregister the above signal handler again. |
856 | |
916 | |
857 | ev_ref (loop); |
917 | ev_ref (loop); |
858 | ev_signal_stop (loop, &exitsig); |
918 | ev_signal_stop (loop, &exitsig); |
… | |
… | |
970 | See also the locking example in the C<THREADS> section later in this |
1030 | See also the locking example in the C<THREADS> section later in this |
971 | document. |
1031 | document. |
972 | |
1032 | |
973 | =item ev_set_userdata (loop, void *data) |
1033 | =item ev_set_userdata (loop, void *data) |
974 | |
1034 | |
975 | =item ev_userdata (loop) |
1035 | =item void *ev_userdata (loop) |
976 | |
1036 | |
977 | Set and retrieve a single C<void *> associated with a loop. When |
1037 | Set and retrieve a single C<void *> associated with a loop. When |
978 | C<ev_set_userdata> has never been called, then C<ev_userdata> returns |
1038 | C<ev_set_userdata> has never been called, then C<ev_userdata> returns |
979 | C<0.> |
1039 | C<0>. |
980 | |
1040 | |
981 | These two functions can be used to associate arbitrary data with a loop, |
1041 | These two functions can be used to associate arbitrary data with a loop, |
982 | and are intended solely for the C<invoke_pending_cb>, C<release> and |
1042 | and are intended solely for the C<invoke_pending_cb>, C<release> and |
983 | C<acquire> callbacks described above, but of course can be (ab-)used for |
1043 | C<acquire> callbacks described above, but of course can be (ab-)used for |
984 | any other purpose as well. |
1044 | any other purpose as well. |
… | |
… | |
1114 | The event loop has been resumed in the child process after fork (see |
1174 | The event loop has been resumed in the child process after fork (see |
1115 | C<ev_fork>). |
1175 | C<ev_fork>). |
1116 | |
1176 | |
1117 | =item C<EV_CLEANUP> |
1177 | =item C<EV_CLEANUP> |
1118 | |
1178 | |
1119 | The event loop is abotu to be destroyed (see C<ev_cleanup>). |
1179 | The event loop is about to be destroyed (see C<ev_cleanup>). |
1120 | |
1180 | |
1121 | =item C<EV_ASYNC> |
1181 | =item C<EV_ASYNC> |
1122 | |
1182 | |
1123 | The given async watcher has been asynchronously notified (see C<ev_async>). |
1183 | The given async watcher has been asynchronously notified (see C<ev_async>). |
1124 | |
1184 | |
… | |
… | |
1146 | programs, though, as the fd could already be closed and reused for another |
1206 | programs, though, as the fd could already be closed and reused for another |
1147 | thing, so beware. |
1207 | thing, so beware. |
1148 | |
1208 | |
1149 | =back |
1209 | =back |
1150 | |
1210 | |
1151 | =head2 WATCHER STATES |
|
|
1152 | |
|
|
1153 | There are various watcher states mentioned throughout this manual - |
|
|
1154 | active, pending and so on. In this section these states and the rules to |
|
|
1155 | transition between them will be described in more detail - and while these |
|
|
1156 | rules might look complicated, they usually do "the right thing". |
|
|
1157 | |
|
|
1158 | =over 4 |
|
|
1159 | |
|
|
1160 | =item initialiased |
|
|
1161 | |
|
|
1162 | Before a watcher can be registered with the event looop it has to be |
|
|
1163 | initialised. This can be done with a call to C<ev_TYPE_init>, or calls to |
|
|
1164 | C<ev_init> followed by the watcher-specific C<ev_TYPE_set> function. |
|
|
1165 | |
|
|
1166 | In this state it is simply some block of memory that is suitable for use |
|
|
1167 | in an event loop. It can be moved around, freed, reused etc. at will. |
|
|
1168 | |
|
|
1169 | =item started/running/active |
|
|
1170 | |
|
|
1171 | Once a watcher has been started with a call to C<ev_TYPE_start> it becomes |
|
|
1172 | property of the event loop, and is actively waiting for events. While in |
|
|
1173 | this state it cannot be accessed (except in a few documented ways), moved, |
|
|
1174 | freed or anything else - the only legal thing is to keep a pointer to it, |
|
|
1175 | and call libev functions on it that are documented to work on active watchers. |
|
|
1176 | |
|
|
1177 | =item pending |
|
|
1178 | |
|
|
1179 | If a watcher is active and libev determines that an event it is interested |
|
|
1180 | in has occurred (such as a timer expiring), it will become pending. It will |
|
|
1181 | stay in this pending state until either it is stopped or its callback is |
|
|
1182 | about to be invoked, so it is not normally pending inside the watcher |
|
|
1183 | callback. |
|
|
1184 | |
|
|
1185 | The watcher might or might not be active while it is pending (for example, |
|
|
1186 | an expired non-repeating timer can be pending but no longer active). If it |
|
|
1187 | is stopped, it can be freely accessed (e.g. by calling C<ev_TYPE_set>), |
|
|
1188 | but it is still property of the event loop at this time, so cannot be |
|
|
1189 | moved, freed or reused. And if it is active the rules described in the |
|
|
1190 | previous item still apply. |
|
|
1191 | |
|
|
1192 | It is also possible to feed an event on a watcher that is not active (e.g. |
|
|
1193 | via C<ev_feed_event>), in which case it becomes pending without being |
|
|
1194 | active. |
|
|
1195 | |
|
|
1196 | =item stopped |
|
|
1197 | |
|
|
1198 | A watcher can be stopped implicitly by libev (in which case it might still |
|
|
1199 | be pending), or explicitly by calling its C<ev_TYPE_stop> function. The |
|
|
1200 | latter will clear any pending state the watcher might be in, regardless |
|
|
1201 | of whether it was active or not, so stopping a watcher explicitly before |
|
|
1202 | freeing it is often a good idea. |
|
|
1203 | |
|
|
1204 | While stopped (and not pending) the watcher is essentially in the |
|
|
1205 | initialised state, that is it can be reused, moved, modified in any way |
|
|
1206 | you wish. |
|
|
1207 | |
|
|
1208 | =back |
|
|
1209 | |
|
|
1210 | =head2 GENERIC WATCHER FUNCTIONS |
1211 | =head2 GENERIC WATCHER FUNCTIONS |
1211 | |
1212 | |
1212 | =over 4 |
1213 | =over 4 |
1213 | |
1214 | |
1214 | =item C<ev_init> (ev_TYPE *watcher, callback) |
1215 | =item C<ev_init> (ev_TYPE *watcher, callback) |
… | |
… | |
1355 | |
1356 | |
1356 | See also C<ev_feed_fd_event> and C<ev_feed_signal_event> for related |
1357 | See also C<ev_feed_fd_event> and C<ev_feed_signal_event> for related |
1357 | functions that do not need a watcher. |
1358 | functions that do not need a watcher. |
1358 | |
1359 | |
1359 | =back |
1360 | =back |
1360 | |
|
|
1361 | |
1361 | |
1362 | =head2 ASSOCIATING CUSTOM DATA WITH A WATCHER |
1362 | =head2 ASSOCIATING CUSTOM DATA WITH A WATCHER |
1363 | |
1363 | |
1364 | Each watcher has, by default, a member C<void *data> that you can change |
1364 | Each watcher has, by default, a member C<void *data> that you can change |
1365 | and read at any time: libev will completely ignore it. This can be used |
1365 | and read at any time: libev will completely ignore it. This can be used |
… | |
… | |
1421 | t2_cb (EV_P_ ev_timer *w, int revents) |
1421 | t2_cb (EV_P_ ev_timer *w, int revents) |
1422 | { |
1422 | { |
1423 | struct my_biggy big = (struct my_biggy *) |
1423 | struct my_biggy big = (struct my_biggy *) |
1424 | (((char *)w) - offsetof (struct my_biggy, t2)); |
1424 | (((char *)w) - offsetof (struct my_biggy, t2)); |
1425 | } |
1425 | } |
|
|
1426 | |
|
|
1427 | =head2 WATCHER STATES |
|
|
1428 | |
|
|
1429 | There are various watcher states mentioned throughout this manual - |
|
|
1430 | active, pending and so on. In this section these states and the rules to |
|
|
1431 | transition between them will be described in more detail - and while these |
|
|
1432 | rules might look complicated, they usually do "the right thing". |
|
|
1433 | |
|
|
1434 | =over 4 |
|
|
1435 | |
|
|
1436 | =item initialiased |
|
|
1437 | |
|
|
1438 | Before a watcher can be registered with the event looop it has to be |
|
|
1439 | initialised. This can be done with a call to C<ev_TYPE_init>, or calls to |
|
|
1440 | C<ev_init> followed by the watcher-specific C<ev_TYPE_set> function. |
|
|
1441 | |
|
|
1442 | In this state it is simply some block of memory that is suitable for use |
|
|
1443 | in an event loop. It can be moved around, freed, reused etc. at will. |
|
|
1444 | |
|
|
1445 | =item started/running/active |
|
|
1446 | |
|
|
1447 | Once a watcher has been started with a call to C<ev_TYPE_start> it becomes |
|
|
1448 | property of the event loop, and is actively waiting for events. While in |
|
|
1449 | this state it cannot be accessed (except in a few documented ways), moved, |
|
|
1450 | freed or anything else - the only legal thing is to keep a pointer to it, |
|
|
1451 | and call libev functions on it that are documented to work on active watchers. |
|
|
1452 | |
|
|
1453 | =item pending |
|
|
1454 | |
|
|
1455 | If a watcher is active and libev determines that an event it is interested |
|
|
1456 | in has occurred (such as a timer expiring), it will become pending. It will |
|
|
1457 | stay in this pending state until either it is stopped or its callback is |
|
|
1458 | about to be invoked, so it is not normally pending inside the watcher |
|
|
1459 | callback. |
|
|
1460 | |
|
|
1461 | The watcher might or might not be active while it is pending (for example, |
|
|
1462 | an expired non-repeating timer can be pending but no longer active). If it |
|
|
1463 | is stopped, it can be freely accessed (e.g. by calling C<ev_TYPE_set>), |
|
|
1464 | but it is still property of the event loop at this time, so cannot be |
|
|
1465 | moved, freed or reused. And if it is active the rules described in the |
|
|
1466 | previous item still apply. |
|
|
1467 | |
|
|
1468 | It is also possible to feed an event on a watcher that is not active (e.g. |
|
|
1469 | via C<ev_feed_event>), in which case it becomes pending without being |
|
|
1470 | active. |
|
|
1471 | |
|
|
1472 | =item stopped |
|
|
1473 | |
|
|
1474 | A watcher can be stopped implicitly by libev (in which case it might still |
|
|
1475 | be pending), or explicitly by calling its C<ev_TYPE_stop> function. The |
|
|
1476 | latter will clear any pending state the watcher might be in, regardless |
|
|
1477 | of whether it was active or not, so stopping a watcher explicitly before |
|
|
1478 | freeing it is often a good idea. |
|
|
1479 | |
|
|
1480 | While stopped (and not pending) the watcher is essentially in the |
|
|
1481 | initialised state, that is it can be reused, moved, modified in any way |
|
|
1482 | you wish. |
|
|
1483 | |
|
|
1484 | =back |
1426 | |
1485 | |
1427 | =head2 WATCHER PRIORITY MODELS |
1486 | =head2 WATCHER PRIORITY MODELS |
1428 | |
1487 | |
1429 | Many event loops support I<watcher priorities>, which are usually small |
1488 | Many event loops support I<watcher priorities>, which are usually small |
1430 | integers that influence the ordering of event callback invocation |
1489 | integers that influence the ordering of event callback invocation |
… | |
… | |
1557 | In general you can register as many read and/or write event watchers per |
1616 | In general you can register as many read and/or write event watchers per |
1558 | fd as you want (as long as you don't confuse yourself). Setting all file |
1617 | fd as you want (as long as you don't confuse yourself). Setting all file |
1559 | descriptors to non-blocking mode is also usually a good idea (but not |
1618 | descriptors to non-blocking mode is also usually a good idea (but not |
1560 | required if you know what you are doing). |
1619 | required if you know what you are doing). |
1561 | |
1620 | |
1562 | If you cannot use non-blocking mode, then force the use of a |
|
|
1563 | known-to-be-good backend (at the time of this writing, this includes only |
|
|
1564 | C<EVBACKEND_SELECT> and C<EVBACKEND_POLL>). The same applies to file |
|
|
1565 | descriptors for which non-blocking operation makes no sense (such as |
|
|
1566 | files) - libev doesn't guarantee any specific behaviour in that case. |
|
|
1567 | |
|
|
1568 | Another thing you have to watch out for is that it is quite easy to |
1621 | Another thing you have to watch out for is that it is quite easy to |
1569 | receive "spurious" readiness notifications, that is your callback might |
1622 | receive "spurious" readiness notifications, that is, your callback might |
1570 | be called with C<EV_READ> but a subsequent C<read>(2) will actually block |
1623 | be called with C<EV_READ> but a subsequent C<read>(2) will actually block |
1571 | because there is no data. Not only are some backends known to create a |
1624 | because there is no data. It is very easy to get into this situation even |
1572 | lot of those (for example Solaris ports), it is very easy to get into |
1625 | with a relatively standard program structure. Thus it is best to always |
1573 | this situation even with a relatively standard program structure. Thus |
1626 | use non-blocking I/O: An extra C<read>(2) returning C<EAGAIN> is far |
1574 | it is best to always use non-blocking I/O: An extra C<read>(2) returning |
|
|
1575 | C<EAGAIN> is far preferable to a program hanging until some data arrives. |
1627 | preferable to a program hanging until some data arrives. |
1576 | |
1628 | |
1577 | If you cannot run the fd in non-blocking mode (for example you should |
1629 | If you cannot run the fd in non-blocking mode (for example you should |
1578 | not play around with an Xlib connection), then you have to separately |
1630 | not play around with an Xlib connection), then you have to separately |
1579 | re-test whether a file descriptor is really ready with a known-to-be good |
1631 | re-test whether a file descriptor is really ready with a known-to-be good |
1580 | interface such as poll (fortunately in our Xlib example, Xlib already |
1632 | interface such as poll (fortunately in the case of Xlib, it already does |
1581 | does this on its own, so its quite safe to use). Some people additionally |
1633 | this on its own, so its quite safe to use). Some people additionally |
1582 | use C<SIGALRM> and an interval timer, just to be sure you won't block |
1634 | use C<SIGALRM> and an interval timer, just to be sure you won't block |
1583 | indefinitely. |
1635 | indefinitely. |
1584 | |
1636 | |
1585 | But really, best use non-blocking mode. |
1637 | But really, best use non-blocking mode. |
1586 | |
1638 | |
… | |
… | |
1614 | |
1666 | |
1615 | There is no workaround possible except not registering events |
1667 | There is no workaround possible except not registering events |
1616 | for potentially C<dup ()>'ed file descriptors, or to resort to |
1668 | for potentially C<dup ()>'ed file descriptors, or to resort to |
1617 | C<EVBACKEND_SELECT> or C<EVBACKEND_POLL>. |
1669 | C<EVBACKEND_SELECT> or C<EVBACKEND_POLL>. |
1618 | |
1670 | |
|
|
1671 | =head3 The special problem of files |
|
|
1672 | |
|
|
1673 | Many people try to use C<select> (or libev) on file descriptors |
|
|
1674 | representing files, and expect it to become ready when their program |
|
|
1675 | doesn't block on disk accesses (which can take a long time on their own). |
|
|
1676 | |
|
|
1677 | However, this cannot ever work in the "expected" way - you get a readiness |
|
|
1678 | notification as soon as the kernel knows whether and how much data is |
|
|
1679 | there, and in the case of open files, that's always the case, so you |
|
|
1680 | always get a readiness notification instantly, and your read (or possibly |
|
|
1681 | write) will still block on the disk I/O. |
|
|
1682 | |
|
|
1683 | Another way to view it is that in the case of sockets, pipes, character |
|
|
1684 | devices and so on, there is another party (the sender) that delivers data |
|
|
1685 | on it's own, but in the case of files, there is no such thing: the disk |
|
|
1686 | will not send data on it's own, simply because it doesn't know what you |
|
|
1687 | wish to read - you would first have to request some data. |
|
|
1688 | |
|
|
1689 | Since files are typically not-so-well supported by advanced notification |
|
|
1690 | mechanism, libev tries hard to emulate POSIX behaviour with respect |
|
|
1691 | to files, even though you should not use it. The reason for this is |
|
|
1692 | convenience: sometimes you want to watch STDIN or STDOUT, which is |
|
|
1693 | usually a tty, often a pipe, but also sometimes files or special devices |
|
|
1694 | (for example, C<epoll> on Linux works with F</dev/random> but not with |
|
|
1695 | F</dev/urandom>), and even though the file might better be served with |
|
|
1696 | asynchronous I/O instead of with non-blocking I/O, it is still useful when |
|
|
1697 | it "just works" instead of freezing. |
|
|
1698 | |
|
|
1699 | So avoid file descriptors pointing to files when you know it (e.g. use |
|
|
1700 | libeio), but use them when it is convenient, e.g. for STDIN/STDOUT, or |
|
|
1701 | when you rarely read from a file instead of from a socket, and want to |
|
|
1702 | reuse the same code path. |
|
|
1703 | |
1619 | =head3 The special problem of fork |
1704 | =head3 The special problem of fork |
1620 | |
1705 | |
1621 | Some backends (epoll, kqueue) do not support C<fork ()> at all or exhibit |
1706 | Some backends (epoll, kqueue) do not support C<fork ()> at all or exhibit |
1622 | useless behaviour. Libev fully supports fork, but needs to be told about |
1707 | useless behaviour. Libev fully supports fork, but needs to be told about |
1623 | it in the child. |
1708 | it in the child if you want to continue to use it in the child. |
1624 | |
1709 | |
1625 | To support fork in your programs, you either have to call |
1710 | To support fork in your child processes, you have to call C<ev_loop_fork |
1626 | C<ev_default_fork ()> or C<ev_loop_fork ()> after a fork in the child, |
1711 | ()> after a fork in the child, enable C<EVFLAG_FORKCHECK>, or resort to |
1627 | enable C<EVFLAG_FORKCHECK>, or resort to C<EVBACKEND_SELECT> or |
1712 | C<EVBACKEND_SELECT> or C<EVBACKEND_POLL>. |
1628 | C<EVBACKEND_POLL>. |
|
|
1629 | |
1713 | |
1630 | =head3 The special problem of SIGPIPE |
1714 | =head3 The special problem of SIGPIPE |
1631 | |
1715 | |
1632 | While not really specific to libev, it is easy to forget about C<SIGPIPE>: |
1716 | While not really specific to libev, it is easy to forget about C<SIGPIPE>: |
1633 | when writing to a pipe whose other end has been closed, your program gets |
1717 | when writing to a pipe whose other end has been closed, your program gets |
… | |
… | |
2249 | |
2333 | |
2250 | =head2 C<ev_signal> - signal me when a signal gets signalled! |
2334 | =head2 C<ev_signal> - signal me when a signal gets signalled! |
2251 | |
2335 | |
2252 | Signal watchers will trigger an event when the process receives a specific |
2336 | Signal watchers will trigger an event when the process receives a specific |
2253 | signal one or more times. Even though signals are very asynchronous, libev |
2337 | signal one or more times. Even though signals are very asynchronous, libev |
2254 | will try it's best to deliver signals synchronously, i.e. as part of the |
2338 | will try its best to deliver signals synchronously, i.e. as part of the |
2255 | normal event processing, like any other event. |
2339 | normal event processing, like any other event. |
2256 | |
2340 | |
2257 | If you want signals to be delivered truly asynchronously, just use |
2341 | If you want signals to be delivered truly asynchronously, just use |
2258 | C<sigaction> as you would do without libev and forget about sharing |
2342 | C<sigaction> as you would do without libev and forget about sharing |
2259 | the signal. You can even use C<ev_async> from a signal handler to |
2343 | the signal. You can even use C<ev_async> from a signal handler to |
… | |
… | |
2301 | I<has> to modify the signal mask, at least temporarily. |
2385 | I<has> to modify the signal mask, at least temporarily. |
2302 | |
2386 | |
2303 | So I can't stress this enough: I<If you do not reset your signal mask when |
2387 | So I can't stress this enough: I<If you do not reset your signal mask when |
2304 | you expect it to be empty, you have a race condition in your code>. This |
2388 | you expect it to be empty, you have a race condition in your code>. This |
2305 | is not a libev-specific thing, this is true for most event libraries. |
2389 | is not a libev-specific thing, this is true for most event libraries. |
|
|
2390 | |
|
|
2391 | =head3 The special problem of threads signal handling |
|
|
2392 | |
|
|
2393 | POSIX threads has problematic signal handling semantics, specifically, |
|
|
2394 | a lot of functionality (sigfd, sigwait etc.) only really works if all |
|
|
2395 | threads in a process block signals, which is hard to achieve. |
|
|
2396 | |
|
|
2397 | When you want to use sigwait (or mix libev signal handling with your own |
|
|
2398 | for the same signals), you can tackle this problem by globally blocking |
|
|
2399 | all signals before creating any threads (or creating them with a fully set |
|
|
2400 | sigprocmask) and also specifying the C<EVFLAG_NOSIGMASK> when creating |
|
|
2401 | loops. Then designate one thread as "signal receiver thread" which handles |
|
|
2402 | these signals. You can pass on any signals that libev might be interested |
|
|
2403 | in by calling C<ev_feed_signal>. |
2306 | |
2404 | |
2307 | =head3 Watcher-Specific Functions and Data Members |
2405 | =head3 Watcher-Specific Functions and Data Members |
2308 | |
2406 | |
2309 | =over 4 |
2407 | =over 4 |
2310 | |
2408 | |
… | |
… | |
3098 | |
3196 | |
3099 | =item ev_fork_init (ev_fork *, callback) |
3197 | =item ev_fork_init (ev_fork *, callback) |
3100 | |
3198 | |
3101 | Initialises and configures the fork watcher - it has no parameters of any |
3199 | Initialises and configures the fork watcher - it has no parameters of any |
3102 | kind. There is a C<ev_fork_set> macro, but using it is utterly pointless, |
3200 | kind. There is a C<ev_fork_set> macro, but using it is utterly pointless, |
3103 | believe me. |
3201 | really. |
3104 | |
3202 | |
3105 | =back |
3203 | =back |
3106 | |
3204 | |
3107 | |
3205 | |
3108 | =head2 C<ev_cleanup> - even the best things end |
3206 | =head2 C<ev_cleanup> - even the best things end |
3109 | |
3207 | |
3110 | Cleanup watchers are called just before the event loop they are registered |
3208 | Cleanup watchers are called just before the event loop is being destroyed |
3111 | with is being destroyed. |
3209 | by a call to C<ev_loop_destroy>. |
3112 | |
3210 | |
3113 | While there is no guarantee that the event loop gets destroyed, cleanup |
3211 | While there is no guarantee that the event loop gets destroyed, cleanup |
3114 | watchers provide a convenient method to install cleanup watchers for your |
3212 | watchers provide a convenient method to install cleanup hooks for your |
3115 | program, worker threads and so on - you just to make sure to destroy the |
3213 | program, worker threads and so on - you just to make sure to destroy the |
3116 | loop when you want them to be invoked. |
3214 | loop when you want them to be invoked. |
3117 | |
3215 | |
|
|
3216 | Cleanup watchers are invoked in the same way as any other watcher. Unlike |
|
|
3217 | all other watchers, they do not keep a reference to the event loop (which |
|
|
3218 | makes a lot of sense if you think about it). Like all other watchers, you |
|
|
3219 | can call libev functions in the callback, except C<ev_cleanup_start>. |
|
|
3220 | |
3118 | =head3 Watcher-Specific Functions and Data Members |
3221 | =head3 Watcher-Specific Functions and Data Members |
3119 | |
3222 | |
3120 | =over 4 |
3223 | =over 4 |
3121 | |
3224 | |
3122 | =item ev_cleanup_init (ev_cleanup *, callback) |
3225 | =item ev_cleanup_init (ev_cleanup *, callback) |
3123 | |
3226 | |
3124 | Initialises and configures the cleanup watcher - it has no parameters of |
3227 | Initialises and configures the cleanup watcher - it has no parameters of |
3125 | any kind. There is a C<ev_cleanup_set> macro, but using it is utterly |
3228 | any kind. There is a C<ev_cleanup_set> macro, but using it is utterly |
3126 | pointless, believe me. |
3229 | pointless, I assure you. |
3127 | |
3230 | |
3128 | =back |
3231 | =back |
3129 | |
3232 | |
3130 | Example: Register an atexit handler to destroy the default loop, so any |
3233 | Example: Register an atexit handler to destroy the default loop, so any |
3131 | cleanup functions are called. |
3234 | cleanup functions are called. |
… | |
… | |
3152 | it by calling C<ev_async_send>, which is thread- and signal safe. |
3255 | it by calling C<ev_async_send>, which is thread- and signal safe. |
3153 | |
3256 | |
3154 | This functionality is very similar to C<ev_signal> watchers, as signals, |
3257 | This functionality is very similar to C<ev_signal> watchers, as signals, |
3155 | too, are asynchronous in nature, and signals, too, will be compressed |
3258 | too, are asynchronous in nature, and signals, too, will be compressed |
3156 | (i.e. the number of callback invocations may be less than the number of |
3259 | (i.e. the number of callback invocations may be less than the number of |
3157 | C<ev_async_sent> calls). |
3260 | C<ev_async_sent> calls). In fact, you could use signal watchers as a kind |
|
|
3261 | of "global async watchers" by using a watcher on an otherwise unused |
|
|
3262 | signal, and C<ev_feed_signal> to signal this watcher from another thread, |
|
|
3263 | even without knowing which loop owns the signal. |
3158 | |
3264 | |
3159 | Unlike C<ev_signal> watchers, C<ev_async> works with any event loop, not |
3265 | Unlike C<ev_signal> watchers, C<ev_async> works with any event loop, not |
3160 | just the default loop. |
3266 | just the default loop. |
3161 | |
3267 | |
3162 | =head3 Queueing |
3268 | =head3 Queueing |
… | |
… | |
3338 | Feed an event on the given fd, as if a file descriptor backend detected |
3444 | Feed an event on the given fd, as if a file descriptor backend detected |
3339 | the given events it. |
3445 | the given events it. |
3340 | |
3446 | |
3341 | =item ev_feed_signal_event (loop, int signum) |
3447 | =item ev_feed_signal_event (loop, int signum) |
3342 | |
3448 | |
3343 | Feed an event as if the given signal occurred (C<loop> must be the default |
3449 | Feed an event as if the given signal occurred. See also C<ev_feed_signal>, |
3344 | loop!). |
3450 | which is async-safe. |
|
|
3451 | |
|
|
3452 | =back |
|
|
3453 | |
|
|
3454 | |
|
|
3455 | =head1 COMMON OR USEFUL IDIOMS (OR BOTH) |
|
|
3456 | |
|
|
3457 | This section explains some common idioms that are not immediately |
|
|
3458 | obvious. Note that examples are sprinkled over the whole manual, and this |
|
|
3459 | section only contains stuff that wouldn't fit anywhere else. |
|
|
3460 | |
|
|
3461 | =over 4 |
|
|
3462 | |
|
|
3463 | =item Model/nested event loop invocations and exit conditions. |
|
|
3464 | |
|
|
3465 | Often (especially in GUI toolkits) there are places where you have |
|
|
3466 | I<modal> interaction, which is most easily implemented by recursively |
|
|
3467 | invoking C<ev_run>. |
|
|
3468 | |
|
|
3469 | This brings the problem of exiting - a callback might want to finish the |
|
|
3470 | main C<ev_run> call, but not the nested one (e.g. user clicked "Quit", but |
|
|
3471 | a modal "Are you sure?" dialog is still waiting), or just the nested one |
|
|
3472 | and not the main one (e.g. user clocked "Ok" in a modal dialog), or some |
|
|
3473 | other combination: In these cases, C<ev_break> will not work alone. |
|
|
3474 | |
|
|
3475 | The solution is to maintain "break this loop" variable for each C<ev_run> |
|
|
3476 | invocation, and use a loop around C<ev_run> until the condition is |
|
|
3477 | triggered, using C<EVRUN_ONCE>: |
|
|
3478 | |
|
|
3479 | // main loop |
|
|
3480 | int exit_main_loop = 0; |
|
|
3481 | |
|
|
3482 | while (!exit_main_loop) |
|
|
3483 | ev_run (EV_DEFAULT_ EVRUN_ONCE); |
|
|
3484 | |
|
|
3485 | // in a model watcher |
|
|
3486 | int exit_nested_loop = 0; |
|
|
3487 | |
|
|
3488 | while (!exit_nested_loop) |
|
|
3489 | ev_run (EV_A_ EVRUN_ONCE); |
|
|
3490 | |
|
|
3491 | To exit from any of these loops, just set the corresponding exit variable: |
|
|
3492 | |
|
|
3493 | // exit modal loop |
|
|
3494 | exit_nested_loop = 1; |
|
|
3495 | |
|
|
3496 | // exit main program, after modal loop is finished |
|
|
3497 | exit_main_loop = 1; |
|
|
3498 | |
|
|
3499 | // exit both |
|
|
3500 | exit_main_loop = exit_nested_loop = 1; |
|
|
3501 | |
|
|
3502 | =item Thread locking example |
|
|
3503 | |
|
|
3504 | Here is a fictitious example of how to run an event loop in a different |
|
|
3505 | thread than where callbacks are being invoked and watchers are |
|
|
3506 | created/added/removed. |
|
|
3507 | |
|
|
3508 | For a real-world example, see the C<EV::Loop::Async> perl module, |
|
|
3509 | which uses exactly this technique (which is suited for many high-level |
|
|
3510 | languages). |
|
|
3511 | |
|
|
3512 | The example uses a pthread mutex to protect the loop data, a condition |
|
|
3513 | variable to wait for callback invocations, an async watcher to notify the |
|
|
3514 | event loop thread and an unspecified mechanism to wake up the main thread. |
|
|
3515 | |
|
|
3516 | First, you need to associate some data with the event loop: |
|
|
3517 | |
|
|
3518 | typedef struct { |
|
|
3519 | mutex_t lock; /* global loop lock */ |
|
|
3520 | ev_async async_w; |
|
|
3521 | thread_t tid; |
|
|
3522 | cond_t invoke_cv; |
|
|
3523 | } userdata; |
|
|
3524 | |
|
|
3525 | void prepare_loop (EV_P) |
|
|
3526 | { |
|
|
3527 | // for simplicity, we use a static userdata struct. |
|
|
3528 | static userdata u; |
|
|
3529 | |
|
|
3530 | ev_async_init (&u->async_w, async_cb); |
|
|
3531 | ev_async_start (EV_A_ &u->async_w); |
|
|
3532 | |
|
|
3533 | pthread_mutex_init (&u->lock, 0); |
|
|
3534 | pthread_cond_init (&u->invoke_cv, 0); |
|
|
3535 | |
|
|
3536 | // now associate this with the loop |
|
|
3537 | ev_set_userdata (EV_A_ u); |
|
|
3538 | ev_set_invoke_pending_cb (EV_A_ l_invoke); |
|
|
3539 | ev_set_loop_release_cb (EV_A_ l_release, l_acquire); |
|
|
3540 | |
|
|
3541 | // then create the thread running ev_loop |
|
|
3542 | pthread_create (&u->tid, 0, l_run, EV_A); |
|
|
3543 | } |
|
|
3544 | |
|
|
3545 | The callback for the C<ev_async> watcher does nothing: the watcher is used |
|
|
3546 | solely to wake up the event loop so it takes notice of any new watchers |
|
|
3547 | that might have been added: |
|
|
3548 | |
|
|
3549 | static void |
|
|
3550 | async_cb (EV_P_ ev_async *w, int revents) |
|
|
3551 | { |
|
|
3552 | // just used for the side effects |
|
|
3553 | } |
|
|
3554 | |
|
|
3555 | The C<l_release> and C<l_acquire> callbacks simply unlock/lock the mutex |
|
|
3556 | protecting the loop data, respectively. |
|
|
3557 | |
|
|
3558 | static void |
|
|
3559 | l_release (EV_P) |
|
|
3560 | { |
|
|
3561 | userdata *u = ev_userdata (EV_A); |
|
|
3562 | pthread_mutex_unlock (&u->lock); |
|
|
3563 | } |
|
|
3564 | |
|
|
3565 | static void |
|
|
3566 | l_acquire (EV_P) |
|
|
3567 | { |
|
|
3568 | userdata *u = ev_userdata (EV_A); |
|
|
3569 | pthread_mutex_lock (&u->lock); |
|
|
3570 | } |
|
|
3571 | |
|
|
3572 | The event loop thread first acquires the mutex, and then jumps straight |
|
|
3573 | into C<ev_run>: |
|
|
3574 | |
|
|
3575 | void * |
|
|
3576 | l_run (void *thr_arg) |
|
|
3577 | { |
|
|
3578 | struct ev_loop *loop = (struct ev_loop *)thr_arg; |
|
|
3579 | |
|
|
3580 | l_acquire (EV_A); |
|
|
3581 | pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0); |
|
|
3582 | ev_run (EV_A_ 0); |
|
|
3583 | l_release (EV_A); |
|
|
3584 | |
|
|
3585 | return 0; |
|
|
3586 | } |
|
|
3587 | |
|
|
3588 | Instead of invoking all pending watchers, the C<l_invoke> callback will |
|
|
3589 | signal the main thread via some unspecified mechanism (signals? pipe |
|
|
3590 | writes? C<Async::Interrupt>?) and then waits until all pending watchers |
|
|
3591 | have been called (in a while loop because a) spurious wakeups are possible |
|
|
3592 | and b) skipping inter-thread-communication when there are no pending |
|
|
3593 | watchers is very beneficial): |
|
|
3594 | |
|
|
3595 | static void |
|
|
3596 | l_invoke (EV_P) |
|
|
3597 | { |
|
|
3598 | userdata *u = ev_userdata (EV_A); |
|
|
3599 | |
|
|
3600 | while (ev_pending_count (EV_A)) |
|
|
3601 | { |
|
|
3602 | wake_up_other_thread_in_some_magic_or_not_so_magic_way (); |
|
|
3603 | pthread_cond_wait (&u->invoke_cv, &u->lock); |
|
|
3604 | } |
|
|
3605 | } |
|
|
3606 | |
|
|
3607 | Now, whenever the main thread gets told to invoke pending watchers, it |
|
|
3608 | will grab the lock, call C<ev_invoke_pending> and then signal the loop |
|
|
3609 | thread to continue: |
|
|
3610 | |
|
|
3611 | static void |
|
|
3612 | real_invoke_pending (EV_P) |
|
|
3613 | { |
|
|
3614 | userdata *u = ev_userdata (EV_A); |
|
|
3615 | |
|
|
3616 | pthread_mutex_lock (&u->lock); |
|
|
3617 | ev_invoke_pending (EV_A); |
|
|
3618 | pthread_cond_signal (&u->invoke_cv); |
|
|
3619 | pthread_mutex_unlock (&u->lock); |
|
|
3620 | } |
|
|
3621 | |
|
|
3622 | Whenever you want to start/stop a watcher or do other modifications to an |
|
|
3623 | event loop, you will now have to lock: |
|
|
3624 | |
|
|
3625 | ev_timer timeout_watcher; |
|
|
3626 | userdata *u = ev_userdata (EV_A); |
|
|
3627 | |
|
|
3628 | ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.); |
|
|
3629 | |
|
|
3630 | pthread_mutex_lock (&u->lock); |
|
|
3631 | ev_timer_start (EV_A_ &timeout_watcher); |
|
|
3632 | ev_async_send (EV_A_ &u->async_w); |
|
|
3633 | pthread_mutex_unlock (&u->lock); |
|
|
3634 | |
|
|
3635 | Note that sending the C<ev_async> watcher is required because otherwise |
|
|
3636 | an event loop currently blocking in the kernel will have no knowledge |
|
|
3637 | about the newly added timer. By waking up the loop it will pick up any new |
|
|
3638 | watchers in the next event loop iteration. |
3345 | |
3639 | |
3346 | =back |
3640 | =back |
3347 | |
3641 | |
3348 | |
3642 | |
3349 | =head1 LIBEVENT EMULATION |
3643 | =head1 LIBEVENT EMULATION |
3350 | |
3644 | |
3351 | Libev offers a compatibility emulation layer for libevent. It cannot |
3645 | Libev offers a compatibility emulation layer for libevent. It cannot |
3352 | emulate the internals of libevent, so here are some usage hints: |
3646 | emulate the internals of libevent, so here are some usage hints: |
3353 | |
3647 | |
3354 | =over 4 |
3648 | =over 4 |
|
|
3649 | |
|
|
3650 | =item * Only the libevent-1.4.1-beta API is being emulated. |
|
|
3651 | |
|
|
3652 | This was the newest libevent version available when libev was implemented, |
|
|
3653 | and is still mostly unchanged in 2010. |
3355 | |
3654 | |
3356 | =item * Use it by including <event.h>, as usual. |
3655 | =item * Use it by including <event.h>, as usual. |
3357 | |
3656 | |
3358 | =item * The following members are fully supported: ev_base, ev_callback, |
3657 | =item * The following members are fully supported: ev_base, ev_callback, |
3359 | ev_arg, ev_fd, ev_res, ev_events. |
3658 | ev_arg, ev_fd, ev_res, ev_events. |
… | |
… | |
3365 | =item * Priorities are not currently supported. Initialising priorities |
3664 | =item * Priorities are not currently supported. Initialising priorities |
3366 | will fail and all watchers will have the same priority, even though there |
3665 | will fail and all watchers will have the same priority, even though there |
3367 | is an ev_pri field. |
3666 | is an ev_pri field. |
3368 | |
3667 | |
3369 | =item * In libevent, the last base created gets the signals, in libev, the |
3668 | =item * In libevent, the last base created gets the signals, in libev, the |
3370 | first base created (== the default loop) gets the signals. |
3669 | base that registered the signal gets the signals. |
3371 | |
3670 | |
3372 | =item * Other members are not supported. |
3671 | =item * Other members are not supported. |
3373 | |
3672 | |
3374 | =item * The libev emulation is I<not> ABI compatible to libevent, you need |
3673 | =item * The libev emulation is I<not> ABI compatible to libevent, you need |
3375 | to use the libev header file and library. |
3674 | to use the libev header file and library. |
… | |
… | |
3394 | Care has been taken to keep the overhead low. The only data member the C++ |
3693 | Care has been taken to keep the overhead low. The only data member the C++ |
3395 | classes add (compared to plain C-style watchers) is the event loop pointer |
3694 | classes add (compared to plain C-style watchers) is the event loop pointer |
3396 | that the watcher is associated with (or no additional members at all if |
3695 | that the watcher is associated with (or no additional members at all if |
3397 | you disable C<EV_MULTIPLICITY> when embedding libev). |
3696 | you disable C<EV_MULTIPLICITY> when embedding libev). |
3398 | |
3697 | |
3399 | Currently, functions, and static and non-static member functions can be |
3698 | Currently, functions, static and non-static member functions and classes |
3400 | used as callbacks. Other types should be easy to add as long as they only |
3699 | with C<operator ()> can be used as callbacks. Other types should be easy |
3401 | need one additional pointer for context. If you need support for other |
3700 | to add as long as they only need one additional pointer for context. If |
3402 | types of functors please contact the author (preferably after implementing |
3701 | you need support for other types of functors please contact the author |
3403 | it). |
3702 | (preferably after implementing it). |
3404 | |
3703 | |
3405 | Here is a list of things available in the C<ev> namespace: |
3704 | Here is a list of things available in the C<ev> namespace: |
3406 | |
3705 | |
3407 | =over 4 |
3706 | =over 4 |
3408 | |
3707 | |
… | |
… | |
4337 | default loop and triggering an C<ev_async> watcher from the default loop |
4636 | default loop and triggering an C<ev_async> watcher from the default loop |
4338 | watcher callback into the event loop interested in the signal. |
4637 | watcher callback into the event loop interested in the signal. |
4339 | |
4638 | |
4340 | =back |
4639 | =back |
4341 | |
4640 | |
4342 | =head4 THREAD LOCKING EXAMPLE |
4641 | See also L<Thread locking example>. |
4343 | |
|
|
4344 | Here is a fictitious example of how to run an event loop in a different |
|
|
4345 | thread than where callbacks are being invoked and watchers are |
|
|
4346 | created/added/removed. |
|
|
4347 | |
|
|
4348 | For a real-world example, see the C<EV::Loop::Async> perl module, |
|
|
4349 | which uses exactly this technique (which is suited for many high-level |
|
|
4350 | languages). |
|
|
4351 | |
|
|
4352 | The example uses a pthread mutex to protect the loop data, a condition |
|
|
4353 | variable to wait for callback invocations, an async watcher to notify the |
|
|
4354 | event loop thread and an unspecified mechanism to wake up the main thread. |
|
|
4355 | |
|
|
4356 | First, you need to associate some data with the event loop: |
|
|
4357 | |
|
|
4358 | typedef struct { |
|
|
4359 | mutex_t lock; /* global loop lock */ |
|
|
4360 | ev_async async_w; |
|
|
4361 | thread_t tid; |
|
|
4362 | cond_t invoke_cv; |
|
|
4363 | } userdata; |
|
|
4364 | |
|
|
4365 | void prepare_loop (EV_P) |
|
|
4366 | { |
|
|
4367 | // for simplicity, we use a static userdata struct. |
|
|
4368 | static userdata u; |
|
|
4369 | |
|
|
4370 | ev_async_init (&u->async_w, async_cb); |
|
|
4371 | ev_async_start (EV_A_ &u->async_w); |
|
|
4372 | |
|
|
4373 | pthread_mutex_init (&u->lock, 0); |
|
|
4374 | pthread_cond_init (&u->invoke_cv, 0); |
|
|
4375 | |
|
|
4376 | // now associate this with the loop |
|
|
4377 | ev_set_userdata (EV_A_ u); |
|
|
4378 | ev_set_invoke_pending_cb (EV_A_ l_invoke); |
|
|
4379 | ev_set_loop_release_cb (EV_A_ l_release, l_acquire); |
|
|
4380 | |
|
|
4381 | // then create the thread running ev_loop |
|
|
4382 | pthread_create (&u->tid, 0, l_run, EV_A); |
|
|
4383 | } |
|
|
4384 | |
|
|
4385 | The callback for the C<ev_async> watcher does nothing: the watcher is used |
|
|
4386 | solely to wake up the event loop so it takes notice of any new watchers |
|
|
4387 | that might have been added: |
|
|
4388 | |
|
|
4389 | static void |
|
|
4390 | async_cb (EV_P_ ev_async *w, int revents) |
|
|
4391 | { |
|
|
4392 | // just used for the side effects |
|
|
4393 | } |
|
|
4394 | |
|
|
4395 | The C<l_release> and C<l_acquire> callbacks simply unlock/lock the mutex |
|
|
4396 | protecting the loop data, respectively. |
|
|
4397 | |
|
|
4398 | static void |
|
|
4399 | l_release (EV_P) |
|
|
4400 | { |
|
|
4401 | userdata *u = ev_userdata (EV_A); |
|
|
4402 | pthread_mutex_unlock (&u->lock); |
|
|
4403 | } |
|
|
4404 | |
|
|
4405 | static void |
|
|
4406 | l_acquire (EV_P) |
|
|
4407 | { |
|
|
4408 | userdata *u = ev_userdata (EV_A); |
|
|
4409 | pthread_mutex_lock (&u->lock); |
|
|
4410 | } |
|
|
4411 | |
|
|
4412 | The event loop thread first acquires the mutex, and then jumps straight |
|
|
4413 | into C<ev_run>: |
|
|
4414 | |
|
|
4415 | void * |
|
|
4416 | l_run (void *thr_arg) |
|
|
4417 | { |
|
|
4418 | struct ev_loop *loop = (struct ev_loop *)thr_arg; |
|
|
4419 | |
|
|
4420 | l_acquire (EV_A); |
|
|
4421 | pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0); |
|
|
4422 | ev_run (EV_A_ 0); |
|
|
4423 | l_release (EV_A); |
|
|
4424 | |
|
|
4425 | return 0; |
|
|
4426 | } |
|
|
4427 | |
|
|
4428 | Instead of invoking all pending watchers, the C<l_invoke> callback will |
|
|
4429 | signal the main thread via some unspecified mechanism (signals? pipe |
|
|
4430 | writes? C<Async::Interrupt>?) and then waits until all pending watchers |
|
|
4431 | have been called (in a while loop because a) spurious wakeups are possible |
|
|
4432 | and b) skipping inter-thread-communication when there are no pending |
|
|
4433 | watchers is very beneficial): |
|
|
4434 | |
|
|
4435 | static void |
|
|
4436 | l_invoke (EV_P) |
|
|
4437 | { |
|
|
4438 | userdata *u = ev_userdata (EV_A); |
|
|
4439 | |
|
|
4440 | while (ev_pending_count (EV_A)) |
|
|
4441 | { |
|
|
4442 | wake_up_other_thread_in_some_magic_or_not_so_magic_way (); |
|
|
4443 | pthread_cond_wait (&u->invoke_cv, &u->lock); |
|
|
4444 | } |
|
|
4445 | } |
|
|
4446 | |
|
|
4447 | Now, whenever the main thread gets told to invoke pending watchers, it |
|
|
4448 | will grab the lock, call C<ev_invoke_pending> and then signal the loop |
|
|
4449 | thread to continue: |
|
|
4450 | |
|
|
4451 | static void |
|
|
4452 | real_invoke_pending (EV_P) |
|
|
4453 | { |
|
|
4454 | userdata *u = ev_userdata (EV_A); |
|
|
4455 | |
|
|
4456 | pthread_mutex_lock (&u->lock); |
|
|
4457 | ev_invoke_pending (EV_A); |
|
|
4458 | pthread_cond_signal (&u->invoke_cv); |
|
|
4459 | pthread_mutex_unlock (&u->lock); |
|
|
4460 | } |
|
|
4461 | |
|
|
4462 | Whenever you want to start/stop a watcher or do other modifications to an |
|
|
4463 | event loop, you will now have to lock: |
|
|
4464 | |
|
|
4465 | ev_timer timeout_watcher; |
|
|
4466 | userdata *u = ev_userdata (EV_A); |
|
|
4467 | |
|
|
4468 | ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.); |
|
|
4469 | |
|
|
4470 | pthread_mutex_lock (&u->lock); |
|
|
4471 | ev_timer_start (EV_A_ &timeout_watcher); |
|
|
4472 | ev_async_send (EV_A_ &u->async_w); |
|
|
4473 | pthread_mutex_unlock (&u->lock); |
|
|
4474 | |
|
|
4475 | Note that sending the C<ev_async> watcher is required because otherwise |
|
|
4476 | an event loop currently blocking in the kernel will have no knowledge |
|
|
4477 | about the newly added timer. By waking up the loop it will pick up any new |
|
|
4478 | watchers in the next event loop iteration. |
|
|
4479 | |
4642 | |
4480 | =head3 COROUTINES |
4643 | =head3 COROUTINES |
4481 | |
4644 | |
4482 | Libev is very accommodating to coroutines ("cooperative threads"): |
4645 | Libev is very accommodating to coroutines ("cooperative threads"): |
4483 | libev fully supports nesting calls to its functions from different |
4646 | libev fully supports nesting calls to its functions from different |
… | |
… | |
4752 | structure (guaranteed by POSIX but not by ISO C for example), but it also |
4915 | structure (guaranteed by POSIX but not by ISO C for example), but it also |
4753 | assumes that the same (machine) code can be used to call any watcher |
4916 | assumes that the same (machine) code can be used to call any watcher |
4754 | callback: The watcher callbacks have different type signatures, but libev |
4917 | callback: The watcher callbacks have different type signatures, but libev |
4755 | calls them using an C<ev_watcher *> internally. |
4918 | calls them using an C<ev_watcher *> internally. |
4756 | |
4919 | |
|
|
4920 | =item pointer accesses must be thread-atomic |
|
|
4921 | |
|
|
4922 | Accessing a pointer value must be atomic, it must both be readable and |
|
|
4923 | writable in one piece - this is the case on all current architectures. |
|
|
4924 | |
4757 | =item C<sig_atomic_t volatile> must be thread-atomic as well |
4925 | =item C<sig_atomic_t volatile> must be thread-atomic as well |
4758 | |
4926 | |
4759 | The type C<sig_atomic_t volatile> (or whatever is defined as |
4927 | The type C<sig_atomic_t volatile> (or whatever is defined as |
4760 | C<EV_ATOMIC_T>) must be atomic with respect to accesses from different |
4928 | C<EV_ATOMIC_T>) must be atomic with respect to accesses from different |
4761 | threads. This is not part of the specification for C<sig_atomic_t>, but is |
4929 | threads. This is not part of the specification for C<sig_atomic_t>, but is |
… | |
… | |
4867 | =back |
5035 | =back |
4868 | |
5036 | |
4869 | |
5037 | |
4870 | =head1 PORTING FROM LIBEV 3.X TO 4.X |
5038 | =head1 PORTING FROM LIBEV 3.X TO 4.X |
4871 | |
5039 | |
4872 | The major version 4 introduced some minor incompatible changes to the API. |
5040 | The major version 4 introduced some incompatible changes to the API. |
4873 | |
5041 | |
4874 | At the moment, the C<ev.h> header file tries to implement superficial |
5042 | At the moment, the C<ev.h> header file provides compatibility definitions |
4875 | compatibility, so most programs should still compile. Those might be |
5043 | for all changes, so most programs should still compile. The compatibility |
4876 | removed in later versions of libev, so better update early than late. |
5044 | layer might be removed in later versions of libev, so better update to the |
|
|
5045 | new API early than late. |
4877 | |
5046 | |
4878 | =over 4 |
5047 | =over 4 |
|
|
5048 | |
|
|
5049 | =item C<EV_COMPAT3> backwards compatibility mechanism |
|
|
5050 | |
|
|
5051 | The backward compatibility mechanism can be controlled by |
|
|
5052 | C<EV_COMPAT3>. See L<PREPROCESSOR SYMBOLS/MACROS> in the L<EMBEDDING> |
|
|
5053 | section. |
4879 | |
5054 | |
4880 | =item C<ev_default_destroy> and C<ev_default_fork> have been removed |
5055 | =item C<ev_default_destroy> and C<ev_default_fork> have been removed |
4881 | |
5056 | |
4882 | These calls can be replaced easily by their C<ev_loop_xxx> counterparts: |
5057 | These calls can be replaced easily by their C<ev_loop_xxx> counterparts: |
4883 | |
5058 | |
… | |
… | |
4909 | ev_loop> anymore and C<EV_TIMER> now follows the same naming scheme |
5084 | ev_loop> anymore and C<EV_TIMER> now follows the same naming scheme |
4910 | as all other watcher types. Note that C<ev_loop_fork> is still called |
5085 | as all other watcher types. Note that C<ev_loop_fork> is still called |
4911 | C<ev_loop_fork> because it would otherwise clash with the C<ev_fork> |
5086 | C<ev_loop_fork> because it would otherwise clash with the C<ev_fork> |
4912 | typedef. |
5087 | typedef. |
4913 | |
5088 | |
4914 | =item C<EV_COMPAT3> backwards compatibility mechanism |
|
|
4915 | |
|
|
4916 | The backward compatibility mechanism can be controlled by |
|
|
4917 | C<EV_COMPAT3>. See L<PREPROCESSOR SYMBOLS/MACROS> in the L<EMBEDDING> |
|
|
4918 | section. |
|
|
4919 | |
|
|
4920 | =item C<EV_MINIMAL> mechanism replaced by C<EV_FEATURES> |
5089 | =item C<EV_MINIMAL> mechanism replaced by C<EV_FEATURES> |
4921 | |
5090 | |
4922 | The preprocessor symbol C<EV_MINIMAL> has been replaced by a different |
5091 | The preprocessor symbol C<EV_MINIMAL> has been replaced by a different |
4923 | mechanism, C<EV_FEATURES>. Programs using C<EV_MINIMAL> usually compile |
5092 | mechanism, C<EV_FEATURES>. Programs using C<EV_MINIMAL> usually compile |
4924 | and work, but the library code will of course be larger. |
5093 | and work, but the library code will of course be larger. |
… | |
… | |
4998 | |
5167 | |
4999 | =back |
5168 | =back |
5000 | |
5169 | |
5001 | =head1 AUTHOR |
5170 | =head1 AUTHOR |
5002 | |
5171 | |
5003 | Marc Lehmann <libev@schmorp.de>, with repeated corrections by Mikael Magnusson. |
5172 | Marc Lehmann <libev@schmorp.de>, with repeated corrections by Mikael |
|
|
5173 | Magnusson and Emanuele Giaquinta. |
5004 | |
5174 | |