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

Comparing libev/ev.3 (file contents):
Revision 1.100 by root, Tue Oct 29 12:13:37 2013 UTC vs.
Revision 1.107 by root, Wed Jun 21 14:42:30 2017 UTC

1.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) 1.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
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
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-10-29" "libev-4.15" "libev - high performance full featured event loop" 136.TH LIBEV 3 "2017-06-21" "libev-4.24" "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"
541GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn sequence 541GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn sequence
542without a system call and thus \fIvery\fR fast, but my GNU/Linux system also has 542without a system call and thus \fIvery\fR fast, but my GNU/Linux system also has
543\&\f(CW\*(C`pthread_atfork\*(C'\fR which is even faster). 543\&\f(CW\*(C`pthread_atfork\*(C'\fR which is even faster).
544.Sp 544.Sp
545The big advantage of this flag is that you can forget about fork (and 545The 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 546forget about forgetting to tell libev about forking, although you still
547flag. 547have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR) when you use this flag.
548.Sp 548.Sp
549This flag setting cannot be overridden or specified in the \f(CW\*(C`LIBEV_FLAGS\*(C'\fR 549This flag setting cannot be overridden or specified in the \f(CW\*(C`LIBEV_FLAGS\*(C'\fR
550environment variable. 550environment variable.
551.ie n .IP """EVFLAG_NOINOTIFY""" 4 551.ie n .IP """EVFLAG_NOINOTIFY""" 4
552.el .IP "\f(CWEVFLAG_NOINOTIFY\fR" 4 552.el .IP "\f(CWEVFLAG_NOINOTIFY\fR" 4
810except in the rare occasion where you really need to free its resources. 810except 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 811If 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. 812and \f(CW\*(C`ev_loop_destroy\*(C'\fR.
813.IP "ev_loop_fork (loop)" 4 813.IP "ev_loop_fork (loop)" 4
814.IX Item "ev_loop_fork (loop)" 814.IX Item "ev_loop_fork (loop)"
815This function sets a flag that causes subsequent \f(CW\*(C`ev_run\*(C'\fR iterations to 815This 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 816to reinitialise the kernel state for backends that have one. Despite
817name, you can call it anytime, but it makes most sense after forking, in 817the 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 818watchers (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. 819sense after forking, in the child process. You \fImust\fR call it (or use
820\&\f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR) in the child before resuming or calling \f(CW\*(C`ev_run\*(C'\fR.
821.Sp
822In addition, if you want to reuse a loop (via this function or
823\&\f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR), you \fIalso\fR have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR.
820.Sp 824.Sp
821Again, you \fIhave\fR to call it on \fIany\fR loop that you want to re-use after 825Again, 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 826a 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 827because some kernel interfaces *cough* \fIkqueue\fR *cough* do funny things
824during fork. 828during fork.
2161.PP 2165.PP
2162The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR 2166The 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 2167time. This is usually the right thing as this timestamp refers to the time
2164of the event triggering whatever timeout you are modifying/starting. If 2168of the event triggering whatever timeout you are modifying/starting. If
2165you suspect event processing to be delayed and you \fIneed\fR to base the 2169you 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: 2170timeout on the current time, use something like the following to adjust
2171for it:
2167.PP 2172.PP
2168.Vb 1 2173.Vb 1
2169\& ev_timer_set (&timer, after + ev_now () \- ev_time (), 0.); 2174\& ev_timer_set (&timer, after + (ev_time () \- ev_now ()), 0.);
2170.Ve 2175.Ve
2171.PP 2176.PP
2172If the event loop is suspended for a long time, you can also force an 2177If 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 2178update of the time returned by \f(CW\*(C`ev_now ()\*(C'\fR by calling \f(CW\*(C`ev_now_update
2174()\*(C'\fR. 2179()\*(C'\fR, although that will push the event time of all outstanding events
2180further into the future.
2175.PP 2181.PP
2176\fIThe special problem of unsynchronised clocks\fR 2182\fIThe special problem of unsynchronised clocks\fR
2177.IX Subsection "The special problem of unsynchronised clocks" 2183.IX Subsection "The special problem of unsynchronised clocks"
2178.PP 2184.PP
2179Modern systems have a variety of clocks \- libev itself uses the normal 2185Modern systems have a variety of clocks \- libev itself uses the normal
2340Periodic watchers are also timers of a kind, but they are very versatile 2346Periodic watchers are also timers of a kind, but they are very versatile
2341(and unfortunately a bit complex). 2347(and unfortunately a bit complex).
2342.PP 2348.PP
2343Unlike \f(CW\*(C`ev_timer\*(C'\fR, periodic watchers are not based on real time (or 2349Unlike \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 2350relative 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 2351(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 2352difference 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 2353time, and time jumps are not uncommon (e.g. when you adjust your
2348wrist-watch). 2354wrist-watch).
2349.PP 2355.PP
2350You can tell a periodic watcher to trigger after some specific point 2356You can tell a periodic watcher to trigger after some specific point
2553only within the same loop, i.e. you can watch for \f(CW\*(C`SIGINT\*(C'\fR in your 2559only within the same loop, i.e. you can watch for \f(CW\*(C`SIGINT\*(C'\fR in your
2554default loop and for \f(CW\*(C`SIGIO\*(C'\fR in another loop, but you cannot watch for 2560default loop and for \f(CW\*(C`SIGIO\*(C'\fR in another loop, but you cannot watch for
2555\&\f(CW\*(C`SIGINT\*(C'\fR in both the default loop and another loop at the same time. At 2561\&\f(CW\*(C`SIGINT\*(C'\fR in both the default loop and another loop at the same time. At
2556the moment, \f(CW\*(C`SIGCHLD\*(C'\fR is permanently tied to the default loop. 2562the moment, \f(CW\*(C`SIGCHLD\*(C'\fR is permanently tied to the default loop.
2557.PP 2563.PP
2558When the first watcher gets started will libev actually register something 2564Only after the first watcher for a signal is started will libev actually
2559with the kernel (thus it coexists with your own signal handlers as long as 2565register something with the kernel. It thus coexists with your own signal
2560you don't register any with libev for the same signal). 2566handlers as long as you don't register any with libev for the same signal.
2561.PP 2567.PP
2562If possible and supported, libev will install its handlers with 2568If possible and supported, libev will install its handlers with
2563\&\f(CW\*(C`SA_RESTART\*(C'\fR (or equivalent) behaviour enabled, so system calls should 2569\&\f(CW\*(C`SA_RESTART\*(C'\fR (or equivalent) behaviour enabled, so system calls should
2564not be unduly interrupted. If you have a problem with system calls getting 2570not be unduly interrupted. If you have a problem with system calls getting
2565interrupted by signals you can block all signals in an \f(CW\*(C`ev_check\*(C'\fR watcher 2571interrupted by signals you can block all signals in an \f(CW\*(C`ev_check\*(C'\fR watcher
3048.IX Subsection "ev_prepare and ev_check - customise your event loop!" 3054.IX Subsection "ev_prepare and ev_check - customise your event loop!"
3049Prepare and check watchers are often (but not always) used in pairs: 3055Prepare and check watchers are often (but not always) used in pairs:
3050prepare watchers get invoked before the process blocks and check watchers 3056prepare watchers get invoked before the process blocks and check watchers
3051afterwards. 3057afterwards.
3052.PP 3058.PP
3053You \fImust not\fR call \f(CW\*(C`ev_run\*(C'\fR or similar functions that enter 3059You \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 3060current 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 3061\&\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 3062however. 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, 3063for 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 3064\&\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. 3065kind they will always be called in pairs bracketing the blocking call.
3060.PP 3066.PP
3061Their main purpose is to integrate other event mechanisms into libev and 3067Their main purpose is to integrate other event mechanisms into libev and
3062their use is somewhat advanced. They could be used, for example, to track 3068their use is somewhat advanced. They could be used, for example, to track
3063variable changes, implement your own watchers, integrate net-snmp or a 3069variable changes, implement your own watchers, integrate net-snmp or a
3064coroutine library and lots more. They are also occasionally useful if 3070coroutine library and lots more. They are also occasionally useful if
3358.PP 3364.PP
3359.Vb 3 3365.Vb 3
3360\& struct ev_loop *loop_hi = ev_default_init (0); 3366\& struct ev_loop *loop_hi = ev_default_init (0);
3361\& struct ev_loop *loop_lo = 0; 3367\& struct ev_loop *loop_lo = 0;
3362\& ev_embed embed; 3368\& ev_embed embed;
3363\& 3369\&
3364\& // see if there is a chance of getting one that works 3370\& // see if there is a chance of getting one that works
3365\& // (remember that a flags value of 0 means autodetection) 3371\& // (remember that a flags value of 0 means autodetection)
3366\& loop_lo = ev_embeddable_backends () & ev_recommended_backends () 3372\& loop_lo = ev_embeddable_backends () & ev_recommended_backends ()
3367\& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ()) 3373\& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ())
3368\& : 0; 3374\& : 0;
3384.PP 3390.PP
3385.Vb 3 3391.Vb 3
3386\& struct ev_loop *loop = ev_default_init (0); 3392\& struct ev_loop *loop = ev_default_init (0);
3387\& struct ev_loop *loop_socket = 0; 3393\& struct ev_loop *loop_socket = 0;
3388\& ev_embed embed; 3394\& ev_embed embed;
3389\& 3395\&
3390\& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) 3396\& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE)
3391\& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE)) 3397\& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE))
3392\& { 3398\& {
3393\& ev_embed_init (&embed, 0, loop_socket); 3399\& ev_embed_init (&embed, 0, loop_socket);
3394\& ev_embed_start (loop, &embed); 3400\& ev_embed_start (loop, &embed);
3411of course. 3417of course.
3412.PP 3418.PP
3413\fIThe special problem of life after fork \- how is it possible?\fR 3419\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?" 3420.IX Subsection "The special problem of life after fork - how is it possible?"
3415.PP 3421.PP
3416Most uses of \f(CW\*(C`fork()\*(C'\fR consist of forking, then some simple calls to set 3422Most 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 3423up/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. 3424sequence should be handled by libev without any problems.
3419.PP 3425.PP
3420This changes when the application actually wants to do event handling 3426This 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 3427in the child, or both parent in child, in effect \*(L"continuing\*(R" after the
4049files, \fImy_ev.h\fR and \fImy_ev.c\fR that include the respective libev files: 4055files, \fImy_ev.h\fR and \fImy_ev.c\fR that include the respective libev files:
4050.PP 4056.PP
4051.Vb 4 4057.Vb 4
4052\& // my_ev.h 4058\& // my_ev.h
4053\& #define EV_CB_DECLARE(type) struct my_coro *cb; 4059\& #define EV_CB_DECLARE(type) struct my_coro *cb;
4054\& #define EV_CB_INVOKE(watcher) switch_to ((watcher)\->cb); 4060\& #define EV_CB_INVOKE(watcher) switch_to ((watcher)\->cb)
4055\& #include "../libev/ev.h" 4061\& #include "../libev/ev.h"
4056\& 4062\&
4057\& // my_ev.c 4063\& // my_ev.c
4058\& #define EV_H "my_ev.h" 4064\& #define EV_H "my_ev.h"
4059\& #include "../libev/ev.c" 4065\& #include "../libev/ev.c"
4245\& void operator() (ev::io &w, int revents) 4251\& void operator() (ev::io &w, int revents)
4246\& { 4252\& {
4247\& ... 4253\& ...
4248\& } 4254\& }
4249\& } 4255\& }
4250\& 4256\&
4251\& myfunctor f; 4257\& myfunctor f;
4252\& 4258\&
4253\& ev::io w; 4259\& ev::io w;
4254\& w.set (&f); 4260\& w.set (&f);
4255.Ve 4261.Ve
4515\& ev_vars.h 4521\& ev_vars.h
4516\& ev_wrap.h 4522\& ev_wrap.h
4517\& 4523\&
4518\& ev_win32.c required on win32 platforms only 4524\& ev_win32.c required on win32 platforms only
4519\& 4525\&
4520\& ev_select.c only when select backend is enabled (which is enabled by default) 4526\& ev_select.c only when select backend is enabled
4521\& ev_poll.c only when poll backend is enabled (disabled by default) 4527\& ev_poll.c only when poll backend is enabled
4522\& ev_epoll.c only when the epoll backend is enabled (disabled by default) 4528\& ev_epoll.c only when the epoll backend is enabled
4523\& ev_kqueue.c only when the kqueue backend is enabled (disabled by default) 4529\& 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) 4530\& ev_port.c only when the solaris port backend is enabled
4525.Ve 4531.Ve
4526.PP 4532.PP
4527\&\fIev.c\fR includes the backend files directly when enabled, so you only need 4533\&\fIev.c\fR includes the backend files directly when enabled, so you only need
4528to compile this single file. 4534to compile this single file.
4529.PP 4535.PP
5406Libev assumes not only that all watcher pointers have the same internal 5412Libev 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 5413structure (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 5414assumes that the same (machine) code can be used to call any watcher
5409callback: The watcher callbacks have different type signatures, but libev 5415callback: The watcher callbacks have different type signatures, but libev
5410calls them using an \f(CW\*(C`ev_watcher *\*(C'\fR internally. 5416calls them using an \f(CW\*(C`ev_watcher *\*(C'\fR internally.
5417.IP "null pointers and integer zero are represented by 0 bytes" 4
5418.IX Item "null pointers and integer zero are represented by 0 bytes"
5419Libev uses \f(CW\*(C`memset\*(C'\fR to initialise structs and arrays to \f(CW0\fR bytes, and
5420relies on this setting pointers and integers to null.
5411.IP "pointer accesses must be thread-atomic" 4 5421.IP "pointer accesses must be thread-atomic" 4
5412.IX Item "pointer accesses must be thread-atomic" 5422.IX Item "pointer accesses must be thread-atomic"
5413Accessing a pointer value must be atomic, it must both be readable and 5423Accessing a pointer value must be atomic, it must both be readable and
5414writable in one piece \- this is the case on all current architectures. 5424writable 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 5425.ie n .IP """sig_atomic_t volatile"" must be thread-atomic as well" 4

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines