ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.3
(Generate patch)

Comparing libev/ev.3 (file contents):
Revision 1.101 by root, Fri Dec 27 06:01:21 2013 UTC vs.
Revision 1.110 by root, Thu Jun 20 22:44:59 2019 UTC

1.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) 1.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
2.\" 2.\"
3.\" Standard preamble: 3.\" Standard preamble:
4.\" ======================================================================== 4.\" ========================================================================
5.de Sp \" Vertical space (when we can't use .PP) 5.de Sp \" Vertical space (when we can't use .PP)
6.if t .sp .5v 6.if t .sp .5v
44.\" 44.\"
45.\" Escape single quotes in literal strings from groff's Unicode transform. 45.\" Escape single quotes in literal strings from groff's Unicode transform.
46.ie \n(.g .ds Aq \(aq 46.ie \n(.g .ds Aq \(aq
47.el .ds Aq ' 47.el .ds Aq '
48.\" 48.\"
49.\" If the F register is turned on, we'll generate index entries on stderr for 49.\" If the F register is >0, we'll generate index entries on stderr for
50.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index 50.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51.\" entries marked with X<> in POD. Of course, you'll have to process the 51.\" entries marked with X<> in POD. Of course, you'll have to process the
52.\" output yourself in some meaningful fashion. 52.\" output yourself in some meaningful fashion.
53.\" 53.\"
54.\" Avoid warning from groff about undefined register 'F'. 54.\" Avoid warning from groff about undefined register 'F'.
55.de IX 55.de IX
56.. 56..
57.nr rF 0 57.nr rF 0
58.if \n(.g .if rF .nr rF 1 58.if \n(.g .if rF .nr rF 1
59.if (\n(rF:(\n(.g==0)) \{ 59.if (\n(rF:(\n(.g==0)) \{\
60. if \nF \{ 60. if \nF \{\
61. de IX 61. de IX
62. tm Index:\\$1\t\\n%\t"\\$2" 62. tm Index:\\$1\t\\n%\t"\\$2"
63.. 63..
64. if !\nF==2 \{ 64. if !\nF==2 \{\
65. nr % 0 65. nr % 0
66. nr F 2 66. nr F 2
67. \} 67. \}
68. \} 68. \}
69.\} 69.\}
131.\} 131.\}
132.rm #[ #] #H #V #F C 132.rm #[ #] #H #V #F C
133.\" ======================================================================== 133.\" ========================================================================
134.\" 134.\"
135.IX Title "LIBEV 3" 135.IX Title "LIBEV 3"
136.TH LIBEV 3 "2013-12-27" "libev-4.15" "libev - high performance full featured event loop" 136.TH LIBEV 3 "2019-06-20" "libev-4.25" "libev - high performance full featured event loop"
137.\" For nroff, turn off justification. Always turn off hyphenation; it makes 137.\" For nroff, turn off justification. Always turn off hyphenation; it makes
138.\" way too many mistakes in technical documents. 138.\" way too many mistakes in technical documents.
139.if n .ad l 139.if n .ad l
140.nh 140.nh
141.SH "NAME" 141.SH "NAME"
392.Sp 392.Sp
393You could override this function in high-availability programs to, say, 393You could override this function in high-availability programs to, say,
394free some memory if it cannot allocate memory, to use a special allocator, 394free some memory if it cannot allocate memory, to use a special allocator,
395or even to sleep a while and retry until some memory is available. 395or even to sleep a while and retry until some memory is available.
396.Sp 396.Sp
397Example: The following is the \f(CW\*(C`realloc\*(C'\fR function that libev itself uses
398which should work with \f(CW\*(C`realloc\*(C'\fR and \f(CW\*(C`free\*(C'\fR functions of all kinds and
399is probably a good basis for your own implementation.
400.Sp
401.Vb 5
402\& static void *
403\& ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT
404\& {
405\& if (size)
406\& return realloc (ptr, size);
407\&
408\& free (ptr);
409\& return 0;
410\& }
411.Ve
412.Sp
397Example: Replace the libev allocator with one that waits a bit and then 413Example: Replace the libev allocator with one that waits a bit and then
398retries (example requires a standards-compliant \f(CW\*(C`realloc\*(C'\fR). 414retries.
399.Sp 415.Sp
400.Vb 6 416.Vb 8
401\& static void * 417\& static void *
402\& persistent_realloc (void *ptr, size_t size) 418\& persistent_realloc (void *ptr, size_t size)
403\& { 419\& {
420\& if (!size)
421\& {
422\& free (ptr);
423\& return 0;
424\& }
425\&
404\& for (;;) 426\& for (;;)
405\& { 427\& {
406\& void *newptr = realloc (ptr, size); 428\& void *newptr = realloc (ptr, size);
407\& 429\&
408\& if (newptr) 430\& if (newptr)
536make libev check for a fork in each iteration by enabling this flag. 558make libev check for a fork in each iteration by enabling this flag.
537.Sp 559.Sp
538This works by calling \f(CW\*(C`getpid ()\*(C'\fR on every iteration of the loop, 560This works by calling \f(CW\*(C`getpid ()\*(C'\fR on every iteration of the loop,
539and thus this might slow down your event loop if you do a lot of loop 561and thus this might slow down your event loop if you do a lot of loop
540iterations and little real work, but is usually not noticeable (on my 562iterations and little real work, but is usually not noticeable (on my
541GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn sequence 563GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn
542without a system call and thus \fIvery\fR fast, but my GNU/Linux system also has 564sequence without a system call and thus \fIvery\fR fast, but my GNU/Linux
543\&\f(CW\*(C`pthread_atfork\*(C'\fR which is even faster). 565system also has \f(CW\*(C`pthread_atfork\*(C'\fR which is even faster). (Update: glibc
566versions 2.25 apparently removed the \f(CW\*(C`getpid\*(C'\fR optimisation again).
544.Sp 567.Sp
545The big advantage of this flag is that you can forget about fork (and 568The big advantage of this flag is that you can forget about fork (and
546forget about forgetting to tell libev about forking) when you use this 569forget about forgetting to tell libev about forking, although you still
547flag. 570have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR) when you use this flag.
548.Sp 571.Sp
549This flag setting cannot be overridden or specified in the \f(CW\*(C`LIBEV_FLAGS\*(C'\fR 572This flag setting cannot be overridden or specified in the \f(CW\*(C`LIBEV_FLAGS\*(C'\fR
550environment variable. 573environment variable.
551.ie n .IP """EVFLAG_NOINOTIFY""" 4 574.ie n .IP """EVFLAG_NOINOTIFY""" 4
552.el .IP "\f(CWEVFLAG_NOINOTIFY\fR" 4 575.el .IP "\f(CWEVFLAG_NOINOTIFY\fR" 4
584.Sp 607.Sp
585This flag's behaviour will become the default in future versions of libev. 608This flag's behaviour will become the default in future versions of libev.
586.ie n .IP """EVBACKEND_SELECT"" (value 1, portable select backend)" 4 609.ie n .IP """EVBACKEND_SELECT"" (value 1, portable select backend)" 4
587.el .IP "\f(CWEVBACKEND_SELECT\fR (value 1, portable select backend)" 4 610.el .IP "\f(CWEVBACKEND_SELECT\fR (value 1, portable select backend)" 4
588.IX Item "EVBACKEND_SELECT (value 1, portable select backend)" 611.IX Item "EVBACKEND_SELECT (value 1, portable select backend)"
589This is your standard \fIselect\fR\|(2) backend. Not \fIcompletely\fR standard, as 612This is your standard \fBselect\fR\|(2) backend. Not \fIcompletely\fR standard, as
590libev tries to roll its own fd_set with no limits on the number of fds, 613libev tries to roll its own fd_set with no limits on the number of fds,
591but if that fails, expect a fairly low limit on the number of fds when 614but if that fails, expect a fairly low limit on the number of fds when
592using this backend. It doesn't scale too well (O(highest_fd)), but its 615using this backend. It doesn't scale too well (O(highest_fd)), but its
593usually the fastest backend for a low number of (low-numbered :) fds. 616usually the fastest backend for a low number of (low-numbered :) fds.
594.Sp 617.Sp
603\&\f(CW\*(C`writefds\*(C'\fR set (and to work around Microsoft Windows bugs, also onto the 626\&\f(CW\*(C`writefds\*(C'\fR set (and to work around Microsoft Windows bugs, also onto the
604\&\f(CW\*(C`exceptfds\*(C'\fR set on that platform). 627\&\f(CW\*(C`exceptfds\*(C'\fR set on that platform).
605.ie n .IP """EVBACKEND_POLL"" (value 2, poll backend, available everywhere except on windows)" 4 628.ie n .IP """EVBACKEND_POLL"" (value 2, poll backend, available everywhere except on windows)" 4
606.el .IP "\f(CWEVBACKEND_POLL\fR (value 2, poll backend, available everywhere except on windows)" 4 629.el .IP "\f(CWEVBACKEND_POLL\fR (value 2, poll backend, available everywhere except on windows)" 4
607.IX Item "EVBACKEND_POLL (value 2, poll backend, available everywhere except on windows)" 630.IX Item "EVBACKEND_POLL (value 2, poll backend, available everywhere except on windows)"
608And this is your standard \fIpoll\fR\|(2) backend. It's more complicated 631And this is your standard \fBpoll\fR\|(2) backend. It's more complicated
609than select, but handles sparse fds better and has no artificial 632than select, but handles sparse fds better and has no artificial
610limit on the number of fds you can use (except it will slow down 633limit on the number of fds you can use (except it will slow down
611considerably with a lot of inactive fds). It scales similarly to select, 634considerably with a lot of inactive fds). It scales similarly to select,
612i.e. O(total_fds). See the entry for \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR, above, for 635i.e. O(total_fds). See the entry for \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR, above, for
613performance tips. 636performance tips.
615This backend maps \f(CW\*(C`EV_READ\*(C'\fR to \f(CW\*(C`POLLIN | POLLERR | POLLHUP\*(C'\fR, and 638This backend maps \f(CW\*(C`EV_READ\*(C'\fR to \f(CW\*(C`POLLIN | POLLERR | POLLHUP\*(C'\fR, and
616\&\f(CW\*(C`EV_WRITE\*(C'\fR to \f(CW\*(C`POLLOUT | POLLERR | POLLHUP\*(C'\fR. 639\&\f(CW\*(C`EV_WRITE\*(C'\fR to \f(CW\*(C`POLLOUT | POLLERR | POLLHUP\*(C'\fR.
617.ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4 640.ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4
618.el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4 641.el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4
619.IX Item "EVBACKEND_EPOLL (value 4, Linux)" 642.IX Item "EVBACKEND_EPOLL (value 4, Linux)"
620Use the linux-specific \fIepoll\fR\|(7) interface (for both pre\- and post\-2.6.9 643Use the linux-specific \fBepoll\fR\|(7) interface (for both pre\- and post\-2.6.9
621kernels). 644kernels).
622.Sp 645.Sp
623For few fds, this backend is a bit little slower than poll and select, but 646For few fds, this backend is a bit little slower than poll and select, but
624it scales phenomenally better. While poll and select usually scale like 647it scales phenomenally better. While poll and select usually scale like
625O(total_fds) where total_fds is the total number of fds (or the highest 648O(total_fds) where total_fds is the total number of fds (or the highest
810except in the rare occasion where you really need to free its resources. 833except in the rare occasion where you really need to free its resources.
811If you need dynamically allocated loops it is better to use \f(CW\*(C`ev_loop_new\*(C'\fR 834If you need dynamically allocated loops it is better to use \f(CW\*(C`ev_loop_new\*(C'\fR
812and \f(CW\*(C`ev_loop_destroy\*(C'\fR. 835and \f(CW\*(C`ev_loop_destroy\*(C'\fR.
813.IP "ev_loop_fork (loop)" 4 836.IP "ev_loop_fork (loop)" 4
814.IX Item "ev_loop_fork (loop)" 837.IX Item "ev_loop_fork (loop)"
815This function sets a flag that causes subsequent \f(CW\*(C`ev_run\*(C'\fR iterations to 838This function sets a flag that causes subsequent \f(CW\*(C`ev_run\*(C'\fR iterations
816reinitialise the kernel state for backends that have one. Despite the 839to reinitialise the kernel state for backends that have one. Despite
817name, you can call it anytime, but it makes most sense after forking, in 840the name, you can call it anytime you are allowed to start or stop
818the child process. You \fImust\fR call it (or use \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR) in the 841watchers (except inside an \f(CW\*(C`ev_prepare\*(C'\fR callback), but it makes most
819child before resuming or calling \f(CW\*(C`ev_run\*(C'\fR. 842sense after forking, in the child process. You \fImust\fR call it (or use
843\&\f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR) in the child before resuming or calling \f(CW\*(C`ev_run\*(C'\fR.
844.Sp
845In addition, if you want to reuse a loop (via this function or
846\&\f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR), you \fIalso\fR have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR.
820.Sp 847.Sp
821Again, you \fIhave\fR to call it on \fIany\fR loop that you want to re-use after 848Again, you \fIhave\fR to call it on \fIany\fR loop that you want to re-use after
822a fork, \fIeven if you do not plan to use the loop in the parent\fR. This is 849a fork, \fIeven if you do not plan to use the loop in the parent\fR. This is
823because some kernel interfaces *cough* \fIkqueue\fR *cough* do funny things 850because some kernel interfaces *cough* \fIkqueue\fR *cough* do funny things
824during fork. 851during fork.
1360bug in your program. 1387bug in your program.
1361.Sp 1388.Sp
1362Libev will usually signal a few \*(L"dummy\*(R" events together with an error, for 1389Libev will usually signal a few \*(L"dummy\*(R" events together with an error, for
1363example it might indicate that a fd is readable or writable, and if your 1390example it might indicate that a fd is readable or writable, and if your
1364callbacks is well-written it can just attempt the operation and cope with 1391callbacks is well-written it can just attempt the operation and cope with
1365the error from \fIread()\fR or \fIwrite()\fR. This will not work in multi-threaded 1392the error from \fBread()\fR or \fBwrite()\fR. This will not work in multi-threaded
1366programs, though, as the fd could already be closed and reused for another 1393programs, though, as the fd could already be closed and reused for another
1367thing, so beware. 1394thing, so beware.
1368.SS "\s-1GENERIC WATCHER FUNCTIONS\s0" 1395.SS "\s-1GENERIC WATCHER FUNCTIONS\s0"
1369.IX Subsection "GENERIC WATCHER FUNCTIONS" 1396.IX Subsection "GENERIC WATCHER FUNCTIONS"
1370.ie n .IP """ev_init"" (ev_TYPE *watcher, callback)" 4 1397.ie n .IP """ev_init"" (ev_TYPE *watcher, callback)" 4
1806when writing to a pipe whose other end has been closed, your program gets 1833when writing to a pipe whose other end has been closed, your program gets
1807sent a \s-1SIGPIPE,\s0 which, by default, aborts your program. For most programs 1834sent a \s-1SIGPIPE,\s0 which, by default, aborts your program. For most programs
1808this is sensible behaviour, for daemons, this is usually undesirable. 1835this is sensible behaviour, for daemons, this is usually undesirable.
1809.PP 1836.PP
1810So when you encounter spurious, unexplained daemon exits, make sure you 1837So when you encounter spurious, unexplained daemon exits, make sure you
1811ignore \s-1SIGPIPE \s0(and maybe make sure you log the exit status of your daemon 1838ignore \s-1SIGPIPE\s0 (and maybe make sure you log the exit status of your daemon
1812somewhere, as that would have given you a big clue). 1839somewhere, as that would have given you a big clue).
1813.PP 1840.PP
1814\fIThe special problem of \fIaccept()\fIing when you can't\fR 1841\fIThe special problem of \f(BIaccept()\fIing when you can't\fR
1815.IX Subsection "The special problem of accept()ing when you can't" 1842.IX Subsection "The special problem of accept()ing when you can't"
1816.PP 1843.PP
1817Many implementations of the \s-1POSIX \s0\f(CW\*(C`accept\*(C'\fR function (for example, 1844Many implementations of the \s-1POSIX\s0 \f(CW\*(C`accept\*(C'\fR function (for example,
1818found in post\-2004 Linux) have the peculiar behaviour of not removing a 1845found in post\-2004 Linux) have the peculiar behaviour of not removing a
1819connection from the pending queue in all error cases. 1846connection from the pending queue in all error cases.
1820.PP 1847.PP
1821For example, larger servers often run out of file descriptors (because 1848For example, larger servers often run out of file descriptors (because
1822of resource limits), causing \f(CW\*(C`accept\*(C'\fR to fail with \f(CW\*(C`ENFILE\*(C'\fR but not 1849of resource limits), causing \f(CW\*(C`accept\*(C'\fR to fail with \f(CW\*(C`ENFILE\*(C'\fR but not
2161.PP 2188.PP
2162The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR 2189The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR
2163time. This is usually the right thing as this timestamp refers to the time 2190time. This is usually the right thing as this timestamp refers to the time
2164of the event triggering whatever timeout you are modifying/starting. If 2191of the event triggering whatever timeout you are modifying/starting. If
2165you suspect event processing to be delayed and you \fIneed\fR to base the 2192you suspect event processing to be delayed and you \fIneed\fR to base the
2166timeout on the current time, use something like this to adjust for this: 2193timeout on the current time, use something like the following to adjust
2194for it:
2167.PP 2195.PP
2168.Vb 1 2196.Vb 1
2169\& ev_timer_set (&timer, after + ev_now () \- ev_time (), 0.); 2197\& ev_timer_set (&timer, after + (ev_time () \- ev_now ()), 0.);
2170.Ve 2198.Ve
2171.PP 2199.PP
2172If the event loop is suspended for a long time, you can also force an 2200If the event loop is suspended for a long time, you can also force an
2173update of the time returned by \f(CW\*(C`ev_now ()\*(C'\fR by calling \f(CW\*(C`ev_now_update 2201update of the time returned by \f(CW\*(C`ev_now ()\*(C'\fR by calling \f(CW\*(C`ev_now_update
2174()\*(C'\fR. 2202()\*(C'\fR, although that will push the event time of all outstanding events
2203further into the future.
2175.PP 2204.PP
2176\fIThe special problem of unsynchronised clocks\fR 2205\fIThe special problem of unsynchronised clocks\fR
2177.IX Subsection "The special problem of unsynchronised clocks" 2206.IX Subsection "The special problem of unsynchronised clocks"
2178.PP 2207.PP
2179Modern systems have a variety of clocks \- libev itself uses the normal 2208Modern systems have a variety of clocks \- libev itself uses the normal
2244.IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" 2273.IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)"
2245.PD 0 2274.PD 0
2246.IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4 2275.IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4
2247.IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 2276.IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)"
2248.PD 2277.PD
2249Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds. If \f(CW\*(C`repeat\*(C'\fR 2278Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds (fractional and
2250is \f(CW0.\fR, then it will automatically be stopped once the timeout is 2279negative values are supported). If \f(CW\*(C`repeat\*(C'\fR is \f(CW0.\fR, then it will
2251reached. If it is positive, then the timer will automatically be 2280automatically be stopped once the timeout is reached. If it is positive,
2252configured to trigger again \f(CW\*(C`repeat\*(C'\fR seconds later, again, and again, 2281then the timer will automatically be configured to trigger again \f(CW\*(C`repeat\*(C'\fR
2253until stopped manually. 2282seconds later, again, and again, until stopped manually.
2254.Sp 2283.Sp
2255The timer itself will do a best-effort at avoiding drift, that is, if 2284The timer itself will do a best-effort at avoiding drift, that is, if
2256you configure a timer to trigger every 10 seconds, then it will normally 2285you configure a timer to trigger every 10 seconds, then it will normally
2257trigger at exactly 10 second intervals. If, however, your program cannot 2286trigger at exactly 10 second intervals. If, however, your program cannot
2258keep up with the timer (because it takes longer than those 10 seconds to 2287keep up with the timer (because it takes longer than those 10 seconds to
2340Periodic watchers are also timers of a kind, but they are very versatile 2369Periodic watchers are also timers of a kind, but they are very versatile
2341(and unfortunately a bit complex). 2370(and unfortunately a bit complex).
2342.PP 2371.PP
2343Unlike \f(CW\*(C`ev_timer\*(C'\fR, periodic watchers are not based on real time (or 2372Unlike \f(CW\*(C`ev_timer\*(C'\fR, periodic watchers are not based on real time (or
2344relative time, the physical time that passes) but on wall clock time 2373relative time, the physical time that passes) but on wall clock time
2345(absolute time, the thing you can read on your calender or clock). The 2374(absolute time, the thing you can read on your calendar or clock). The
2346difference is that wall clock time can run faster or slower than real 2375difference is that wall clock time can run faster or slower than real
2347time, and time jumps are not uncommon (e.g. when you adjust your 2376time, and time jumps are not uncommon (e.g. when you adjust your
2348wrist-watch). 2377wrist-watch).
2349.PP 2378.PP
2350You can tell a periodic watcher to trigger after some specific point 2379You can tell a periodic watcher to trigger after some specific point
2355\&\f(CW\*(C`ev_timer\*(C'\fR, which would still trigger roughly 10 seconds after starting 2384\&\f(CW\*(C`ev_timer\*(C'\fR, which would still trigger roughly 10 seconds after starting
2356it, as it uses a relative timeout). 2385it, as it uses a relative timeout).
2357.PP 2386.PP
2358\&\f(CW\*(C`ev_periodic\*(C'\fR watchers can also be used to implement vastly more complex 2387\&\f(CW\*(C`ev_periodic\*(C'\fR watchers can also be used to implement vastly more complex
2359timers, such as triggering an event on each \*(L"midnight, local time\*(R", or 2388timers, such as triggering an event on each \*(L"midnight, local time\*(R", or
2360other complicated rules. This cannot be done with \f(CW\*(C`ev_timer\*(C'\fR watchers, as 2389other complicated rules. This cannot easily be done with \f(CW\*(C`ev_timer\*(C'\fR
2361those cannot react to time jumps. 2390watchers, as those cannot react to time jumps.
2362.PP 2391.PP
2363As with timers, the callback is guaranteed to be invoked only when the 2392As with timers, the callback is guaranteed to be invoked only when the
2364point in time where it is supposed to trigger has passed. If multiple 2393point in time where it is supposed to trigger has passed. If multiple
2365timers become ready during the same loop iteration then the ones with 2394timers become ready during the same loop iteration then the ones with
2366earlier time-out values are invoked before ones with later time-out values 2395earlier time-out values are invoked before ones with later time-out values
2427In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`offset\*(C'\fR are both being 2456In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`offset\*(C'\fR are both being
2428ignored. Instead, each time the periodic watcher gets scheduled, the 2457ignored. Instead, each time the periodic watcher gets scheduled, the
2429reschedule callback will be called with the watcher as first, and the 2458reschedule callback will be called with the watcher as first, and the
2430current time as second argument. 2459current time as second argument.
2431.Sp 2460.Sp
2432\&\s-1NOTE: \s0\fIThis callback \s-1MUST NOT\s0 stop or destroy any periodic watcher, ever, 2461\&\s-1NOTE:\s0 \fIThis callback \s-1MUST NOT\s0 stop or destroy any periodic watcher, ever,
2433or make \s-1ANY\s0 other event loop modifications whatsoever, unless explicitly 2462or make \s-1ANY\s0 other event loop modifications whatsoever, unless explicitly
2434allowed by documentation here\fR. 2463allowed by documentation here\fR.
2435.Sp 2464.Sp
2436If you need to stop it, return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop 2465If you need to stop it, return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop
2437it afterwards (e.g. by starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is the 2466it afterwards (e.g. by starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is the
2451It must return the next time to trigger, based on the passed time value 2480It must return the next time to trigger, based on the passed time value
2452(that is, the lowest time value larger than to the second argument). It 2481(that is, the lowest time value larger than to the second argument). It
2453will usually be called just before the callback will be triggered, but 2482will usually be called just before the callback will be triggered, but
2454might be called at other times, too. 2483might be called at other times, too.
2455.Sp 2484.Sp
2456\&\s-1NOTE: \s0\fIThis callback must always return a time that is higher than or 2485\&\s-1NOTE:\s0 \fIThis callback must always return a time that is higher than or
2457equal to the passed \f(CI\*(C`now\*(C'\fI value\fR. 2486equal to the passed \f(CI\*(C`now\*(C'\fI value\fR.
2458.Sp 2487.Sp
2459This can be used to create very complex timers, such as a timer that 2488This can be used to create very complex timers, such as a timer that
2460triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate the 2489triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate
2461next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for this. How 2490the next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for
2462you do this is, again, up to you (but it is not trivial, which is the main 2491this. Here is a (completely untested, no error checking) example on how to
2463reason I omitted it as an example). 2492do this:
2493.Sp
2494.Vb 1
2495\& #include <time.h>
2496\&
2497\& static ev_tstamp
2498\& my_rescheduler (ev_periodic *w, ev_tstamp now)
2499\& {
2500\& time_t tnow = (time_t)now;
2501\& struct tm tm;
2502\& localtime_r (&tnow, &tm);
2503\&
2504\& tm.tm_sec = tm.tm_min = tm.tm_hour = 0; // midnight current day
2505\& ++tm.tm_mday; // midnight next day
2506\&
2507\& return mktime (&tm);
2508\& }
2509.Ve
2510.Sp
2511Note: this code might run into trouble on days that have more then two
2512midnights (beginning and end).
2464.RE 2513.RE
2465.RS 4 2514.RS 4
2466.RE 2515.RE
2467.IP "ev_periodic_again (loop, ev_periodic *)" 4 2516.IP "ev_periodic_again (loop, ev_periodic *)" 4
2468.IX Item "ev_periodic_again (loop, ev_periodic *)" 2517.IX Item "ev_periodic_again (loop, ev_periodic *)"
2586The simplest way to ensure that the signal mask is reset in the child is 2635The simplest way to ensure that the signal mask is reset in the child is
2587to install a fork handler with \f(CW\*(C`pthread_atfork\*(C'\fR that resets it. That will 2636to install a fork handler with \f(CW\*(C`pthread_atfork\*(C'\fR that resets it. That will
2588catch fork calls done by libraries (such as the libc) as well. 2637catch fork calls done by libraries (such as the libc) as well.
2589.PP 2638.PP
2590In current versions of libev, the signal will not be blocked indefinitely 2639In current versions of libev, the signal will not be blocked indefinitely
2591unless you use the \f(CW\*(C`signalfd\*(C'\fR \s-1API \s0(\f(CW\*(C`EV_SIGNALFD\*(C'\fR). While this reduces 2640unless you use the \f(CW\*(C`signalfd\*(C'\fR \s-1API\s0 (\f(CW\*(C`EV_SIGNALFD\*(C'\fR). While this reduces
2592the window of opportunity for problems, it will not go away, as libev 2641the window of opportunity for problems, it will not go away, as libev
2593\&\fIhas\fR to modify the signal mask, at least temporarily. 2642\&\fIhas\fR to modify the signal mask, at least temporarily.
2594.PP 2643.PP
2595So I can't stress this enough: \fIIf you do not reset your signal mask when 2644So I can't stress this enough: \fIIf you do not reset your signal mask when
2596you expect it to be empty, you have a race condition in your code\fR. This 2645you expect it to be empty, you have a race condition in your code\fR. This
3048.IX Subsection "ev_prepare and ev_check - customise your event loop!" 3097.IX Subsection "ev_prepare and ev_check - customise your event loop!"
3049Prepare and check watchers are often (but not always) used in pairs: 3098Prepare and check watchers are often (but not always) used in pairs:
3050prepare watchers get invoked before the process blocks and check watchers 3099prepare watchers get invoked before the process blocks and check watchers
3051afterwards. 3100afterwards.
3052.PP 3101.PP
3053You \fImust not\fR call \f(CW\*(C`ev_run\*(C'\fR or similar functions that enter 3102You \fImust not\fR call \f(CW\*(C`ev_run\*(C'\fR (or similar functions that enter the
3054the current event loop from either \f(CW\*(C`ev_prepare\*(C'\fR or \f(CW\*(C`ev_check\*(C'\fR 3103current event loop) or \f(CW\*(C`ev_loop_fork\*(C'\fR from either \f(CW\*(C`ev_prepare\*(C'\fR or
3055watchers. Other loops than the current one are fine, however. The 3104\&\f(CW\*(C`ev_check\*(C'\fR watchers. Other loops than the current one are fine,
3056rationale behind this is that you do not need to check for recursion in 3105however. The rationale behind this is that you do not need to check
3057those watchers, i.e. the sequence will always be \f(CW\*(C`ev_prepare\*(C'\fR, blocking, 3106for recursion in those watchers, i.e. the sequence will always be
3058\&\f(CW\*(C`ev_check\*(C'\fR so if you have one watcher of each kind they will always be 3107\&\f(CW\*(C`ev_prepare\*(C'\fR, blocking, \f(CW\*(C`ev_check\*(C'\fR so if you have one watcher of each
3059called in pairs bracketing the blocking call. 3108kind they will always be called in pairs bracketing the blocking call.
3060.PP 3109.PP
3061Their main purpose is to integrate other event mechanisms into libev and 3110Their main purpose is to integrate other event mechanisms into libev and
3062their use is somewhat advanced. They could be used, for example, to track 3111their use is somewhat advanced. They could be used, for example, to track
3063variable changes, implement your own watchers, integrate net-snmp or a 3112variable changes, implement your own watchers, integrate net-snmp or a
3064coroutine library and lots more. They are also occasionally useful if 3113coroutine library and lots more. They are also occasionally useful if
3358.PP 3407.PP
3359.Vb 3 3408.Vb 3
3360\& struct ev_loop *loop_hi = ev_default_init (0); 3409\& struct ev_loop *loop_hi = ev_default_init (0);
3361\& struct ev_loop *loop_lo = 0; 3410\& struct ev_loop *loop_lo = 0;
3362\& ev_embed embed; 3411\& ev_embed embed;
3363\& 3412\&
3364\& // see if there is a chance of getting one that works 3413\& // see if there is a chance of getting one that works
3365\& // (remember that a flags value of 0 means autodetection) 3414\& // (remember that a flags value of 0 means autodetection)
3366\& loop_lo = ev_embeddable_backends () & ev_recommended_backends () 3415\& loop_lo = ev_embeddable_backends () & ev_recommended_backends ()
3367\& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ()) 3416\& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ())
3368\& : 0; 3417\& : 0;
3384.PP 3433.PP
3385.Vb 3 3434.Vb 3
3386\& struct ev_loop *loop = ev_default_init (0); 3435\& struct ev_loop *loop = ev_default_init (0);
3387\& struct ev_loop *loop_socket = 0; 3436\& struct ev_loop *loop_socket = 0;
3388\& ev_embed embed; 3437\& ev_embed embed;
3389\& 3438\&
3390\& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) 3439\& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE)
3391\& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE)) 3440\& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE))
3392\& { 3441\& {
3393\& ev_embed_init (&embed, 0, loop_socket); 3442\& ev_embed_init (&embed, 0, loop_socket);
3394\& ev_embed_start (loop, &embed); 3443\& ev_embed_start (loop, &embed);
3411of course. 3460of course.
3412.PP 3461.PP
3413\fIThe special problem of life after fork \- how is it possible?\fR 3462\fIThe special problem of life after fork \- how is it possible?\fR
3414.IX Subsection "The special problem of life after fork - how is it possible?" 3463.IX Subsection "The special problem of life after fork - how is it possible?"
3415.PP 3464.PP
3416Most uses of \f(CW\*(C`fork()\*(C'\fR consist of forking, then some simple calls to set 3465Most uses of \f(CW\*(C`fork ()\*(C'\fR consist of forking, then some simple calls to set
3417up/change the process environment, followed by a call to \f(CW\*(C`exec()\*(C'\fR. This 3466up/change the process environment, followed by a call to \f(CW\*(C`exec()\*(C'\fR. This
3418sequence should be handled by libev without any problems. 3467sequence should be handled by libev without any problems.
3419.PP 3468.PP
3420This changes when the application actually wants to do event handling 3469This changes when the application actually wants to do event handling
3421in the child, or both parent in child, in effect \*(L"continuing\*(R" after the 3470in the child, or both parent in child, in effect \*(L"continuing\*(R" after the
3638is a time window between the event loop checking and resetting the async 3687is a time window between the event loop checking and resetting the async
3639notification, and the callback being invoked. 3688notification, and the callback being invoked.
3640.SH "OTHER FUNCTIONS" 3689.SH "OTHER FUNCTIONS"
3641.IX Header "OTHER FUNCTIONS" 3690.IX Header "OTHER FUNCTIONS"
3642There are some other functions of possible interest. Described. Here. Now. 3691There are some other functions of possible interest. Described. Here. Now.
3643.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4 3692.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback, arg)" 4
3644.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 3693.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback, arg)"
3645This function combines a simple timer and an I/O watcher, calls your 3694This function combines a simple timer and an I/O watcher, calls your
3646callback on whichever event happens first and automatically stops both 3695callback on whichever event happens first and automatically stops both
3647watchers. This is useful if you want to wait for a single event on an fd 3696watchers. This is useful if you want to wait for a single event on an fd
3648or timeout without having to allocate/configure/start/stop/free one or 3697or timeout without having to allocate/configure/start/stop/free one or
3649more watchers yourself. 3698more watchers yourself.
4049files, \fImy_ev.h\fR and \fImy_ev.c\fR that include the respective libev files: 4098files, \fImy_ev.h\fR and \fImy_ev.c\fR that include the respective libev files:
4050.PP 4099.PP
4051.Vb 4 4100.Vb 4
4052\& // my_ev.h 4101\& // my_ev.h
4053\& #define EV_CB_DECLARE(type) struct my_coro *cb; 4102\& #define EV_CB_DECLARE(type) struct my_coro *cb;
4054\& #define EV_CB_INVOKE(watcher) switch_to ((watcher)\->cb); 4103\& #define EV_CB_INVOKE(watcher) switch_to ((watcher)\->cb)
4055\& #include "../libev/ev.h" 4104\& #include "../libev/ev.h"
4056\& 4105\&
4057\& // my_ev.c 4106\& // my_ev.c
4058\& #define EV_H "my_ev.h" 4107\& #define EV_H "my_ev.h"
4059\& #include "../libev/ev.c" 4108\& #include "../libev/ev.c"
4099The normal C \s-1API\s0 should work fine when used from \*(C+: both ev.h and the 4148The normal C \s-1API\s0 should work fine when used from \*(C+: both ev.h and the
4100libev sources can be compiled as \*(C+. Therefore, code that uses the C \s-1API\s0 4149libev sources can be compiled as \*(C+. Therefore, code that uses the C \s-1API\s0
4101will work fine. 4150will work fine.
4102.PP 4151.PP
4103Proper exception specifications might have to be added to callbacks passed 4152Proper exception specifications might have to be added to callbacks passed
4104to libev: exceptions may be thrown only from watcher callbacks, all 4153to libev: exceptions may be thrown only from watcher callbacks, all other
4105other callbacks (allocator, syserr, loop acquire/release and periodic 4154callbacks (allocator, syserr, loop acquire/release and periodic reschedule
4106reschedule callbacks) must not throw exceptions, and might need a \f(CW\*(C`throw 4155callbacks) must not throw exceptions, and might need a \f(CW\*(C`noexcept\*(C'\fR
4107()\*(C'\fR specification. If you have code that needs to be compiled as both C 4156specification. If you have code that needs to be compiled as both C and
4108and \*(C+ you can use the \f(CW\*(C`EV_THROW\*(C'\fR macro for this: 4157\&\*(C+ you can use the \f(CW\*(C`EV_NOEXCEPT\*(C'\fR macro for this:
4109.PP 4158.PP
4110.Vb 6 4159.Vb 6
4111\& static void 4160\& static void
4112\& fatal_error (const char *msg) EV_THROW 4161\& fatal_error (const char *msg) EV_NOEXCEPT
4113\& { 4162\& {
4114\& perror (msg); 4163\& perror (msg);
4115\& abort (); 4164\& abort ();
4116\& } 4165\& }
4117\& 4166\&
4245\& void operator() (ev::io &w, int revents) 4294\& void operator() (ev::io &w, int revents)
4246\& { 4295\& {
4247\& ... 4296\& ...
4248\& } 4297\& }
4249\& } 4298\& }
4250\& 4299\&
4251\& myfunctor f; 4300\& myfunctor f;
4252\& 4301\&
4253\& ev::io w; 4302\& ev::io w;
4254\& w.set (&f); 4303\& w.set (&f);
4255.Ve 4304.Ve
4491\& #include "ev.c" 4540\& #include "ev.c"
4492.Ve 4541.Ve
4493.PP 4542.PP
4494This will automatically include \fIev.h\fR, too, and should be done in a 4543This will automatically include \fIev.h\fR, too, and should be done in a
4495single C source file only to provide the function implementations. To use 4544single C source file only to provide the function implementations. To use
4496it, do the same for \fIev.h\fR in all files wishing to use this \s-1API \s0(best 4545it, do the same for \fIev.h\fR in all files wishing to use this \s-1API\s0 (best
4497done by writing a wrapper around \fIev.h\fR that you can include instead and 4546done by writing a wrapper around \fIev.h\fR that you can include instead and
4498where you can put other configuration options): 4547where you can put other configuration options):
4499.PP 4548.PP
4500.Vb 2 4549.Vb 2
4501\& #define EV_STANDALONE 1 4550\& #define EV_STANDALONE 1
4515\& ev_vars.h 4564\& ev_vars.h
4516\& ev_wrap.h 4565\& ev_wrap.h
4517\& 4566\&
4518\& ev_win32.c required on win32 platforms only 4567\& ev_win32.c required on win32 platforms only
4519\& 4568\&
4520\& ev_select.c only when select backend is enabled (which is enabled by default) 4569\& ev_select.c only when select backend is enabled
4521\& ev_poll.c only when poll backend is enabled (disabled by default) 4570\& ev_poll.c only when poll backend is enabled
4522\& ev_epoll.c only when the epoll backend is enabled (disabled by default) 4571\& ev_epoll.c only when the epoll backend is enabled
4523\& ev_kqueue.c only when the kqueue backend is enabled (disabled by default) 4572\& ev_kqueue.c only when the kqueue backend is enabled
4524\& ev_port.c only when the solaris port backend is enabled (disabled by default) 4573\& ev_port.c only when the solaris port backend is enabled
4525.Ve 4574.Ve
4526.PP 4575.PP
4527\&\fIev.c\fR includes the backend files directly when enabled, so you only need 4576\&\fIev.c\fR includes the backend files directly when enabled, so you only need
4528to compile this single file. 4577to compile this single file.
4529.PP 4578.PP
4574values when compiling libev vs. including \fIev.h\fR, so it is permissible 4623values when compiling libev vs. including \fIev.h\fR, so it is permissible
4575to redefine them before including \fIev.h\fR without breaking compatibility 4624to redefine them before including \fIev.h\fR without breaking compatibility
4576to a compiled library. All other symbols change the \s-1ABI,\s0 which means all 4625to a compiled library. All other symbols change the \s-1ABI,\s0 which means all
4577users of libev and the libev code itself must be compiled with compatible 4626users of libev and the libev code itself must be compiled with compatible
4578settings. 4627settings.
4579.IP "\s-1EV_COMPAT3 \s0(h)" 4 4628.IP "\s-1EV_COMPAT3\s0 (h)" 4
4580.IX Item "EV_COMPAT3 (h)" 4629.IX Item "EV_COMPAT3 (h)"
4581Backwards compatibility is a major concern for libev. This is why this 4630Backwards compatibility is a major concern for libev. This is why this
4582release of libev comes with wrappers for the functions and symbols that 4631release of libev comes with wrappers for the functions and symbols that
4583have been renamed between libev version 3 and 4. 4632have been renamed between libev version 3 and 4.
4584.Sp 4633.Sp
4589typedef in that case. 4638typedef in that case.
4590.Sp 4639.Sp
4591In some future version, the default for \f(CW\*(C`EV_COMPAT3\*(C'\fR will become \f(CW0\fR, 4640In some future version, the default for \f(CW\*(C`EV_COMPAT3\*(C'\fR will become \f(CW0\fR,
4592and in some even more future version the compatibility code will be 4641and in some even more future version the compatibility code will be
4593removed completely. 4642removed completely.
4594.IP "\s-1EV_STANDALONE \s0(h)" 4 4643.IP "\s-1EV_STANDALONE\s0 (h)" 4
4595.IX Item "EV_STANDALONE (h)" 4644.IX Item "EV_STANDALONE (h)"
4596Must always be \f(CW1\fR if you do not use autoconf configuration, which 4645Must always be \f(CW1\fR if you do not use autoconf configuration, which
4597keeps libev from including \fIconfig.h\fR, and it also defines dummy 4646keeps libev from including \fIconfig.h\fR, and it also defines dummy
4598implementations for some libevent functions (such as logging, which is not 4647implementations for some libevent functions (such as logging, which is not
4599supported). It will also not define any of the structs usually found in 4648supported). It will also not define any of the structs usually found in
4757handler \*(L"locking\*(R" as well as for signal and thread safety in \f(CW\*(C`ev_async\*(C'\fR 4806handler \*(L"locking\*(R" as well as for signal and thread safety in \f(CW\*(C`ev_async\*(C'\fR
4758watchers. 4807watchers.
4759.Sp 4808.Sp
4760In the absence of this define, libev will use \f(CW\*(C`sig_atomic_t volatile\*(C'\fR 4809In the absence of this define, libev will use \f(CW\*(C`sig_atomic_t volatile\*(C'\fR
4761(from \fIsignal.h\fR), which is usually good enough on most platforms. 4810(from \fIsignal.h\fR), which is usually good enough on most platforms.
4762.IP "\s-1EV_H \s0(h)" 4 4811.IP "\s-1EV_H\s0 (h)" 4
4763.IX Item "EV_H (h)" 4812.IX Item "EV_H (h)"
4764The name of the \fIev.h\fR header file used to include it. The default if 4813The name of the \fIev.h\fR header file used to include it. The default if
4765undefined is \f(CW"ev.h"\fR in \fIevent.h\fR, \fIev.c\fR and \fIev++.h\fR. This can be 4814undefined is \f(CW"ev.h"\fR in \fIevent.h\fR, \fIev.c\fR and \fIev++.h\fR. This can be
4766used to virtually rename the \fIev.h\fR header file in case of conflicts. 4815used to virtually rename the \fIev.h\fR header file in case of conflicts.
4767.IP "\s-1EV_CONFIG_H \s0(h)" 4 4816.IP "\s-1EV_CONFIG_H\s0 (h)" 4
4768.IX Item "EV_CONFIG_H (h)" 4817.IX Item "EV_CONFIG_H (h)"
4769If \f(CW\*(C`EV_STANDALONE\*(C'\fR isn't \f(CW1\fR, this variable can be used to override 4818If \f(CW\*(C`EV_STANDALONE\*(C'\fR isn't \f(CW1\fR, this variable can be used to override
4770\&\fIev.c\fR's idea of where to find the \fIconfig.h\fR file, similarly to 4819\&\fIev.c\fR's idea of where to find the \fIconfig.h\fR file, similarly to
4771\&\f(CW\*(C`EV_H\*(C'\fR, above. 4820\&\f(CW\*(C`EV_H\*(C'\fR, above.
4772.IP "\s-1EV_EVENT_H \s0(h)" 4 4821.IP "\s-1EV_EVENT_H\s0 (h)" 4
4773.IX Item "EV_EVENT_H (h)" 4822.IX Item "EV_EVENT_H (h)"
4774Similarly to \f(CW\*(C`EV_H\*(C'\fR, this macro can be used to override \fIevent.c\fR's idea 4823Similarly to \f(CW\*(C`EV_H\*(C'\fR, this macro can be used to override \fIevent.c\fR's idea
4775of how the \fIevent.h\fR header can be found, the default is \f(CW"event.h"\fR. 4824of how the \fIevent.h\fR header can be found, the default is \f(CW"event.h"\fR.
4776.IP "\s-1EV_PROTOTYPES \s0(h)" 4 4825.IP "\s-1EV_PROTOTYPES\s0 (h)" 4
4777.IX Item "EV_PROTOTYPES (h)" 4826.IX Item "EV_PROTOTYPES (h)"
4778If defined to be \f(CW0\fR, then \fIev.h\fR will not define any function 4827If defined to be \f(CW0\fR, then \fIev.h\fR will not define any function
4779prototypes, but still define all the structs and other symbols. This is 4828prototypes, but still define all the structs and other symbols. This is
4780occasionally useful if you want to provide your own wrapper functions 4829occasionally useful if you want to provide your own wrapper functions
4781around libev functions. 4830around libev functions.
4990.Vb 3 5039.Vb 3
4991\& #define EV_COMMON \e 5040\& #define EV_COMMON \e
4992\& SV *self; /* contains this struct */ \e 5041\& SV *self; /* contains this struct */ \e
4993\& SV *cb_sv, *fh /* note no trailing ";" */ 5042\& SV *cb_sv, *fh /* note no trailing ";" */
4994.Ve 5043.Ve
4995.IP "\s-1EV_CB_DECLARE \s0(type)" 4 5044.IP "\s-1EV_CB_DECLARE\s0 (type)" 4
4996.IX Item "EV_CB_DECLARE (type)" 5045.IX Item "EV_CB_DECLARE (type)"
4997.PD 0 5046.PD 0
4998.IP "\s-1EV_CB_INVOKE \s0(watcher, revents)" 4 5047.IP "\s-1EV_CB_INVOKE\s0 (watcher, revents)" 4
4999.IX Item "EV_CB_INVOKE (watcher, revents)" 5048.IX Item "EV_CB_INVOKE (watcher, revents)"
5000.IP "ev_set_cb (ev, cb)" 4 5049.IP "ev_set_cb (ev, cb)" 4
5001.IX Item "ev_set_cb (ev, cb)" 5050.IX Item "ev_set_cb (ev, cb)"
5002.PD 5051.PD
5003Can be used to change the callback member declaration in each watcher, 5052Can be used to change the callback member declaration in each watcher,
5006their default definitions. One possible use for overriding these is to 5055their default definitions. One possible use for overriding these is to
5007avoid the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument in all cases, or to use 5056avoid the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument in all cases, or to use
5008method calls instead of plain function calls in \*(C+. 5057method calls instead of plain function calls in \*(C+.
5009.SS "\s-1EXPORTED API SYMBOLS\s0" 5058.SS "\s-1EXPORTED API SYMBOLS\s0"
5010.IX Subsection "EXPORTED API SYMBOLS" 5059.IX Subsection "EXPORTED API SYMBOLS"
5011If you need to re-export the \s-1API \s0(e.g. via a \s-1DLL\s0) and you need a list of 5060If you need to re-export the \s-1API\s0 (e.g. via a \s-1DLL\s0) and you need a list of
5012exported symbols, you can use the provided \fISymbol.*\fR files which list 5061exported symbols, you can use the provided \fISymbol.*\fR files which list
5013all public symbols, one per line: 5062all public symbols, one per line:
5014.PP 5063.PP
5015.Vb 2 5064.Vb 2
5016\& Symbols.ev for libev proper 5065\& Symbols.ev for libev proper
5248.PP 5297.PP
5249\fI\f(CI\*(C`select\*(C'\fI is buggy\fR 5298\fI\f(CI\*(C`select\*(C'\fI is buggy\fR
5250.IX Subsection "select is buggy" 5299.IX Subsection "select is buggy"
5251.PP 5300.PP
5252All that's left is \f(CW\*(C`select\*(C'\fR, and of course Apple found a way to fuck this 5301All that's left is \f(CW\*(C`select\*(C'\fR, and of course Apple found a way to fuck this
5253one up as well: On \s-1OS/X, \s0\f(CW\*(C`select\*(C'\fR actively limits the number of file 5302one up as well: On \s-1OS/X,\s0 \f(CW\*(C`select\*(C'\fR actively limits the number of file
5254descriptors you can pass in to 1024 \- your program suddenly crashes when 5303descriptors you can pass in to 1024 \- your program suddenly crashes when
5255you use more. 5304you use more.
5256.PP 5305.PP
5257There is an undocumented \*(L"workaround\*(R" for this \- defining 5306There is an undocumented \*(L"workaround\*(R" for this \- defining
5258\&\f(CW\*(C`_DARWIN_UNLIMITED_SELECT\*(C'\fR, which libev tries to use, so select \fIshould\fR 5307\&\f(CW\*(C`_DARWIN_UNLIMITED_SELECT\*(C'\fR, which libev tries to use, so select \fIshould\fR
5406Libev assumes not only that all watcher pointers have the same internal 5455Libev assumes not only that all watcher pointers have the same internal
5407structure (guaranteed by \s-1POSIX\s0 but not by \s-1ISO C\s0 for example), but it also 5456structure (guaranteed by \s-1POSIX\s0 but not by \s-1ISO C\s0 for example), but it also
5408assumes that the same (machine) code can be used to call any watcher 5457assumes that the same (machine) code can be used to call any watcher
5409callback: The watcher callbacks have different type signatures, but libev 5458callback: The watcher callbacks have different type signatures, but libev
5410calls them using an \f(CW\*(C`ev_watcher *\*(C'\fR internally. 5459calls them using an \f(CW\*(C`ev_watcher *\*(C'\fR internally.
5460.IP "null pointers and integer zero are represented by 0 bytes" 4
5461.IX Item "null pointers and integer zero are represented by 0 bytes"
5462Libev uses \f(CW\*(C`memset\*(C'\fR to initialise structs and arrays to \f(CW0\fR bytes, and
5463relies on this setting pointers and integers to null.
5411.IP "pointer accesses must be thread-atomic" 4 5464.IP "pointer accesses must be thread-atomic" 4
5412.IX Item "pointer accesses must be thread-atomic" 5465.IX Item "pointer accesses must be thread-atomic"
5413Accessing a pointer value must be atomic, it must both be readable and 5466Accessing a pointer value must be atomic, it must both be readable and
5414writable in one piece \- this is the case on all current architectures. 5467writable in one piece \- this is the case on all current architectures.
5415.ie n .IP """sig_atomic_t volatile"" must be thread-atomic as well" 4 5468.ie n .IP """sig_atomic_t volatile"" must be thread-atomic as well" 4

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines