X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/363b337b90b2575d2cc5253af2ffe6afa0d3eb72..4bfa2139d1477eca27d2050ca93951cc409517ac:/ev.pod diff --git a/ev.pod b/ev.pod index ab57ffb..2269dff 100644 --- a/ev.pod +++ b/ev.pod @@ -6,7 +6,7 @@ libev - a high performance full-featured event loop written in C #include -=head1 EXAMPLE PROGRAM +=head2 EXAMPLE PROGRAM #include @@ -55,7 +55,7 @@ web page you might find easier to navigate when reading it for the first time: L. Libev is an event loop: you register interest in certain events (such as a -file descriptor being readable or a timeout occuring), and it will manage +file descriptor being readable or a timeout occurring), and it will manage these event sources and provide your program with events. To do this, it must take more or less complete control over your process @@ -67,7 +67,7 @@ watchers>, which are relatively small C structures you initialise with the details of the event, and then hand it over to libev by I the watcher. -=head1 FEATURES +=head2 FEATURES Libev supports C which have a high +overhead for the actual polling but can deliver many events at once. + +By setting a higher I you allow libev to spend more +time collecting I/O events, so you can handle more events per iteration, +at the cost of increasing latency. Timeouts (both C and +C) will be not affected. Setting this to a non-null value will +introduce an additional C call into most loop iterations. + +Likewise, by setting a higher I you allow libev +to spend more time collecting timeouts, at the expense of increased +latency (the watcher callback will be called later). C watchers +will not be affected. Setting this to a non-null value will not introduce +any overhead in libev. + +Many (busy) programs can usually benefit by setting the io collect +interval to a value near C<0.1> or so, which is often enough for +interactive servers (of course not for games), likewise for timeouts. It +usually doesn't make much sense to set it to a lower value than C<0.01>, +as this approsaches the timing granularity of most systems. + =back @@ -915,7 +1012,7 @@ its own, so its quite safe to use). =head3 The special problem of disappearing file descriptors -Some backends (e.g kqueue, epoll) need to be told about closing a file +Some backends (e.g. kqueue, epoll) need to be told about closing a file descriptor (either by calling C explicitly or by any other means, such as C). The reason is that you register interest in some file descriptor, but when it goes away, the operating system will silently drop @@ -934,6 +1031,30 @@ This is how one would do it normally anyway, the important point is that the libev application should not optimise around libev but should leave optimisations to libev. +=head3 The special problem of dup'ed file descriptors + +Some backends (e.g. epoll), cannot register events for file descriptors, +but only events for the underlying file descriptions. That means when you +have C'ed file descriptors and register events for them, only one +file descriptor might actually receive events. + +There is no workaround possible except not registering events +for potentially C'ed file descriptors, or to resort to +C or C. + +=head3 The special problem of fork + +Some backends (epoll, kqueue) do not support C at all or exhibit +useless behaviour. Libev fully supports fork, but needs to be told about +it in the child. + +To support fork in your programs, you either have to call +C or C after a fork in the child, +enable C, or resort to C or +C. + + +=head3 Watcher-Specific Functions =over 4 @@ -997,6 +1118,8 @@ The callback is guarenteed to be invoked only when its timeout has passed, but if multiple timers become ready during the same loop iteration then order of execution is undefined. +=head3 Watcher-Specific Functions and Data Members + =over 4 =item ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat) @@ -1111,6 +1234,8 @@ As with timers, the callback is guarenteed to be invoked only when the time (C) has been passed, but if multiple periodic timers become ready during the same loop iteration then order of execution is undefined. +=head3 Watcher-Specific Functions and Data Members + =over 4 =item ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb) @@ -1216,6 +1341,11 @@ The current reschedule callback, or C<0>, if this functionality is switched off. Can be changed any time, but changes only take effect when the periodic timer fires or C is being called. +=item ev_tstamp at [read-only] + +When active, contains the absolute time that the watcher is supposed to +trigger next. + =back Example: Call a callback every hour, or, more precisely, whenever the @@ -1266,6 +1396,8 @@ as you don't register any with libev). Similarly, when the last signal watcher for a signal is stopped libev will reset the signal handler to SIG_DFL (regardless of what it was set to before). +=head3 Watcher-Specific Functions and Data Members + =over 4 =item ev_signal_init (ev_signal *, callback, int signum) @@ -1287,6 +1419,8 @@ The signal the watcher watches out for. Child watchers trigger when your process receives a SIGCHLD in response to some child status changes (most typically when a child of yours dies). +=head3 Watcher-Specific Functions and Data Members + =over 4 =item ev_child_init (ev_child *, callback, int pid) @@ -1364,6 +1498,8 @@ to fall back to regular polling again even with inotify, but changes are usually detected immediately, and if the file exists there will be no polling. +=head3 Watcher-Specific Functions and Data Members + =over 4 =item ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval) @@ -1455,6 +1591,8 @@ effect on its own sometimes), idle watchers are a good place to do "pseudo-background processing", or delay processing stuff to after the event loop has handled all outstanding events. +=head3 Watcher-Specific Functions and Data Members + =over 4 =item ev_idle_init (ev_signal *, callback) @@ -1525,11 +1663,13 @@ It is recommended to give C watchers highest (C) priority, to ensure that they are being run before any other watchers after the poll. Also, C watchers (and C watchers, too) should not activate ("feed") events into libev. While libev fully -supports this, they will be called before other C watchers did -their job. As C watchers are often used to embed other event -loops those other event loops might be in an unusable state until their -C watcher ran (always remind yourself to coexist peacefully with -others). +supports this, they will be called before other C watchers +did their job. As C watchers are often used to embed other +(non-libev) event loops those other event loops might be in an unusable +state until their C watcher ran (always remind yourself to +coexist peacefully with others). + +=head3 Watcher-Specific Functions and Data Members =over 4 @@ -1741,6 +1881,8 @@ create it, and if that fails, use the normal loop for everything: else loop_lo = loop_hi; +=head3 Watcher-Specific Functions and Data Members + =over 4 =item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop) @@ -1759,7 +1901,7 @@ Make a single, non-blocking sweep over the embedded loop. This works similarly to C, but in the most apropriate way for embedded loops. -=item struct ev_loop *loop [read-only] +=item struct ev_loop *other [read-only] The embedded event loop. @@ -1776,6 +1918,8 @@ and only in the child after the fork. If whoever good citizen calling C cheats and calls it in the wrong process, the fork handlers will be invoked, too, of course. +=head3 Watcher-Specific Functions and Data Members + =over 4 =item ev_fork_init (ev_signal *, callback) @@ -2001,16 +2145,16 @@ constructor already stores the event loop. Stops the watcher if it is active. Again, no C argument. -=item w->again () C, C only +=item w->again () (C, C only) For C and C, this invokes the corresponding C function. -=item w->sweep () C only +=item w->sweep () (C only) Invokes C. -=item w->update () C only +=item w->update () (C only) Invokes C. @@ -2040,9 +2184,9 @@ the constructor. =head1 MACRO MAGIC -Libev can be compiled with a variety of options, the most fundemantal is -C. This option determines whether (most) functions and -callbacks have an initial C argument. +Libev can be compiled with a variety of options, the most fundamantal +of which is C. This option determines whether (most) +functions and callbacks have an initial C argument. To make it easier to write programs that cope with either variant, the following macros are defined: @@ -2106,7 +2250,7 @@ applications. Examples of applications that embed it include the Deliantra Game Server, the EV perl module, the GNU Virtual Private Ethernet (gvpe) and rxvt-unicode. -The goal is to enable you to just copy the neecssary files into your +The goal is to enable you to just copy the necessary files into your source directory without having to change even a single line in them, so you can easily upgrade by simply copying (or having a checked-out copy of libev somewhere in your source tree). @@ -2206,7 +2350,7 @@ If defined to be C<1>, libev will try to detect the availability of the monotonic clock option at both compiletime and runtime. Otherwise no use of the monotonic clock option will be attempted. If you enable this, you usually have to link against librt or something similar. Enabling it when -the functionality isn't available is safe, though, althoguh you have +the functionality isn't available is safe, though, although you have to make sure you link against any libraries where the C function is hiding in (often F<-lrt>). @@ -2216,8 +2360,13 @@ If defined to be C<1>, libev will try to detect the availability of the realtime clock option at compiletime (and assume its availability at runtime if successful). Otherwise no use of the realtime clock option will be attempted. This effectively replaces C by C and will not normally affect correctness. See tzhe note about libraries -in the description of C, though. +(CLOCK_REALTIME, ...)> and will not normally affect correctness. See the +note about libraries in the description of C, though. + +=item EV_USE_NANOSLEEP + +If defined to be C<1>, libev will assume that C is available +and will use it for delays. Otherwise it will use C