… | |
… | |
53 | The newest version of this document is also available as a html-formatted |
53 | The newest version of this document is also available as a html-formatted |
54 | web page you might find easier to navigate when reading it for the first |
54 | web page you might find easier to navigate when reading it for the first |
55 | time: L<http://cvs.schmorp.de/libev/ev.html>. |
55 | time: L<http://cvs.schmorp.de/libev/ev.html>. |
56 | |
56 | |
57 | Libev is an event loop: you register interest in certain events (such as a |
57 | Libev is an event loop: you register interest in certain events (such as a |
58 | file descriptor being readable or a timeout occuring), and it will manage |
58 | file descriptor being readable or a timeout occurring), and it will manage |
59 | these event sources and provide your program with events. |
59 | these event sources and provide your program with events. |
60 | |
60 | |
61 | To do this, it must take more or less complete control over your process |
61 | To do this, it must take more or less complete control over your process |
62 | (or thread) by executing the I<event loop> handler, and will then |
62 | (or thread) by executing the I<event loop> handler, and will then |
63 | communicate events via a callback mechanism. |
63 | communicate events via a callback mechanism. |
… | |
… | |
98 | Libev represents time as a single floating point number, representing the |
98 | Libev represents time as a single floating point number, representing the |
99 | (fractional) number of seconds since the (POSIX) epoch (somewhere near |
99 | (fractional) number of seconds since the (POSIX) epoch (somewhere near |
100 | the beginning of 1970, details are complicated, don't ask). This type is |
100 | the beginning of 1970, details are complicated, don't ask). This type is |
101 | called C<ev_tstamp>, which is what you should use too. It usually aliases |
101 | called C<ev_tstamp>, which is what you should use too. It usually aliases |
102 | to the C<double> type in C, and when you need to do any calculations on |
102 | to the C<double> type in C, and when you need to do any calculations on |
103 | it, you should treat it as such. |
103 | it, you should treat it as some floatingpoint value. Unlike the name |
|
|
104 | component C<stamp> might indicate, it is also used for time differences |
|
|
105 | throughout libev. |
104 | |
106 | |
105 | =head1 GLOBAL FUNCTIONS |
107 | =head1 GLOBAL FUNCTIONS |
106 | |
108 | |
107 | These functions can be called anytime, even before initialising the |
109 | These functions can be called anytime, even before initialising the |
108 | library in any way. |
110 | library in any way. |
… | |
… | |
112 | =item ev_tstamp ev_time () |
114 | =item ev_tstamp ev_time () |
113 | |
115 | |
114 | Returns the current time as libev would use it. Please note that the |
116 | Returns the current time as libev would use it. Please note that the |
115 | C<ev_now> function is usually faster and also often returns the timestamp |
117 | C<ev_now> function is usually faster and also often returns the timestamp |
116 | you actually want to know. |
118 | you actually want to know. |
|
|
119 | |
|
|
120 | =item ev_sleep (ev_tstamp interval) |
|
|
121 | |
|
|
122 | Sleep for the given interval: The current thread will be blocked until |
|
|
123 | either it is interrupted or the given time interval has passed. Basically |
|
|
124 | this is a subsecond-resolution C<sleep ()>. |
117 | |
125 | |
118 | =item int ev_version_major () |
126 | =item int ev_version_major () |
119 | |
127 | |
120 | =item int ev_version_minor () |
128 | =item int ev_version_minor () |
121 | |
129 | |
… | |
… | |
311 | lot of inactive fds). It scales similarly to select, i.e. O(total_fds). |
319 | lot of inactive fds). It scales similarly to select, i.e. O(total_fds). |
312 | |
320 | |
313 | =item C<EVBACKEND_EPOLL> (value 4, Linux) |
321 | =item C<EVBACKEND_EPOLL> (value 4, Linux) |
314 | |
322 | |
315 | For few fds, this backend is a bit little slower than poll and select, |
323 | For few fds, this backend is a bit little slower than poll and select, |
316 | but it scales phenomenally better. While poll and select usually scale like |
324 | but it scales phenomenally better. While poll and select usually scale |
317 | O(total_fds) where n is the total number of fds (or the highest fd), epoll scales |
325 | like O(total_fds) where n is the total number of fds (or the highest fd), |
318 | either O(1) or O(active_fds). |
326 | epoll scales either O(1) or O(active_fds). The epoll design has a number |
|
|
327 | of shortcomings, such as silently dropping events in some hard-to-detect |
|
|
328 | cases and rewiring a syscall per fd change, no fork support and bad |
|
|
329 | support for dup: |
319 | |
330 | |
320 | While stopping and starting an I/O watcher in the same iteration will |
331 | While stopping, setting and starting an I/O watcher in the same iteration |
321 | result in some caching, there is still a syscall per such incident |
332 | will result in some caching, there is still a syscall per such incident |
322 | (because the fd could point to a different file description now), so its |
333 | (because the fd could point to a different file description now), so its |
323 | best to avoid that. Also, dup()ed file descriptors might not work very |
334 | best to avoid that. Also, C<dup ()>'ed file descriptors might not work |
324 | well if you register events for both fds. |
335 | very well if you register events for both fds. |
325 | |
336 | |
326 | Please note that epoll sometimes generates spurious notifications, so you |
337 | Please note that epoll sometimes generates spurious notifications, so you |
327 | need to use non-blocking I/O or other means to avoid blocking when no data |
338 | need to use non-blocking I/O or other means to avoid blocking when no data |
328 | (or space) is available. |
339 | (or space) is available. |
329 | |
340 | |
330 | =item C<EVBACKEND_KQUEUE> (value 8, most BSD clones) |
341 | =item C<EVBACKEND_KQUEUE> (value 8, most BSD clones) |
331 | |
342 | |
332 | Kqueue deserves special mention, as at the time of this writing, it |
343 | Kqueue deserves special mention, as at the time of this writing, it |
333 | was broken on all BSDs except NetBSD (usually it doesn't work with |
344 | was broken on I<all> BSDs (usually it doesn't work with anything but |
334 | anything but sockets and pipes, except on Darwin, where of course its |
345 | sockets and pipes, except on Darwin, where of course it's completely |
|
|
346 | useless. On NetBSD, it seems to work for all the FD types I tested, so it |
335 | completely useless). For this reason its not being "autodetected" |
347 | is used by default there). For this reason it's not being "autodetected" |
336 | unless you explicitly specify it explicitly in the flags (i.e. using |
348 | unless you explicitly specify it explicitly in the flags (i.e. using |
337 | C<EVBACKEND_KQUEUE>). |
349 | C<EVBACKEND_KQUEUE>) or libev was compiled on a known-to-be-good (-enough) |
|
|
350 | system like NetBSD. |
338 | |
351 | |
339 | It scales in the same way as the epoll backend, but the interface to the |
352 | It scales in the same way as the epoll backend, but the interface to the |
340 | kernel is more efficient (which says nothing about its actual speed, of |
353 | kernel is more efficient (which says nothing about its actual speed, |
341 | course). While starting and stopping an I/O watcher does not cause an |
354 | of course). While stopping, setting and starting an I/O watcher does |
342 | extra syscall as with epoll, it still adds up to four event changes per |
355 | never cause an extra syscall as with epoll, it still adds up to two event |
343 | incident, so its best to avoid that. |
356 | changes per incident, support for C<fork ()> is very bad and it drops fds |
|
|
357 | silently in similarly hard-to-detetc cases. |
344 | |
358 | |
345 | =item C<EVBACKEND_DEVPOLL> (value 16, Solaris 8) |
359 | =item C<EVBACKEND_DEVPOLL> (value 16, Solaris 8) |
346 | |
360 | |
347 | This is not implemented yet (and might never be). |
361 | This is not implemented yet (and might never be). |
348 | |
362 | |
349 | =item C<EVBACKEND_PORT> (value 32, Solaris 10) |
363 | =item C<EVBACKEND_PORT> (value 32, Solaris 10) |
350 | |
364 | |
351 | This uses the Solaris 10 port mechanism. As with everything on Solaris, |
365 | This uses the Solaris 10 event port mechanism. As with everything on Solaris, |
352 | it's really slow, but it still scales very well (O(active_fds)). |
366 | it's really slow, but it still scales very well (O(active_fds)). |
353 | |
367 | |
354 | Please note that solaris ports can result in a lot of spurious |
368 | Please note that solaris event ports can deliver a lot of spurious |
355 | notifications, so you need to use non-blocking I/O or other means to avoid |
369 | notifications, so you need to use non-blocking I/O or other means to avoid |
356 | blocking when no data (or space) is available. |
370 | blocking when no data (or space) is available. |
357 | |
371 | |
358 | =item C<EVBACKEND_ALL> |
372 | =item C<EVBACKEND_ALL> |
359 | |
373 | |
… | |
… | |
402 | Destroys the default loop again (frees all memory and kernel state |
416 | Destroys the default loop again (frees all memory and kernel state |
403 | etc.). None of the active event watchers will be stopped in the normal |
417 | etc.). None of the active event watchers will be stopped in the normal |
404 | sense, so e.g. C<ev_is_active> might still return true. It is your |
418 | sense, so e.g. C<ev_is_active> might still return true. It is your |
405 | responsibility to either stop all watchers cleanly yoursef I<before> |
419 | responsibility to either stop all watchers cleanly yoursef I<before> |
406 | calling this function, or cope with the fact afterwards (which is usually |
420 | calling this function, or cope with the fact afterwards (which is usually |
407 | the easiest thing, youc na just ignore the watchers and/or C<free ()> them |
421 | the easiest thing, you can just ignore the watchers and/or C<free ()> them |
408 | for example). |
422 | for example). |
|
|
423 | |
|
|
424 | Note that certain global state, such as signal state, will not be freed by |
|
|
425 | this function, and related watchers (such as signal and child watchers) |
|
|
426 | would need to be stopped manually. |
|
|
427 | |
|
|
428 | In general it is not advisable to call this function except in the |
|
|
429 | rare occasion where you really need to free e.g. the signal handling |
|
|
430 | pipe fds. If you need dynamically allocated loops it is better to use |
|
|
431 | C<ev_loop_new> and C<ev_loop_destroy>). |
409 | |
432 | |
410 | =item ev_loop_destroy (loop) |
433 | =item ev_loop_destroy (loop) |
411 | |
434 | |
412 | Like C<ev_default_destroy>, but destroys an event loop created by an |
435 | Like C<ev_default_destroy>, but destroys an event loop created by an |
413 | earlier call to C<ev_loop_new>. |
436 | earlier call to C<ev_loop_new>. |
… | |
… | |
458 | |
481 | |
459 | Returns the current "event loop time", which is the time the event loop |
482 | Returns the current "event loop time", which is the time the event loop |
460 | received events and started processing them. This timestamp does not |
483 | received events and started processing them. This timestamp does not |
461 | change as long as callbacks are being processed, and this is also the base |
484 | change as long as callbacks are being processed, and this is also the base |
462 | time used for relative timers. You can treat it as the timestamp of the |
485 | time used for relative timers. You can treat it as the timestamp of the |
463 | event occuring (or more correctly, libev finding out about it). |
486 | event occurring (or more correctly, libev finding out about it). |
464 | |
487 | |
465 | =item ev_loop (loop, int flags) |
488 | =item ev_loop (loop, int flags) |
466 | |
489 | |
467 | Finally, this is it, the event handler. This function usually is called |
490 | Finally, this is it, the event handler. This function usually is called |
468 | after you initialised all your watchers and you want to start handling |
491 | after you initialised all your watchers and you want to start handling |
… | |
… | |
552 | Example: For some weird reason, unregister the above signal handler again. |
575 | Example: For some weird reason, unregister the above signal handler again. |
553 | |
576 | |
554 | ev_ref (loop); |
577 | ev_ref (loop); |
555 | ev_signal_stop (loop, &exitsig); |
578 | ev_signal_stop (loop, &exitsig); |
556 | |
579 | |
|
|
580 | =item ev_set_io_collect_interval (loop, ev_tstamp interval) |
|
|
581 | |
|
|
582 | =item ev_set_timeout_collect_interval (loop, ev_tstamp interval) |
|
|
583 | |
|
|
584 | These advanced functions influence the time that libev will spend waiting |
|
|
585 | for events. Both are by default C<0>, meaning that libev will try to |
|
|
586 | invoke timer/periodic callbacks and I/O callbacks with minimum latency. |
|
|
587 | |
|
|
588 | Setting these to a higher value (the C<interval> I<must> be >= C<0>) |
|
|
589 | allows libev to delay invocation of I/O and timer/periodic callbacks to |
|
|
590 | increase efficiency of loop iterations. |
|
|
591 | |
|
|
592 | The background is that sometimes your program runs just fast enough to |
|
|
593 | handle one (or very few) event(s) per loop iteration. While this makes |
|
|
594 | the program responsive, it also wastes a lot of CPU time to poll for new |
|
|
595 | events, especially with backends like C<select ()> which have a high |
|
|
596 | overhead for the actual polling but can deliver many events at once. |
|
|
597 | |
|
|
598 | By setting a higher I<io collect interval> you allow libev to spend more |
|
|
599 | time collecting I/O events, so you can handle more events per iteration, |
|
|
600 | at the cost of increasing latency. Timeouts (both C<ev_periodic> and |
|
|
601 | C<ev_timer>) will be not affected. Setting this to a non-null bvalue will |
|
|
602 | introduce an additional C<ev_sleep ()> call into most loop iterations. |
|
|
603 | |
|
|
604 | Likewise, by setting a higher I<timeout collect interval> you allow libev |
|
|
605 | to spend more time collecting timeouts, at the expense of increased |
|
|
606 | latency (the watcher callback will be called later). C<ev_io> watchers |
|
|
607 | will not be affected. Setting this to a non-null value will not introduce |
|
|
608 | any overhead in libev. |
|
|
609 | |
|
|
610 | Many (busy) programs can usually benefit by setting the io collect |
|
|
611 | interval to a value near C<0.1> or so, which is often enough for |
|
|
612 | interactive servers (of course not for games), likewise for timeouts. It |
|
|
613 | usually doesn't make much sense to set it to a lower value than C<0.01>, |
|
|
614 | as this approsaches the timing granularity of most systems. |
|
|
615 | |
557 | =back |
616 | =back |
558 | |
617 | |
559 | |
618 | |
560 | =head1 ANATOMY OF A WATCHER |
619 | =head1 ANATOMY OF A WATCHER |
561 | |
620 | |
… | |
… | |
913 | such as poll (fortunately in our Xlib example, Xlib already does this on |
972 | such as poll (fortunately in our Xlib example, Xlib already does this on |
914 | its own, so its quite safe to use). |
973 | its own, so its quite safe to use). |
915 | |
974 | |
916 | =head3 The special problem of disappearing file descriptors |
975 | =head3 The special problem of disappearing file descriptors |
917 | |
976 | |
918 | Some backends (e.g kqueue, epoll) need to be told about closing a file |
977 | Some backends (e.g. kqueue, epoll) need to be told about closing a file |
919 | descriptor (either by calling C<close> explicitly or by any other means, |
978 | descriptor (either by calling C<close> explicitly or by any other means, |
920 | such as C<dup>). The reason is that you register interest in some file |
979 | such as C<dup>). The reason is that you register interest in some file |
921 | descriptor, but when it goes away, the operating system will silently drop |
980 | descriptor, but when it goes away, the operating system will silently drop |
922 | this interest. If another file descriptor with the same number then is |
981 | this interest. If another file descriptor with the same number then is |
923 | registered with libev, there is no efficient way to see that this is, in |
982 | registered with libev, there is no efficient way to see that this is, in |
… | |
… | |
931 | descriptor even if the file descriptor number itself did not change. |
990 | descriptor even if the file descriptor number itself did not change. |
932 | |
991 | |
933 | This is how one would do it normally anyway, the important point is that |
992 | This is how one would do it normally anyway, the important point is that |
934 | the libev application should not optimise around libev but should leave |
993 | the libev application should not optimise around libev but should leave |
935 | optimisations to libev. |
994 | optimisations to libev. |
|
|
995 | |
|
|
996 | =head3 The special problem of dup'ed file descriptors |
|
|
997 | |
|
|
998 | Some backends (e.g. epoll), cannot register events for file descriptors, |
|
|
999 | but only events for the underlying file descriptions. That menas when you |
|
|
1000 | have C<dup ()>'ed file descriptors and register events for them, only one |
|
|
1001 | file descriptor might actually receive events. |
|
|
1002 | |
|
|
1003 | There is no workaorund possible except not registering events |
|
|
1004 | for potentially C<dup ()>'ed file descriptors or to resort to |
|
|
1005 | C<EVBACKEND_SELECT> or C<EVBACKEND_POLL>. |
|
|
1006 | |
|
|
1007 | =head3 The special problem of fork |
|
|
1008 | |
|
|
1009 | Some backends (epoll, kqueue) do not support C<fork ()> at all or exhibit |
|
|
1010 | useless behaviour. Libev fully supports fork, but needs to be told about |
|
|
1011 | it in the child. |
|
|
1012 | |
|
|
1013 | To support fork in your programs, you either have to call |
|
|
1014 | C<ev_default_fork ()> or C<ev_loop_fork ()> after a fork in the child, |
|
|
1015 | enable C<EVFLAG_FORKCHECK>, or resort to C<EVBACKEND_SELECT> or |
|
|
1016 | C<EVBACKEND_POLL>. |
936 | |
1017 | |
937 | |
1018 | |
938 | =head3 Watcher-Specific Functions |
1019 | =head3 Watcher-Specific Functions |
939 | |
1020 | |
940 | =over 4 |
1021 | =over 4 |
… | |
… | |
1695 | =head2 C<ev_embed> - when one backend isn't enough... |
1776 | =head2 C<ev_embed> - when one backend isn't enough... |
1696 | |
1777 | |
1697 | This is a rather advanced watcher type that lets you embed one event loop |
1778 | This is a rather advanced watcher type that lets you embed one event loop |
1698 | into another (currently only C<ev_io> events are supported in the embedded |
1779 | into another (currently only C<ev_io> events are supported in the embedded |
1699 | loop, other types of watchers might be handled in a delayed or incorrect |
1780 | loop, other types of watchers might be handled in a delayed or incorrect |
1700 | fashion and must not be used). |
1781 | fashion and must not be used). (See portability notes, below). |
1701 | |
1782 | |
1702 | There are primarily two reasons you would want that: work around bugs and |
1783 | There are primarily two reasons you would want that: work around bugs and |
1703 | prioritise I/O. |
1784 | prioritise I/O. |
1704 | |
1785 | |
1705 | As an example for a bug workaround, the kqueue backend might only support |
1786 | As an example for a bug workaround, the kqueue backend might only support |
… | |
… | |
1760 | ev_embed_start (loop_hi, &embed); |
1841 | ev_embed_start (loop_hi, &embed); |
1761 | } |
1842 | } |
1762 | else |
1843 | else |
1763 | loop_lo = loop_hi; |
1844 | loop_lo = loop_hi; |
1764 | |
1845 | |
|
|
1846 | =head2 Portability notes |
|
|
1847 | |
|
|
1848 | Kqueue is nominally embeddable, but this is broken on all BSDs that I |
|
|
1849 | tried, in various ways. Usually the embedded event loop will simply never |
|
|
1850 | receive events, sometimes it will only trigger a few times, sometimes in a |
|
|
1851 | loop. Epoll is also nominally embeddable, but many Linux kernel versions |
|
|
1852 | will always eport the epoll fd as ready, even when no events are pending. |
|
|
1853 | |
|
|
1854 | While libev allows embedding these backends (they are contained in |
|
|
1855 | C<ev_embeddable_backends ()>), take extreme care that it will actually |
|
|
1856 | work. |
|
|
1857 | |
|
|
1858 | When in doubt, create a dynamic event loop forced to use sockets (this |
|
|
1859 | usually works) and possibly another thread and a pipe or so to report to |
|
|
1860 | your main event loop. |
|
|
1861 | |
1765 | =head3 Watcher-Specific Functions and Data Members |
1862 | =head3 Watcher-Specific Functions and Data Members |
1766 | |
1863 | |
1767 | =over 4 |
1864 | =over 4 |
1768 | |
1865 | |
1769 | =item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop) |
1866 | =item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop) |
… | |
… | |
1780 | |
1877 | |
1781 | Make a single, non-blocking sweep over the embedded loop. This works |
1878 | Make a single, non-blocking sweep over the embedded loop. This works |
1782 | similarly to C<ev_loop (embedded_loop, EVLOOP_NONBLOCK)>, but in the most |
1879 | similarly to C<ev_loop (embedded_loop, EVLOOP_NONBLOCK)>, but in the most |
1783 | apropriate way for embedded loops. |
1880 | apropriate way for embedded loops. |
1784 | |
1881 | |
1785 | =item struct ev_loop *loop [read-only] |
1882 | =item struct ev_loop *other [read-only] |
1786 | |
1883 | |
1787 | The embedded event loop. |
1884 | The embedded event loop. |
1788 | |
1885 | |
1789 | =back |
1886 | =back |
1790 | |
1887 | |
… | |
… | |
2129 | Libev can (and often is) directly embedded into host |
2226 | Libev can (and often is) directly embedded into host |
2130 | applications. Examples of applications that embed it include the Deliantra |
2227 | applications. Examples of applications that embed it include the Deliantra |
2131 | Game Server, the EV perl module, the GNU Virtual Private Ethernet (gvpe) |
2228 | Game Server, the EV perl module, the GNU Virtual Private Ethernet (gvpe) |
2132 | and rxvt-unicode. |
2229 | and rxvt-unicode. |
2133 | |
2230 | |
2134 | The goal is to enable you to just copy the neecssary files into your |
2231 | The goal is to enable you to just copy the necessary files into your |
2135 | source directory without having to change even a single line in them, so |
2232 | source directory without having to change even a single line in them, so |
2136 | you can easily upgrade by simply copying (or having a checked-out copy of |
2233 | you can easily upgrade by simply copying (or having a checked-out copy of |
2137 | libev somewhere in your source tree). |
2234 | libev somewhere in your source tree). |
2138 | |
2235 | |
2139 | =head2 FILESETS |
2236 | =head2 FILESETS |
… | |
… | |
2229 | |
2326 | |
2230 | If defined to be C<1>, libev will try to detect the availability of the |
2327 | If defined to be C<1>, libev will try to detect the availability of the |
2231 | monotonic clock option at both compiletime and runtime. Otherwise no use |
2328 | monotonic clock option at both compiletime and runtime. Otherwise no use |
2232 | of the monotonic clock option will be attempted. If you enable this, you |
2329 | of the monotonic clock option will be attempted. If you enable this, you |
2233 | usually have to link against librt or something similar. Enabling it when |
2330 | usually have to link against librt or something similar. Enabling it when |
2234 | the functionality isn't available is safe, though, althoguh you have |
2331 | the functionality isn't available is safe, though, although you have |
2235 | to make sure you link against any libraries where the C<clock_gettime> |
2332 | to make sure you link against any libraries where the C<clock_gettime> |
2236 | function is hiding in (often F<-lrt>). |
2333 | function is hiding in (often F<-lrt>). |
2237 | |
2334 | |
2238 | =item EV_USE_REALTIME |
2335 | =item EV_USE_REALTIME |
2239 | |
2336 | |
2240 | If defined to be C<1>, libev will try to detect the availability of the |
2337 | If defined to be C<1>, libev will try to detect the availability of the |
2241 | realtime clock option at compiletime (and assume its availability at |
2338 | realtime clock option at compiletime (and assume its availability at |
2242 | runtime if successful). Otherwise no use of the realtime clock option will |
2339 | runtime if successful). Otherwise no use of the realtime clock option will |
2243 | be attempted. This effectively replaces C<gettimeofday> by C<clock_get |
2340 | be attempted. This effectively replaces C<gettimeofday> by C<clock_get |
2244 | (CLOCK_REALTIME, ...)> and will not normally affect correctness. See tzhe note about libraries |
2341 | (CLOCK_REALTIME, ...)> and will not normally affect correctness. See the |
2245 | in the description of C<EV_USE_MONOTONIC>, though. |
2342 | note about libraries in the description of C<EV_USE_MONOTONIC>, though. |
|
|
2343 | |
|
|
2344 | =item EV_USE_NANOSLEEP |
|
|
2345 | |
|
|
2346 | If defined to be C<1>, libev will assume that C<nanosleep ()> is available |
|
|
2347 | and will use it for delays. Otherwise it will use C<select ()>. |
2246 | |
2348 | |
2247 | =item EV_USE_SELECT |
2349 | =item EV_USE_SELECT |
2248 | |
2350 | |
2249 | If undefined or defined to be C<1>, libev will compile in support for the |
2351 | If undefined or defined to be C<1>, libev will compile in support for the |
2250 | C<select>(2) backend. No attempt at autodetection will be done: if no |
2352 | C<select>(2) backend. No attempt at autodetection will be done: if no |
… | |
… | |
2429 | |
2531 | |
2430 | =item ev_set_cb (ev, cb) |
2532 | =item ev_set_cb (ev, cb) |
2431 | |
2533 | |
2432 | Can be used to change the callback member declaration in each watcher, |
2534 | Can be used to change the callback member declaration in each watcher, |
2433 | and the way callbacks are invoked and set. Must expand to a struct member |
2535 | and the way callbacks are invoked and set. Must expand to a struct member |
2434 | definition and a statement, respectively. See the F<ev.v> header file for |
2536 | definition and a statement, respectively. See the F<ev.h> header file for |
2435 | their default definitions. One possible use for overriding these is to |
2537 | their default definitions. One possible use for overriding these is to |
2436 | avoid the C<struct ev_loop *> as first argument in all cases, or to use |
2538 | avoid the C<struct ev_loop *> as first argument in all cases, or to use |
2437 | method calls instead of plain function calls in C++. |
2539 | method calls instead of plain function calls in C++. |
|
|
2540 | |
|
|
2541 | =head2 EXPORTED API SYMBOLS |
|
|
2542 | |
|
|
2543 | If you need to re-export the API (e.g. via a dll) and you need a list of |
|
|
2544 | exported symbols, you can use the provided F<Symbol.*> files which list |
|
|
2545 | all public symbols, one per line: |
|
|
2546 | |
|
|
2547 | Symbols.ev for libev proper |
|
|
2548 | Symbols.event for the libevent emulation |
|
|
2549 | |
|
|
2550 | This can also be used to rename all public symbols to avoid clashes with |
|
|
2551 | multiple versions of libev linked together (which is obviously bad in |
|
|
2552 | itself, but sometimes it is inconvinient to avoid this). |
|
|
2553 | |
|
|
2554 | A sed command like this will create wrapper C<#define>'s that you need to |
|
|
2555 | include before including F<ev.h>: |
|
|
2556 | |
|
|
2557 | <Symbols.ev sed -e "s/.*/#define & myprefix_&/" >wrap.h |
|
|
2558 | |
|
|
2559 | This would create a file F<wrap.h> which essentially looks like this: |
|
|
2560 | |
|
|
2561 | #define ev_backend myprefix_ev_backend |
|
|
2562 | #define ev_check_start myprefix_ev_check_start |
|
|
2563 | #define ev_check_stop myprefix_ev_check_stop |
|
|
2564 | ... |
2438 | |
2565 | |
2439 | =head2 EXAMPLES |
2566 | =head2 EXAMPLES |
2440 | |
2567 | |
2441 | For a real-world example of a program the includes libev |
2568 | For a real-world example of a program the includes libev |
2442 | verbatim, you can have a look at the EV perl module |
2569 | verbatim, you can have a look at the EV perl module |