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

Comparing libev/ev.3 (file contents):
Revision 1.74 by root, Wed Nov 19 10:33:32 2008 UTC vs.
Revision 1.75 by root, Wed Dec 24 22:05:18 2008 UTC

130.\} 130.\}
131.rm #[ #] #H #V #F C 131.rm #[ #] #H #V #F C
132.\" ======================================================================== 132.\" ========================================================================
133.\" 133.\"
134.IX Title "LIBEV 3" 134.IX Title "LIBEV 3"
135.TH LIBEV 3 "2008-11-17" "libev-3.49" "libev - high performance full featured event loop" 135.TH LIBEV 3 "2008-12-14" "libev-3.51" "libev - high performance full featured event loop"
136.\" For nroff, turn off justification. Always turn off hyphenation; it makes 136.\" For nroff, turn off justification. Always turn off hyphenation; it makes
137.\" way too many mistakes in technical documents. 137.\" way too many mistakes in technical documents.
138.if n .ad l 138.if n .ad l
139.nh 139.nh
140.SH "NAME" 140.SH "NAME"
182\& 182\&
183\& int 183\& int
184\& main (void) 184\& main (void)
185\& { 185\& {
186\& // use the default event loop unless you have special needs 186\& // use the default event loop unless you have special needs
187\& ev_loop *loop = ev_default_loop (0); 187\& struct ev_loop *loop = ev_default_loop (0);
188\& 188\&
189\& // initialise an io watcher, then start it 189\& // initialise an io watcher, then start it
190\& // this one will watch for stdin to become readable 190\& // this one will watch for stdin to become readable
191\& ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ); 191\& ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
192\& ev_io_start (loop, &stdin_watcher); 192\& ev_io_start (loop, &stdin_watcher);
586.Sp 586.Sp
587While nominally embeddable in other event loops, this doesn't work 587While nominally embeddable in other event loops, this doesn't work
588everywhere, so you might need to test for this. And since it is broken 588everywhere, so you might need to test for this. And since it is broken
589almost everywhere, you should only use it when you have a lot of sockets 589almost everywhere, you should only use it when you have a lot of sockets
590(for which it usually works), by embedding it into another event loop 590(for which it usually works), by embedding it into another event loop
591(e.g. \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR) and, did I mention it, 591(e.g. \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR (but \f(CW\*(C`poll\*(C'\fR is of course
592using it only for sockets. 592also broken on \s-1OS\s0 X)) and, did I mention it, using it only for sockets.
593.Sp 593.Sp
594This backend maps \f(CW\*(C`EV_READ\*(C'\fR into an \f(CW\*(C`EVFILT_READ\*(C'\fR kevent with 594This backend maps \f(CW\*(C`EV_READ\*(C'\fR into an \f(CW\*(C`EVFILT_READ\*(C'\fR kevent with
595\&\f(CW\*(C`NOTE_EOF\*(C'\fR, and \f(CW\*(C`EV_WRITE\*(C'\fR into an \f(CW\*(C`EVFILT_WRITE\*(C'\fR kevent with 595\&\f(CW\*(C`NOTE_EOF\*(C'\fR, and \f(CW\*(C`EV_WRITE\*(C'\fR into an \f(CW\*(C`EVFILT_WRITE\*(C'\fR kevent with
596\&\f(CW\*(C`NOTE_EOF\*(C'\fR. 596\&\f(CW\*(C`NOTE_EOF\*(C'\fR.
597.ie n .IP """EVBACKEND_DEVPOLL"" (value 16, Solaris 8)" 4 597.ie n .IP """EVBACKEND_DEVPOLL"" (value 16, Solaris 8)" 4
2164the process. The exception are \f(CW\*(C`ev_stat\*(C'\fR watchers \- those call \f(CW\*(C`stat 2164the process. The exception are \f(CW\*(C`ev_stat\*(C'\fR watchers \- those call \f(CW\*(C`stat
2165()\*(C'\fR, which is a synchronous operation. 2165()\*(C'\fR, which is a synchronous operation.
2166.PP 2166.PP
2167For local paths, this usually doesn't matter: unless the system is very 2167For local paths, this usually doesn't matter: unless the system is very
2168busy or the intervals between stat's are large, a stat call will be fast, 2168busy or the intervals between stat's are large, a stat call will be fast,
2169as the path data is suually in memory already (except when starting the 2169as the path data is usually in memory already (except when starting the
2170watcher). 2170watcher).
2171.PP 2171.PP
2172For networked file systems, calling \f(CW\*(C`stat ()\*(C'\fR can block an indefinite 2172For networked file systems, calling \f(CW\*(C`stat ()\*(C'\fR can block an indefinite
2173time due to network issues, and even under good conditions, a stat call 2173time due to network issues, and even under good conditions, a stat call
2174often takes multiple milliseconds. 2174often takes multiple milliseconds.
2580some fds have to be watched and handled very quickly (with low latency), 2580some fds have to be watched and handled very quickly (with low latency),
2581and even priorities and idle watchers might have too much overhead. In 2581and even priorities and idle watchers might have too much overhead. In
2582this case you would put all the high priority stuff in one loop and all 2582this case you would put all the high priority stuff in one loop and all
2583the rest in a second one, and embed the second one in the first. 2583the rest in a second one, and embed the second one in the first.
2584.PP 2584.PP
2585As long as the watcher is active, the callback will be invoked every time 2585As long as the watcher is active, the callback will be invoked every
2586there might be events pending in the embedded loop. The callback must then 2586time there might be events pending in the embedded loop. The callback
2587call \f(CW\*(C`ev_embed_sweep (mainloop, watcher)\*(C'\fR to make a single sweep and invoke 2587must then call \f(CW\*(C`ev_embed_sweep (mainloop, watcher)\*(C'\fR to make a single
2588their callbacks (you could also start an idle watcher to give the embedded 2588sweep and invoke their callbacks (the callback doesn't need to invoke the
2589loop strictly lower priority for example). You can also set the callback 2589\&\f(CW\*(C`ev_embed_sweep\*(C'\fR function directly, it could also start an idle watcher
2590to \f(CW0\fR, in which case the embed watcher will automatically execute the 2590to give the embedded loop strictly lower priority for example).
2591embedded loop sweep.
2592.PP 2591.PP
2593As long as the watcher is started it will automatically handle events. The 2592You can also set the callback to \f(CW0\fR, in which case the embed watcher
2594callback will be invoked whenever some events have been handled. You can 2593will automatically execute the embedded loop sweep whenever necessary.
2595set the callback to \f(CW0\fR to avoid having to specify one if you are not
2596interested in that.
2597.PP 2594.PP
2598Also, there have not currently been made special provisions for forking: 2595Fork detection will be handled transparently while the \f(CW\*(C`ev_embed\*(C'\fR watcher
2599when you fork, you not only have to call \f(CW\*(C`ev_loop_fork\*(C'\fR on both loops, 2596is active, i.e., the embedded loop will automatically be forked when the
2600but you will also have to stop and restart any \f(CW\*(C`ev_embed\*(C'\fR watchers 2597embedding loop forks. In other cases, the user is responsible for calling
2601yourself \- but you can use a fork watcher to handle this automatically, 2598\&\f(CW\*(C`ev_loop_fork\*(C'\fR on the embedded loop.
2602and future versions of libev might do just that.
2603.PP 2599.PP
2604Unfortunately, not all backends are embeddable: only the ones returned by 2600Unfortunately, not all backends are embeddable: only the ones returned by
2605\&\f(CW\*(C`ev_embeddable_backends\*(C'\fR are, which, unfortunately, does not include any 2601\&\f(CW\*(C`ev_embeddable_backends\*(C'\fR are, which, unfortunately, does not include any
2606portable one. 2602portable one.
2607.PP 2603.PP
3016\& 3012\&
3017\& myclass obj; 3013\& myclass obj;
3018\& ev::io iow; 3014\& ev::io iow;
3019\& iow.set <myclass, &myclass::io_cb> (&obj); 3015\& iow.set <myclass, &myclass::io_cb> (&obj);
3020.Ve 3016.Ve
3017.IP "w\->set (object *)" 4
3018.IX Item "w->set (object *)"
3019This is an \fBexperimental\fR feature that might go away in a future version.
3020.Sp
3021This is a variation of a method callback \- leaving out the method to call
3022will default the method to \f(CW\*(C`operator ()\*(C'\fR, which makes it possible to use
3023functor objects without having to manually specify the \f(CW\*(C`operator ()\*(C'\fR all
3024the time. Incidentally, you can then also leave out the template argument
3025list.
3026.Sp
3027The \f(CW\*(C`operator ()\*(C'\fR method prototype must be \f(CW\*(C`void operator ()(watcher &w,
3028int revents)\*(C'\fR.
3029.Sp
3030See the method\-\f(CW\*(C`set\*(C'\fR above for more details.
3031.Sp
3032Example: use a functor object as callback.
3033.Sp
3034.Vb 7
3035\& struct myfunctor
3036\& {
3037\& void operator() (ev::io &w, int revents)
3038\& {
3039\& ...
3040\& }
3041\& }
3042\&
3043\& myfunctor f;
3044\&
3045\& ev::io w;
3046\& w.set (&f);
3047.Ve
3021.IP "w\->set<function> (void *data = 0)" 4 3048.IP "w\->set<function> (void *data = 0)" 4
3022.IX Item "w->set<function> (void *data = 0)" 3049.IX Item "w->set<function> (void *data = 0)"
3023Also sets a callback, but uses a static method or plain function as 3050Also sets a callback, but uses a static method or plain function as
3024callback. The optional \f(CW\*(C`data\*(C'\fR argument will be stored in the watcher's 3051callback. The optional \f(CW\*(C`data\*(C'\fR argument will be stored in the watcher's
3025\&\f(CW\*(C`data\*(C'\fR member and is free for you to use. 3052\&\f(CW\*(C`data\*(C'\fR member and is free for you to use.
3115.IX Item "Ruby" 3142.IX Item "Ruby"
3116Tony Arcieri has written a ruby extension that offers access to a subset 3143Tony Arcieri has written a ruby extension that offers access to a subset
3117of the libev \s-1API\s0 and adds file handle abstractions, asynchronous \s-1DNS\s0 and 3144of the libev \s-1API\s0 and adds file handle abstractions, asynchronous \s-1DNS\s0 and
3118more on top of it. It can be found via gem servers. Its homepage is at 3145more on top of it. It can be found via gem servers. Its homepage is at
3119<http://rev.rubyforge.org/>. 3146<http://rev.rubyforge.org/>.
3147.Sp
3148Roger Pack reports that using the link order \f(CW\*(C`\-lws2_32 \-lmsvcrt\-ruby\-190\*(C'\fR
3149makes rev work even on mingw.
3120.IP "D" 4 3150.IP "D" 4
3121.IX Item "D" 3151.IX Item "D"
3122Leandro Lucarella has written a D language binding (\fIev.d\fR) for libev, to 3152Leandro Lucarella has written a D language binding (\fIev.d\fR) for libev, to
3123be found at <http://proj.llucax.com.ar/wiki/evd>. 3153be found at <http://proj.llucax.com.ar/wiki/evd>.
3124.IP "Ocaml" 4 3154.IP "Ocaml" 4
3307Must always be \f(CW1\fR if you do not use autoconf configuration, which 3337Must always be \f(CW1\fR if you do not use autoconf configuration, which
3308keeps libev from including \fIconfig.h\fR, and it also defines dummy 3338keeps libev from including \fIconfig.h\fR, and it also defines dummy
3309implementations for some libevent functions (such as logging, which is not 3339implementations for some libevent functions (such as logging, which is not
3310supported). It will also not define any of the structs usually found in 3340supported). It will also not define any of the structs usually found in
3311\&\fIevent.h\fR that are not directly supported by the libev core alone. 3341\&\fIevent.h\fR that are not directly supported by the libev core alone.
3342.Sp
3343In stanbdalone mode, libev will still try to automatically deduce the
3344configuration, but has to be more conservative.
3312.IP "\s-1EV_USE_MONOTONIC\s0" 4 3345.IP "\s-1EV_USE_MONOTONIC\s0" 4
3313.IX Item "EV_USE_MONOTONIC" 3346.IX Item "EV_USE_MONOTONIC"
3314If defined to be \f(CW1\fR, libev will try to detect the availability of the 3347If defined to be \f(CW1\fR, libev will try to detect the availability of the
3315monotonic clock option at both compile time and runtime. Otherwise no use 3348monotonic clock option at both compile time and runtime. Otherwise no
3316of the monotonic clock option will be attempted. If you enable this, you 3349use of the monotonic clock option will be attempted. If you enable this,
3317usually have to link against librt or something similar. Enabling it when 3350you usually have to link against librt or something similar. Enabling it
3318the functionality isn't available is safe, though, although you have 3351when the functionality isn't available is safe, though, although you have
3319to make sure you link against any libraries where the \f(CW\*(C`clock_gettime\*(C'\fR 3352to make sure you link against any libraries where the \f(CW\*(C`clock_gettime\*(C'\fR
3320function is hiding in (often \fI\-lrt\fR). 3353function is hiding in (often \fI\-lrt\fR). See also \f(CW\*(C`EV_USE_CLOCK_SYSCALL\*(C'\fR.
3321.IP "\s-1EV_USE_REALTIME\s0" 4 3354.IP "\s-1EV_USE_REALTIME\s0" 4
3322.IX Item "EV_USE_REALTIME" 3355.IX Item "EV_USE_REALTIME"
3323If defined to be \f(CW1\fR, libev will try to detect the availability of the 3356If defined to be \f(CW1\fR, libev will try to detect the availability of the
3324real-time clock option at compile time (and assume its availability at 3357real-time clock option at compile time (and assume its availability at
3325runtime if successful). Otherwise no use of the real-time clock option will 3358runtime if successful). Otherwise no use of the real-time clock option will
3326be attempted. This effectively replaces \f(CW\*(C`gettimeofday\*(C'\fR by \f(CW\*(C`clock_get 3359be attempted. This effectively replaces \f(CW\*(C`gettimeofday\*(C'\fR by \f(CW\*(C`clock_get
3327(CLOCK_REALTIME, ...)\*(C'\fR and will not normally affect correctness. See the 3360(CLOCK_REALTIME, ...)\*(C'\fR and will not normally affect correctness. See the
3328note about libraries in the description of \f(CW\*(C`EV_USE_MONOTONIC\*(C'\fR, though. 3361note about libraries in the description of \f(CW\*(C`EV_USE_MONOTONIC\*(C'\fR, though.
3362.IP "\s-1EV_USE_CLOCK_SYSCALL\s0" 4
3363.IX Item "EV_USE_CLOCK_SYSCALL"
3364If defined to be \f(CW1\fR, libev will try to use a direct syscall instead
3365of calling the system-provided \f(CW\*(C`clock_gettime\*(C'\fR function. This option
3366exists because on GNU/Linux, \f(CW\*(C`clock_gettime\*(C'\fR is in \f(CW\*(C`librt\*(C'\fR, but \f(CW\*(C`librt\*(C'\fR
3367unconditionally pulls in \f(CW\*(C`libpthread\*(C'\fR, slowing down single-threaded
3368programs needlessly. Using a direct syscall is slightly slower (in
3369theory), because no optimised vdso implementation can be used, but avoids
3370the pthread dependency. Defaults to \f(CW1\fR on GNU/Linux with glibc 2.x or
3371higher, as it simplifies linking (no need for \f(CW\*(C`\-lrt\*(C'\fR).
3329.IP "\s-1EV_USE_NANOSLEEP\s0" 4 3372.IP "\s-1EV_USE_NANOSLEEP\s0" 4
3330.IX Item "EV_USE_NANOSLEEP" 3373.IX Item "EV_USE_NANOSLEEP"
3331If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available 3374If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available
3332and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR. 3375and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR.
3333.IP "\s-1EV_USE_EVENTFD\s0" 4 3376.IP "\s-1EV_USE_EVENTFD\s0" 4
3345will not be compiled in. 3388will not be compiled in.
3346.IP "\s-1EV_SELECT_USE_FD_SET\s0" 4 3389.IP "\s-1EV_SELECT_USE_FD_SET\s0" 4
3347.IX Item "EV_SELECT_USE_FD_SET" 3390.IX Item "EV_SELECT_USE_FD_SET"
3348If defined to \f(CW1\fR, then the select backend will use the system \f(CW\*(C`fd_set\*(C'\fR 3391If defined to \f(CW1\fR, then the select backend will use the system \f(CW\*(C`fd_set\*(C'\fR
3349structure. This is useful if libev doesn't compile due to a missing 3392structure. This is useful if libev doesn't compile due to a missing
3350\&\f(CW\*(C`NFDBITS\*(C'\fR or \f(CW\*(C`fd_mask\*(C'\fR definition or it mis-guesses the bitset layout on 3393\&\f(CW\*(C`NFDBITS\*(C'\fR or \f(CW\*(C`fd_mask\*(C'\fR definition or it mis-guesses the bitset layout
3351exotic systems. This usually limits the range of file descriptors to some 3394on exotic systems. This usually limits the range of file descriptors to
3352low limit such as 1024 or might have other limitations (winsocket only 3395some low limit such as 1024 or might have other limitations (winsocket
3353allows 64 sockets). The \f(CW\*(C`FD_SETSIZE\*(C'\fR macro, set before compilation, might 3396only allows 64 sockets). The \f(CW\*(C`FD_SETSIZE\*(C'\fR macro, set before compilation,
3354influence the size of the \f(CW\*(C`fd_set\*(C'\fR used. 3397configures the maximum size of the \f(CW\*(C`fd_set\*(C'\fR.
3355.IP "\s-1EV_SELECT_IS_WINSOCKET\s0" 4 3398.IP "\s-1EV_SELECT_IS_WINSOCKET\s0" 4
3356.IX Item "EV_SELECT_IS_WINSOCKET" 3399.IX Item "EV_SELECT_IS_WINSOCKET"
3357When defined to \f(CW1\fR, the select backend will assume that 3400When defined to \f(CW1\fR, the select backend will assume that
3358select/socket/connect etc. don't understand file descriptors but 3401select/socket/connect etc. don't understand file descriptors but
3359wants osf handles on win32 (this is the case when the select to 3402wants osf handles on win32 (this is the case when the select to

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines