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

Comparing libev/ev.3 (file contents):
Revision 1.1 by root, Tue Nov 13 03:11:57 2007 UTC vs.
Revision 1.4 by root, Thu Nov 22 12:28:35 2007 UTC

127.\} 127.\}
128.rm #[ #] #H #V #F C 128.rm #[ #] #H #V #F C
129.\" ======================================================================== 129.\" ========================================================================
130.\" 130.\"
131.IX Title ""<STANDARD INPUT>" 1" 131.IX Title ""<STANDARD INPUT>" 1"
132.TH "<STANDARD INPUT>" 1 "2007-11-13" "perl v5.8.8" "User Contributed Perl Documentation" 132.TH "<STANDARD INPUT>" 1 "2007-11-22" "perl v5.8.8" "User Contributed Perl Documentation"
133.SH "NAME" 133.SH "NAME"
134libev \- a high performance full\-featured event loop written in C 134libev \- a high performance full\-featured event loop written in C
135.SH "SYNOPSIS" 135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS" 136.IX Header "SYNOPSIS"
137.Vb 1 137.Vb 1
180.IX Header "GLOBAL FUNCTIONS" 180.IX Header "GLOBAL FUNCTIONS"
181These functions can be called anytime, even before initialising the 181These functions can be called anytime, even before initialising the
182library in any way. 182library in any way.
183.IP "ev_tstamp ev_time ()" 4 183.IP "ev_tstamp ev_time ()" 4
184.IX Item "ev_tstamp ev_time ()" 184.IX Item "ev_tstamp ev_time ()"
185Returns the current time as libev would use it. 185Returns the current time as libev would use it. Please note that the
186\&\f(CW\*(C`ev_now\*(C'\fR function is usually faster and also often returns the timestamp
187you actually want to know.
186.IP "int ev_version_major ()" 4 188.IP "int ev_version_major ()" 4
187.IX Item "int ev_version_major ()" 189.IX Item "int ev_version_major ()"
188.PD 0 190.PD 0
189.IP "int ev_version_minor ()" 4 191.IP "int ev_version_minor ()" 4
190.IX Item "int ev_version_minor ()" 192.IX Item "int ev_version_minor ()"
258or setgid) then libev will \fInot\fR look at the environment variable 260or setgid) then libev will \fInot\fR look at the environment variable
259\&\f(CW\*(C`LIBEV_FLAGS\*(C'\fR. Otherwise (the default), this environment variable will 261\&\f(CW\*(C`LIBEV_FLAGS\*(C'\fR. Otherwise (the default), this environment variable will
260override the flags completely if it is found in the environment. This is 262override the flags completely if it is found in the environment. This is
261useful to try out specific backends to test their performance, or to work 263useful to try out specific backends to test their performance, or to work
262around bugs. 264around bugs.
263.ie n .IP """EVMETHOD_SELECT"" (portable select backend)" 4 265.ie n .IP """EVMETHOD_SELECT"" (value 1, portable select backend)" 4
264.el .IP "\f(CWEVMETHOD_SELECT\fR (portable select backend)" 4 266.el .IP "\f(CWEVMETHOD_SELECT\fR (value 1, portable select backend)" 4
265.IX Item "EVMETHOD_SELECT (portable select backend)" 267.IX Item "EVMETHOD_SELECT (value 1, portable select backend)"
266.PD 0 268This is your standard \fIselect\fR\|(2) backend. Not \fIcompletely\fR standard, as
269libev tries to roll its own fd_set with no limits on the number of fds,
270but if that fails, expect a fairly low limit on the number of fds when
271using this backend. It doesn't scale too well (O(highest_fd)), but its usually
272the fastest backend for a low number of fds.
267.ie n .IP """EVMETHOD_POLL"" (poll backend, available everywhere except on windows)" 4 273.ie n .IP """EVMETHOD_POLL"" (value 2, poll backend, available everywhere except on windows)" 4
268.el .IP "\f(CWEVMETHOD_POLL\fR (poll backend, available everywhere except on windows)" 4 274.el .IP "\f(CWEVMETHOD_POLL\fR (value 2, poll backend, available everywhere except on windows)" 4
269.IX Item "EVMETHOD_POLL (poll backend, available everywhere except on windows)" 275.IX Item "EVMETHOD_POLL (value 2, poll backend, available everywhere except on windows)"
276And this is your standard \fIpoll\fR\|(2) backend. It's more complicated than
277select, but handles sparse fds better and has no artificial limit on the
278number of fds you can use (except it will slow down considerably with a
279lot of inactive fds). It scales similarly to select, i.e. O(total_fds).
270.ie n .IP """EVMETHOD_EPOLL"" (linux only)" 4 280.ie n .IP """EVMETHOD_EPOLL"" (value 4, Linux)" 4
271.el .IP "\f(CWEVMETHOD_EPOLL\fR (linux only)" 4 281.el .IP "\f(CWEVMETHOD_EPOLL\fR (value 4, Linux)" 4
272.IX Item "EVMETHOD_EPOLL (linux only)" 282.IX Item "EVMETHOD_EPOLL (value 4, Linux)"
273.ie n .IP """EVMETHOD_KQUEUE"" (some bsds only)" 4 283For few fds, this backend is a bit little slower than poll and select,
274.el .IP "\f(CWEVMETHOD_KQUEUE\fR (some bsds only)" 4 284but it scales phenomenally better. While poll and select usually scale like
275.IX Item "EVMETHOD_KQUEUE (some bsds only)" 285O(total_fds) where n is the total number of fds (or the highest fd), epoll scales
286either O(1) or O(active_fds).
287.Sp
288While stopping and starting an I/O watcher in the same iteration will
289result in some caching, there is still a syscall per such incident
290(because the fd could point to a different file description now), so its
291best to avoid that. Also, \fIdup()\fRed file descriptors might not work very
292well if you register events for both fds.
293.ie n .IP """EVMETHOD_KQUEUE"" (value 8, most \s-1BSD\s0 clones)" 4
294.el .IP "\f(CWEVMETHOD_KQUEUE\fR (value 8, most \s-1BSD\s0 clones)" 4
295.IX Item "EVMETHOD_KQUEUE (value 8, most BSD clones)"
296Kqueue deserves special mention, as at the time of this writing, it
297was broken on all BSDs except NetBSD (usually it doesn't work with
298anything but sockets and pipes, except on Darwin, where of course its
299completely useless). For this reason its not being \*(L"autodetected\*(R" unless
300you explicitly specify the flags (i.e. you don't use \s-1EVFLAG_AUTO\s0).
301.Sp
302It scales in the same way as the epoll backend, but the interface to the
303kernel is more efficient (which says nothing about its actual speed, of
304course). While starting and stopping an I/O watcher does not cause an
305extra syscall as with epoll, it still adds up to four event changes per
306incident, so its best to avoid that.
276.ie n .IP """EVMETHOD_DEVPOLL"" (solaris 8 only)" 4 307.ie n .IP """EVMETHOD_DEVPOLL"" (value 16, Solaris 8)" 4
277.el .IP "\f(CWEVMETHOD_DEVPOLL\fR (solaris 8 only)" 4 308.el .IP "\f(CWEVMETHOD_DEVPOLL\fR (value 16, Solaris 8)" 4
278.IX Item "EVMETHOD_DEVPOLL (solaris 8 only)" 309.IX Item "EVMETHOD_DEVPOLL (value 16, Solaris 8)"
310This is not implemented yet (and might never be).
279.ie n .IP """EVMETHOD_PORT"" (solaris 10 only)" 4 311.ie n .IP """EVMETHOD_PORT"" (value 32, Solaris 10)" 4
280.el .IP "\f(CWEVMETHOD_PORT\fR (solaris 10 only)" 4 312.el .IP "\f(CWEVMETHOD_PORT\fR (value 32, Solaris 10)" 4
281.IX Item "EVMETHOD_PORT (solaris 10 only)" 313.IX Item "EVMETHOD_PORT (value 32, Solaris 10)"
282.PD 314This uses the Solaris 10 port mechanism. As with everything on Solaris,
283If one or more of these are ored into the flags value, then only these 315it's really slow, but it still scales very well (O(active_fds)).
284backends will be tried (in the reverse order as given here). If one are 316.ie n .IP """EVMETHOD_ALL""" 4
285specified, any backend will do. 317.el .IP "\f(CWEVMETHOD_ALL\fR" 4
318.IX Item "EVMETHOD_ALL"
319Try all backends (even potentially broken ones that wouldn't be tried
320with \f(CW\*(C`EVFLAG_AUTO\*(C'\fR). Since this is a mask, you can do stuff such as
321\&\f(CW\*(C`EVMETHOD_ALL & ~EVMETHOD_KQUEUE\*(C'\fR.
286.RE 322.RE
287.RS 4 323.RS 4
324.Sp
325If one or more of these are ored into the flags value, then only these
326backends will be tried (in the reverse order as given here). If none are
327specified, most compiled-in backend will be tried, usually in reverse
328order of their flag values :)
288.RE 329.RE
289.IP "struct ev_loop *ev_loop_new (unsigned int flags)" 4 330.IP "struct ev_loop *ev_loop_new (unsigned int flags)" 4
290.IX Item "struct ev_loop *ev_loop_new (unsigned int flags)" 331.IX Item "struct ev_loop *ev_loop_new (unsigned int flags)"
291Similar to \f(CW\*(C`ev_default_loop\*(C'\fR, but always creates a new event loop that is 332Similar to \f(CW\*(C`ev_default_loop\*(C'\fR, but always creates a new event loop that is
292always distinct from the default loop. Unlike the default loop, it cannot 333always distinct from the default loop. Unlike the default loop, it cannot
354one iteration of the loop. 395one iteration of the loop.
355.Sp 396.Sp
356This flags value could be used to implement alternative looping 397This flags value could be used to implement alternative looping
357constructs, but the \f(CW\*(C`prepare\*(C'\fR and \f(CW\*(C`check\*(C'\fR watchers provide a better and 398constructs, but the \f(CW\*(C`prepare\*(C'\fR and \f(CW\*(C`check\*(C'\fR watchers provide a better and
358more generic mechanism. 399more generic mechanism.
400.Sp
401Here are the gory details of what ev_loop does:
402.Sp
403.Vb 15
404\& 1. If there are no active watchers (reference count is zero), return.
405\& 2. Queue and immediately call all prepare watchers.
406\& 3. If we have been forked, recreate the kernel state.
407\& 4. Update the kernel state with all outstanding changes.
408\& 5. Update the "event loop time".
409\& 6. Calculate for how long to block.
410\& 7. Block the process, waiting for events.
411\& 8. Update the "event loop time" and do time jump handling.
412\& 9. Queue all outstanding timers.
413\& 10. Queue all outstanding periodics.
414\& 11. If no events are pending now, queue all idle watchers.
415\& 12. Queue all check watchers.
416\& 13. Call all queued watchers in reverse order (i.e. check watchers first).
417\& 14. If ev_unloop has been called or EVLOOP_ONESHOT or EVLOOP_NONBLOCK
418\& was used, return, otherwise continue with step #1.
419.Ve
359.IP "ev_unloop (loop, how)" 4 420.IP "ev_unloop (loop, how)" 4
360.IX Item "ev_unloop (loop, how)" 421.IX Item "ev_unloop (loop, how)"
361Can be used to make a call to \f(CW\*(C`ev_loop\*(C'\fR return early (but only after it 422Can be used to make a call to \f(CW\*(C`ev_loop\*(C'\fR return early (but only after it
362has processed all outstanding events). The \f(CW\*(C`how\*(C'\fR argument must be either 423has processed all outstanding events). The \f(CW\*(C`how\*(C'\fR argument must be either
363\&\f(CW\*(C`EVUNLOOP_ONE\*(C'\fR, which will make the innermost \f(CW\*(C`ev_loop\*(C'\fR call return, or 424\&\f(CW\*(C`EVUNLOOP_ONE\*(C'\fR, which will make the innermost \f(CW\*(C`ev_loop\*(C'\fR call return, or
571given time, and optionally repeating in regular intervals after that. 632given time, and optionally repeating in regular intervals after that.
572.PP 633.PP
573The timers are based on real time, that is, if you register an event that 634The timers are based on real time, that is, if you register an event that
574times out after an hour and you reset your system clock to last years 635times out after an hour and you reset your system clock to last years
575time, it will still time out after (roughly) and hour. \*(L"Roughly\*(R" because 636time, it will still time out after (roughly) and hour. \*(L"Roughly\*(R" because
576detecting time jumps is hard, and soem inaccuracies are unavoidable (the 637detecting time jumps is hard, and some inaccuracies are unavoidable (the
577monotonic clock option helps a lot here). 638monotonic clock option helps a lot here).
578.PP 639.PP
579The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR 640The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR
580time. This is usually the right thing as this timestamp refers to the time 641time. This is usually the right thing as this timestamp refers to the time
581of the event triggering whatever timeout you are modifying/starting. If 642of the event triggering whatever timeout you are modifying/starting. If
582you suspect event processing to be delayed and you *need* to base the timeout 643you suspect event processing to be delayed and you \fIneed\fR to base the timeout
583on the current time, use something like this to adjust for this: 644on the current time, use something like this to adjust for this:
584.PP 645.PP
585.Vb 1 646.Vb 1
586\& ev_timer_set (&timer, after + ev_now () - ev_time (), 0.); 647\& ev_timer_set (&timer, after + ev_now () - ev_time (), 0.);
587.Ve 648.Ve
649.PP
650The callback is guarenteed to be invoked only when its timeout has passed,
651but if multiple timers become ready during the same loop iteration then
652order of execution is undefined.
588.IP "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" 4 653.IP "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" 4
589.IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" 654.IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)"
590.PD 0 655.PD 0
591.IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4 656.IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4
592.IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 657.IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)"
634roughly 10 seconds later and of course not if you reset your system time 699roughly 10 seconds later and of course not if you reset your system time
635again). 700again).
636.PP 701.PP
637They can also be used to implement vastly more complex timers, such as 702They can also be used to implement vastly more complex timers, such as
638triggering an event on eahc midnight, local time. 703triggering an event on eahc midnight, local time.
704.PP
705As with timers, the callback is guarenteed to be invoked only when the
706time (\f(CW\*(C`at\*(C'\fR) has been passed, but if multiple periodic timers become ready
707during the same loop iteration then order of execution is undefined.
639.IP "ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb)" 4 708.IP "ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb)" 4
640.IX Item "ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb)" 709.IX Item "ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb)"
641.PD 0 710.PD 0
642.IP "ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb)" 4 711.IP "ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb)" 4
643.IX Item "ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb)" 712.IX Item "ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb)"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines