Browse Source

*** empty log message ***

master
Marc Alexander Lehmann 14 years ago
parent
commit
82563c5fdd
  1. 214
      ev.pod

214
ev.pod

@ -115,7 +115,7 @@ Libev represents time as a single floating point number, representing the
the beginning of 1970, details are complicated, don't ask). This type is
called C<ev_tstamp>, which is what you should use too. It usually aliases
to the C<double> type in C, and when you need to do any calculations on
it, you should treat it as some floatingpoint value. Unlike the name
it, you should treat it as some floating point value. Unlike the name
component C<stamp> might indicate, it is also used for time differences
throughout libev.
@ -125,7 +125,7 @@ Libev knows three classes of errors: operating system errors, usage errors
and internal errors (bugs).
When libev catches an operating system error it cannot handle (for example
a syscall indicating a condition libev cannot fix), it calls the callback
a system call indicating a condition libev cannot fix), it calls the callback
set via C<ev_set_syserr_cb>, which is supposed to fix the problem or
abort. The default is to print a diagnostic message and to call C<abort
()>.
@ -157,7 +157,7 @@ you actually want to know.
Sleep for the given interval: The current thread will be blocked until
either it is interrupted or the given time interval has passed. Basically
this is a subsecond-resolution C<sleep ()>.
this is a sub-second-resolution C<sleep ()>.
=item int ev_version_major ()
@ -202,7 +202,7 @@ a must have and can we have a torrent of it please!!!11
Return the set of all backends compiled into this binary of libev and also
recommended for this platform. This set is often smaller than the one
returned by C<ev_supported_backends>, as for example kqueue is broken on
most BSDs and will not be autodetected unless you explicitly request it
most BSDs and will not be auto-detected unless you explicitly request it
(assuming you know what you are doing). This is the set of backends that
libev will probe for if you specify no backends explicitly.
@ -254,10 +254,10 @@ retries (example requires a standards-compliant C<realloc>).
=item ev_set_syserr_cb (void (*cb)(const char *msg));
Set the callback function to call on a retryable syscall error (such
Set the callback function to call on a retryable system call error (such
as failed select, poll, epoll_wait). The message is a printable string
indicating the system call or subsystem causing the problem. If this
callback is set, then libev will expect it to remedy the sitution, no
callback is set, then libev will expect it to remedy the situation, no
matter what, when it returns. That is, libev will generally retry the
requested operation, or, if the condition doesn't go away, do bad stuff
(such as abort).
@ -300,7 +300,7 @@ as loops cannot bes hared easily between threads anyway).
The default loop is the only loop that can handle C<ev_signal> and
C<ev_child> watchers, and to do this, it always registers a handler
for C<SIGCHLD>. If this is a problem for your app you can either
for C<SIGCHLD>. If this is a problem for your application you can either
create a dynamic loop with C<ev_loop_new> that doesn't do that, or you
can simply overwrite the C<SIGCHLD> signal handler I<after> calling
C<ev_default_init>.
@ -319,7 +319,7 @@ thing, believe me).
=item C<EVFLAG_NOENV>
If this flag bit is ored into the flag value (or the program runs setuid
If this flag bit is or'ed into the flag value (or the program runs setuid
or setgid) then libev will I<not> look at the environment variable
C<LIBEV_FLAGS>. Otherwise (the default), this environment variable will
override the flags completely if it is found in the environment. This is
@ -336,14 +336,14 @@ This works by calling C<getpid ()> on every iteration of the loop,
and thus this might slow down your event loop if you do a lot of loop
iterations and little real work, but is usually not noticeable (on my
GNU/Linux system for example, C<getpid> is actually a simple 5-insn sequence
without a syscall and thus I<very> fast, but my GNU/Linux system also has
without a system call and thus I<very> fast, but my GNU/Linux system also has
C<pthread_atfork> which is even faster).
The big advantage of this flag is that you can forget about fork (and
forget about forgetting to tell libev about forking) when you use this
flag.
This flag setting cannot be overriden or specified in the C<LIBEV_FLAGS>
This flag setting cannot be overridden or specified in the C<LIBEV_FLAGS>
environment variable.
=item C<EVBACKEND_SELECT> (value 1, portable select backend)
@ -355,7 +355,7 @@ using this backend. It doesn't scale too well (O(highest_fd)), but its
usually the fastest backend for a low number of (low-numbered :) fds.
To get good performance out of this backend you need a high amount of
parallelity (most of the file descriptors should be busy). If you are
parallelism (most of the file descriptors should be busy). If you are
writing a server, you should C<accept ()> in a loop to accept as many
connections as possible during one iteration. You might also want to have
a look at C<ev_set_io_collect_interval ()> to increase the amount of
@ -377,11 +377,11 @@ but it scales phenomenally better. While poll and select usually scale
like O(total_fds) where n is the total number of fds (or the highest fd),
epoll scales either O(1) or O(active_fds). The epoll design has a number
of shortcomings, such as silently dropping events in some hard-to-detect
cases and requiring a syscall per fd change, no fork support and bad
cases and requiring a system call per fd change, no fork support and bad
support for dup.
While stopping, setting and starting an I/O watcher in the same iteration
will result in some caching, there is still a syscall per such incident
will result in some caching, there is still a system call per such incident
(because the fd could point to a different file description now), so its
best to avoid that. Also, C<dup ()>'ed file descriptors might not work
very well if you register events for both fds.
@ -394,7 +394,7 @@ Best performance from this backend is achieved by not unregistering all
watchers for a file descriptor until it has been closed, if possible, i.e.
keep at least one watcher active per fd at all times.
While nominally embeddeble in other event loops, this feature is broken in
While nominally embeddable in other event loops, this feature is broken in
all kernel versions tested so far.
=item C<EVBACKEND_KQUEUE> (value 8, most BSD clones)
@ -402,7 +402,7 @@ all kernel versions tested so far.
Kqueue deserves special mention, as at the time of this writing, it
was broken on all BSDs except NetBSD (usually it doesn't work reliably
with anything but sockets and pipes, except on Darwin, where of course
it's completely useless). For this reason it's not being "autodetected"
it's completely useless). For this reason it's not being "auto-detected"
unless you explicitly specify it explicitly in the flags (i.e. using
C<EVBACKEND_KQUEUE>) or libev was compiled on a known-to-be-good (-enough)
system like NetBSD.
@ -414,7 +414,7 @@ the target platform). See C<ev_embed> watchers for more info.
It scales in the same way as the epoll backend, but the interface to the
kernel is more efficient (which says nothing about its actual speed, of
course). While stopping, setting and starting an I/O watcher does never
cause an extra syscall as with C<EVBACKEND_EPOLL>, it still adds up to
cause an extra system call as with C<EVBACKEND_EPOLL>, it still adds up to
two event changes per incident, support for C<fork ()> is very bad and it
drops fds silently in similarly hard-to-detect cases.
@ -439,7 +439,7 @@ immensely.
This uses the Solaris 10 event port mechanism. As with everything on Solaris,
it's really slow, but it still scales very well (O(active_fds)).
Please note that solaris event ports can deliver a lot of spurious
Please note that Solaris event ports can deliver a lot of spurious
notifications, so you need to use non-blocking I/O or other means to avoid
blocking when no data (or space) is available.
@ -462,7 +462,7 @@ It is definitely not recommended to use this flag.
=back
If one or more of these are ored into the flags value, then only these
If one or more of these are or'ed into the flags value, then only these
backends will be tried (in the reverse order as listed here). If none are
specified, all backends in C<ev_recommended_backends ()> will be tried.
@ -504,7 +504,7 @@ Example: Try to create a event loop that uses epoll and nothing else.
Destroys the default loop again (frees all memory and kernel state
etc.). None of the active event watchers will be stopped in the normal
sense, so e.g. C<ev_is_active> might still return true. It is your
responsibility to either stop all watchers cleanly yoursef I<before>
responsibility to either stop all watchers cleanly yourself I<before>
calling this function, or cope with the fact afterwards (which is usually
the easiest thing, you can just ignore the watchers and/or C<free ()> them
for example).
@ -595,7 +595,7 @@ those events and any outstanding ones, but will not block your process in
case there are no events and will return after one iteration of the loop.
A flags value of C<EVLOOP_ONESHOT> will look for new events (waiting if
neccessary) and will handle those and any outstanding ones. It will block
necessary) and will handle those and any outstanding ones. It will block
your process until at least one new event arrives, and will return after
one iteration of the loop. This is useful if you are waiting for some
external event in conjunction with something not expressible using other
@ -706,11 +706,11 @@ latency (the watcher callback will be called later). C<ev_io> 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
Many (busy) programs can usually benefit by setting the I/O 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.
as this approaches the timing granularity of most systems.
=item ev_loop_verify (loop)
@ -751,7 +751,7 @@ although this can sometimes be quite valid).
Each watcher structure must be initialised by a call to C<ev_init
(watcher *, callback)>, which expects a callback to be provided. This
callback gets invoked each time the event occurs (or, in the case of io
callback gets invoked each time the event occurs (or, in the case of I/O
watchers, each time the event loop detects that the file descriptor given
is readable and/or writable).
@ -837,7 +837,7 @@ The given async watcher has been asynchronously notified (see C<ev_async>).
=item C<EV_ERROR>
An unspecified error has occured, the watcher has been stopped. This might
An unspecified error has occurred, the watcher has been stopped. This might
happen because the watcher could not be properly started because libev
ran out of memory, a file descriptor was found to be closed or any other
problem. You best act on it by reporting the problem and somehow coping
@ -846,7 +846,7 @@ with the watcher being stopped.
Libev will usually signal a few "dummy" events together with an error,
for example it might indicate that a fd is readable or writable, and if
your callbacks is well-written it can just attempt the operation and cope
with the error from read() or write(). This will not work in multithreaded
with the error from read() or write(). This will not work in multi-threaded
programs, though, so beware.
=back
@ -886,8 +886,8 @@ Although some watcher types do not have type-specific arguments
=item C<ev_TYPE_init> (ev_TYPE *watcher, callback, [args])
This convinience macro rolls both C<ev_init> and C<ev_TYPE_set> macro
calls into a single call. This is the most convinient method to initialise
This convenience macro rolls both C<ev_init> and C<ev_TYPE_set> macro
calls into a single call. This is the most convenient method to initialise
a watcher. The same limitations apply, of course.
=item C<ev_TYPE_start> (loop *, ev_TYPE *watcher)
@ -1069,13 +1069,13 @@ Another thing you have to watch out for is that it is quite easy to
receive "spurious" readiness notifications, that is your callback might
be called with C<EV_READ> but a subsequent C<read>(2) will actually block
because there is no data. Not only are some backends known to create a
lot of those (for example solaris ports), it is very easy to get into
lot of those (for example Solaris ports), it is very easy to get into
this situation even with a relatively standard program structure. Thus
it is best to always use non-blocking I/O: An extra C<read>(2) returning
C<EAGAIN> is far preferable to a program hanging until some data arrives.
If you cannot run the fd in non-blocking mode (for example you should not
play around with an Xlib connection), then you have to seperately re-test
play around with an Xlib connection), then you have to separately re-test
whether a file descriptor is really ready with a known-to-be good interface
such as poll (fortunately in our Xlib example, Xlib already does this on
its own, so its quite safe to use).
@ -1145,7 +1145,7 @@ somewhere, as that would have given you a big clue).
=item ev_io_set (ev_io *, int fd, int events)
Configures an C<ev_io> watcher. The C<fd> is the file descriptor to
rceeive events for and events is either C<EV_READ>, C<EV_WRITE> or
receive events for and events is either C<EV_READ>, C<EV_WRITE> or
C<EV_READ | EV_WRITE> to receive the given events.
=item int fd [read-only]
@ -1185,7 +1185,7 @@ Timer watchers are simple relative timers that generate an event after a
given time, and optionally repeating in regular intervals after that.
The timers are based on real time, that is, if you register an event that
times out after an hour and you reset your system clock to january last
times out after an hour and you reset your system clock to January last
year, it will still time out after (roughly) and hour. "Roughly" because
detecting time jumps is hard, and some inaccuracies are unavoidable (the
monotonic clock option helps a lot here).
@ -1198,7 +1198,7 @@ on the current time, use something like this to adjust for this:
ev_timer_set (&timer, after + ev_now () - ev_time (), 0.);
The callback is guarenteed to be invoked only after its timeout has passed,
The callback is guaranteed to be invoked only after its timeout has passed,
but if multiple timers become ready during the same loop iteration then
order of execution is undefined.
@ -1229,13 +1229,13 @@ repeating. The exact semantics are:
If the timer is pending, its pending status is cleared.
If the timer is started but nonrepeating, stop it (as if it timed out).
If the timer is started but non-repeating, stop it (as if it timed out).
If the timer is repeating, either start it if necessary (with the
C<repeat> value), or reset the running timer to the C<repeat> value.
This sounds a bit complicated, but here is a useful and typical
example: Imagine you have a tcp connection and you want a so-called idle
example: Imagine you have a TCP connection and you want a so-called idle
timeout, that is, you want to be called when there have been, say, 60
seconds of inactivity on the socket. The easiest way to do this is to
configure an C<ev_timer> with a C<repeat> value of C<60> and then call
@ -1306,11 +1306,11 @@ Periodic watchers are also timers of a kind, but they are very versatile
(and unfortunately a bit complex).
Unlike C<ev_timer>'s, they are not based on real time (or relative time)
but on wallclock time (absolute time). You can tell a periodic watcher
but on wall clock time (absolute time). You can tell a periodic watcher
to trigger after some specific point in time. For example, if you tell a
periodic watcher to trigger in 10 seconds (by specifiying e.g. C<ev_now ()
periodic watcher to trigger in 10 seconds (by specifying e.g. C<ev_now ()
+ 10.>, that is, an absolute time not a delay) and then reset your system
clock to january of the previous year, then it will take more than year
clock to January of the previous year, then it will take more than year
to trigger the event (unlike an C<ev_timer>, which would still trigger
roughly 10 seconds later as it uses a relative timeout).
@ -1318,7 +1318,7 @@ C<ev_periodic>s can also be used to implement vastly more complex timers,
such as triggering an event on each "midnight, local time", or other
complicated, rules.
As with timers, the callback is guarenteed to be invoked only when the
As with timers, the callback is guaranteed to be invoked only when the
time (C<at>) has passed, but if multiple periodic timers become ready
during the same loop iteration then order of execution is undefined.
@ -1337,7 +1337,7 @@ operation, and we will explain them from simplest to complex:
=item * absolute timer (at = time, interval = reschedule_cb = 0)
In this configuration the watcher triggers an event after the wallclock
In this configuration the watcher triggers an event after the wall clock
time C<at> has passed and doesn't repeat. It will not adjust when a time
jump occurs, that is, if it is to be run at January 1st 2011 then it will
run when the system time reaches or surpasses this time.
@ -1355,7 +1355,7 @@ the hour:
ev_periodic_set (&periodic, 0., 3600., 0);
This doesn't mean there will always be 3600 seconds in between triggers,
but only that the the callback will be called when the system time shows a
but only that the callback will be called when the system time shows a
full hour (UTC), or more correctly, when the system time is evenly divisible
by 3600.
@ -1367,9 +1367,9 @@ For numerical stability it is preferable that the C<at> value is near
C<ev_now ()> (the current time), but there is no range requirement for
this value, and in fact is often specified as zero.
Note also that there is an upper limit to how often a timer can fire (cpu
Note also that there is an upper limit to how often a timer can fire (CPU
speed for example), so if C<interval> is very small then timing stability
will of course detoriate. Libev itself tries to be exact to be about one
will of course deteriorate. Libev itself tries to be exact to be about one
millisecond (if the OS supports it and the machine is fast enough).
=item * manual reschedule mode (at and interval ignored, reschedule_cb = callback)
@ -1448,7 +1448,7 @@ the periodic timer fires or C<ev_periodic_again> is being called.
Example: Call a callback every hour, or, more precisely, whenever the
system clock is divisible by 3600. The callback invocation times have
potentially a lot of jittering, but good long-term stability.
potentially a lot of jitter, but good long-term stability.
static void
clock_cb (struct ev_loop *loop, struct ev_io *w, int revents)
@ -1495,8 +1495,8 @@ watcher for a signal is stopped libev will reset the signal handler to
SIG_DFL (regardless of what it was set to before).
If possible and supported, libev will install its handlers with
C<SA_RESTART> behaviour enabled, so syscalls should not be unduly
interrupted. If you have a problem with syscalls getting interrupted by
C<SA_RESTART> behaviour enabled, so system calls should not be unduly
interrupted. If you have a problem with system calls getting interrupted by
signals you can block all signals in an C<ev_check> watcher and unblock
them in an C<ev_prepare> watcher.
@ -1541,13 +1541,13 @@ forked (which implies it might have already exited), as long as the event
loop isn't entered (or is continued from a watcher).
Only the default event loop is capable of handling signals, and therefore
you can only rgeister child watchers in the default event loop.
you can only register child watchers in the default event loop.
=head3 Process Interaction
Libev grabs C<SIGCHLD> as soon as the default event loop is
initialised. This is necessary to guarantee proper behaviour even if
the first child watcher is started after the child exits. The occurance
the first child watcher is started after the child exits. The occurrence
of C<SIGCHLD> is recorded asynchronously, but child reaping is done
synchronously as part of the event loop processing. Libev always reaps all
children, even ones not watched.
@ -1626,7 +1626,7 @@ its completion.
=head2 C<ev_stat> - did the file attributes just change?
This watches a filesystem path for attribute changes. That is, it calls
This watches a file system path for attribute changes. That is, it calls
C<stat> regularly (or when the OS says it changed) and sees if it changed
compared to the last time, invoking the callback if it did.
@ -1670,7 +1670,7 @@ structure. When using the library from programs that change the ABI to
use 64 bit file offsets the programs will fail. In that case you have to
compile libev with the same flags to get binary compatibility. This is
obviously the case with any flags that change the ABI, but the problem is
most noticably with ev_stat and largefile support.
most noticeably with ev_stat and large file support.
=head3 Inotify
@ -1690,8 +1690,8 @@ descriptor open on the object at all times).
=head3 The special problem of stat time resolution
The C<stat ()> syscall only supports full-second resolution portably, and
even on systems where the resolution is higher, many filesystems still
The C<stat ()> system call only supports full-second resolution portably, and
even on systems where the resolution is higher, many file systems still
only support whole seconds.
That means that, if the time is the only thing that changes, you can
@ -1761,7 +1761,7 @@ The specified interval.
=item const char *path [read-only]
The filesystem path that is being watched.
The file system path that is being watched.
=back
@ -1897,7 +1897,7 @@ This is done by examining in each prepare call which file descriptors need
to be watched by the other library, registering C<ev_io> watchers for
them and starting an C<ev_timer> watcher for any timeouts (many libraries
provide just this functionality). Then, in the check watcher you check for
any events that occured (by checking the pending status of all watchers
any events that occurred (by checking the pending status of all watchers
and stopping them) and call back into the library. The I/O and timer
callbacks will never actually be called (but must be valid nevertheless,
because you never know, you know?).
@ -2009,7 +2009,7 @@ Method 2: This would be just like method 1, but you run C<adns_afterpoll>
in the prepare watcher and would dispose of the check watcher.
Method 3: If the module to be embedded supports explicit event
notification (adns does), you can also make use of the actual watcher
notification (libadns does), you can also make use of the actual watcher
callbacks, and only destroy/create the watchers in the prepare watcher.
static void
@ -2034,7 +2034,7 @@ callbacks, and only destroy/create the watchers in the prepare watcher.
// do not ever call adns_afterpoll
Method 4: Do not use a prepare or check watcher because the module you
want to embed is too inflexible to support it. Instead, youc na override
want to embed is too inflexible to support it. Instead, you can override
their poll function. The drawback with this solution is that the main
loop is now no longer controllable by EV. The C<Glib::EV> module does
this.
@ -2128,13 +2128,13 @@ Configures the watcher to embed the given loop, which must be
embeddable. If the callback is C<0>, then C<ev_embed_sweep> will be
invoked automatically, otherwise it is the responsibility of the callback
to invoke it (it will continue to be called until the sweep has been done,
if you do not want thta, you need to temporarily stop the embed watcher).
if you do not want that, you need to temporarily stop the embed watcher).
=item ev_embed_sweep (loop, ev_embed *)
Make a single, non-blocking sweep over the embedded loop. This works
similarly to C<ev_loop (embedded_loop, EVLOOP_NONBLOCK)>, but in the most
apropriate way for embedded loops.
appropriate way for embedded loops.
=item struct ev_loop *other [read-only]
@ -2146,8 +2146,8 @@ The embedded event loop.
Example: Try to get an embeddable event loop and embed it into the default
event loop. If that is not possible, use the default loop. The default
loop is stored in C<loop_hi>, while the mebeddable loop is stored in
C<loop_lo> (which is C<loop_hi> in the acse no embeddable loop can be
loop is stored in C<loop_hi>, while the embeddable loop is stored in
C<loop_lo> (which is C<loop_hi> in the case no embeddable loop can be
used).
struct ev_loop *loop_hi = ev_default_init (0);
@ -2251,7 +2251,7 @@ queue:
To implement race-free queueing, you simply add to the queue in the signal
handler but you block the signal handler in the watcher callback. Here is an example that does that for
some fictitiuous SIGUSR1 handler:
some fictitious SIGUSR1 handler:
static ev_async mysig;
@ -2335,11 +2335,11 @@ believe me.
Sends/signals/activates the given C<ev_async> watcher, that is, feeds
an C<EV_ASYNC> event on the watcher into the event loop. Unlike
C<ev_feed_event>, this call is safe to do in other threads, signal or
similar contexts (see the dicusssion of C<EV_ATOMIC_T> in the embedding
similar contexts (see the discussion of C<EV_ATOMIC_T> in the embedding
section below on what exactly this means).
This call incurs the overhead of a syscall only once per loop iteration,
so while the overhead might be noticable, it doesn't apply to repeated
This call incurs the overhead of a system call only once per loop iteration,
so while the overhead might be noticeable, it doesn't apply to repeated
calls to C<ev_async_send>.
=item bool = ev_async_pending (ev_async *)
@ -2351,10 +2351,10 @@ event loop.
C<ev_async_send> sets a flag in the watcher and wakes up the loop. When
the loop iterates next and checks for the watcher to have become active,
it will reset the flag again. C<ev_async_pending> can be used to very
quickly check wether invoking the loop might be a good idea.
quickly check whether invoking the loop might be a good idea.
Not that this does I<not> check wether the watcher itself is pending, only
wether it has been requested to make this watcher pending.
Not that this does I<not> check whether the watcher itself is pending, only
whether it has been requested to make this watcher pending.
=back
@ -2375,7 +2375,7 @@ more watchers yourself.
If C<fd> is less than 0, then no I/O watcher will be started and events
is being ignored. Otherwise, an C<ev_io> watcher for the given C<fd> and
C<events> set will be craeted and started.
C<events> set will be created and started.
If C<timeout> is less than 0, then no timeout watcher will be
started. Otherwise an C<ev_timer> watcher with after = C<timeout> (and
@ -2410,7 +2410,7 @@ the given events it.
=item ev_feed_signal_event (ev_loop *loop, int signum)
Feed an event as if the given signal occured (C<loop> must be the default
Feed an event as if the given signal occurred (C<loop> must be the default
loop!).
=back
@ -2449,7 +2449,7 @@ to use the libev header file and library.
=head1 C++ SUPPORT
Libev comes with some simplistic wrapper classes for C++ that mainly allow
you to use some convinience methods to start/stop watchers and also change
you to use some convenience methods to start/stop watchers and also change
the callback model to a model using method callbacks on objects.
To use it,
@ -2560,9 +2560,9 @@ Example:
Associates a different C<struct ev_loop> with this watcher. You can only
do this when the watcher is inactive (and not pending either).
=item w->set ([args])
=item w->set ([arguments])
Basically the same as C<ev_TYPE_set>, with the same args. Must be
Basically the same as C<ev_TYPE_set>, with the same arguments. Must be
called at least once. Unlike the C counterpart, an active watcher gets
automatically stopped and restarted when reconfiguring it with this
method.
@ -2614,7 +2614,7 @@ the constructor.
=head1 OTHER LANGUAGE BINDINGS
Libev does not offer other language bindings itself, but bindings for a
numbe rof languages exist in the form of third-party packages. If you know
number of languages exist in the form of third-party packages. If you know
any interesting language binding in addition to the ones listed here, drop
me a note.
@ -2634,7 +2634,7 @@ L<http://software.schmorp.de/pkg/EV>.
=item Ruby
Tony Arcieri has written a ruby extension that offers access to a subset
of the libev API and adds filehandle abstractions, asynchronous DNS and
of the libev API and adds file handle abstractions, asynchronous DNS and
more on top of it. It can be found via gem servers. Its homepage is at
L<http://rev.rubyforge.org/>.
@ -2648,7 +2648,7 @@ be found at L<http://git.llucax.com.ar/?p=software/ev.d.git;a=summary>.
=head1 MACRO MAGIC
Libev can be compiled with a variety of options, the most fundamantal
Libev can be compiled with a variety of options, the most fundamental
of which is C<EV_MULTIPLICITY>. This option determines whether (most)
functions and callbacks have an initial C<struct ev_loop *> argument.
@ -2732,7 +2732,7 @@ libev somewhere in your source tree).
=head2 FILESETS
Depending on what features you need you need to include one or more sets of files
in your app.
in your application.
=head3 CORE EVENT LOOP
@ -2793,7 +2793,7 @@ You need the following additional files for this:
=head3 AUTOCONF SUPPORT
Instead of using C<EV_STANDALONE=1> and providing your config in
Instead of using C<EV_STANDALONE=1> and providing your configuration in
whatever way you want, you can also C<m4_include([libev.m4])> in your
F<configure.ac> and leave C<EV_STANDALONE> undefined. F<ev.c> will then
include F<config.h> and configure itself accordingly.
@ -2805,7 +2805,7 @@ For this of course you need the m4 file:
=head2 PREPROCESSOR SYMBOLS/MACROS
Libev can be configured via a variety of preprocessor symbols you have to
define before including any of its files. The default in the absense of
define before including any of its files. The default in the absence of
autoconf is noted for every option.
=over 4
@ -2821,7 +2821,7 @@ F<event.h> that are not directly supported by the libev core alone.
=item EV_USE_MONOTONIC
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
monotonic clock option at both compile time 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, although you have
@ -2831,8 +2831,8 @@ function is hiding in (often F<-lrt>).
=item EV_USE_REALTIME
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
real-time clock option at compile time (and assume its availability at
runtime if successful). Otherwise no use of the real-time clock option will
be attempted. This effectively replaces C<gettimeofday> by C<clock_get
(CLOCK_REALTIME, ...)> and will not normally affect correctness. See the
note about libraries in the description of C<EV_USE_MONOTONIC>, though.
@ -2853,7 +2853,7 @@ If undefined, it will be enabled if the headers indicate GNU/Linux + Glibc
=item EV_USE_SELECT
If undefined or defined to be C<1>, libev will compile in support for the
C<select>(2) backend. No attempt at autodetection will be done: if no
C<select>(2) backend. No attempt at auto-detection will be done: if no
other method takes over, select will be it. Otherwise the select backend
will not be compiled in.
@ -2861,7 +2861,7 @@ will not be compiled in.
If defined to C<1>, then the select backend will use the system C<fd_set>
structure. This is useful if libev doesn't compile due to a missing
C<NFDBITS> or C<fd_mask> definition or it misguesses the bitset layout on
C<NFDBITS> or C<fd_mask> definition or it mis-guesses the bitset layout on
exotic systems. This usually limits the range of file descriptors to some
low limit such as 1024 or might have other limitations (winsocket only
allows 64 sockets). The C<FD_SETSIZE> macro, set before compilation, might
@ -2920,7 +2920,7 @@ backend for Solaris 10 systems.
=item EV_USE_DEVPOLL
reserved for future expansion, works like the USE symbols above.
Reserved for future expansion, works like the USE symbols above.
=item EV_USE_INOTIFY
@ -2937,7 +2937,7 @@ type is easily found in the C language, so you can provide your own type
that you know is safe for your purposes. It is used both for signal handler "locking"
as well as for signal and thread safety in C<ev_async> watchers.
In the absense of this define, libev will use C<sig_atomic_t volatile>
In the absence of this define, libev will use C<sig_atomic_t volatile>
(from F<signal.h>), which is usually good enough on most platforms.
=item EV_H
@ -2986,8 +2986,8 @@ all the priorities, so having many of them (hundreds) uses a lot of space
and time, so using the defaults of five priorities (-2 .. +2) is usually
fine.
If your embedding app does not need any priorities, defining these both to
C<0> will save some memory and cpu.
If your embedding application does not need any priorities, defining these both to
C<0> will save some memory and CPU.
=item EV_PERIODIC_ENABLE
@ -3025,7 +3025,7 @@ defined to be C<0>, then they are not.
If you need to shave off some kilobytes of code at the expense of some
speed, define this symbol to C<1>. Currently this is used to override some
inlining decisions, saves roughly 30% codesize of amd64. It also selects a
inlining decisions, saves roughly 30% code size on amd64. It also selects a
much smaller 2-heap for timer management over the default 4-heap.
=item EV_PID_HASHSIZE
@ -3048,7 +3048,7 @@ two).
Heaps are not very cache-efficient. To improve the cache-efficiency of the
timer and periodics heap, libev uses a 4-heap when this symbol is defined
to C<1>. The 4-heap uses more complicated (longer) code but has
noticably faster performance with many (thousands) of watchers.
noticeably faster performance with many (thousands) of watchers.
The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0>
(disabled).
@ -3060,7 +3060,7 @@ timer and periodics heap, libev can cache the timestamp (I<at>) within
the heap structure (selected by defining C<EV_HEAP_CACHE_AT> to C<1>),
which uses 8-12 bytes more per watcher and a few hundred bytes more code,
but avoids random read accesses on heap changes. This improves performance
noticably with with many (hundreds) of watchers.
noticeably with with many (hundreds) of watchers.
The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0>
(disabled).
@ -3106,7 +3106,7 @@ method calls instead of plain function calls in C++.
=head2 EXPORTED API SYMBOLS
If you need to re-export the API (e.g. via a dll) and you need a list of
If you need to re-export the API (e.g. via a DLL) and you need a list of
exported symbols, you can use the provided F<Symbol.*> files which list
all public symbols, one per line:
@ -3115,7 +3115,7 @@ all public symbols, one per line:
This can also be used to rename all public symbols to avoid clashes with
multiple versions of libev linked together (which is obviously bad in
itself, but sometimes it is inconvinient to avoid this).
itself, but sometimes it is inconvenient to avoid this).
A sed command like this will create wrapper C<#define>'s that you need to
include before including F<ev.h>:
@ -3164,7 +3164,7 @@ And a F<ev_cpp.C> implementation file that contains libev proper and is compiled
=head2 THREADS
Libev itself is completely threadsafe, but it uses no locking. This
Libev itself is completely thread-safe, but it uses no locking. This
means that you can use as many loops as you want in parallel, as long as
only one thread ever calls into one libev function with the same loop
parameter.
@ -3181,7 +3181,7 @@ help you but by giving some generic advice:
=over 4
=item * most applications have a main thread: use the default libev loop
in that thread, or create a seperate thread running only the default loop.
in that thread, or create a separate thread running only the default loop.
This helps integrating other libraries or software modules that use libev
themselves and don't care/know about threading.
@ -3192,9 +3192,9 @@ Doing this is almost never wrong, sometimes a better-performance model
exists, but it is always a good start.
=item * other models exist, such as the leader/follower pattern, where one
loop is handed through multiple threads in a kind of round-robbin fashion.
loop is handed through multiple threads in a kind of round-robin fashion.
Chosing a model is hard - look around, learn, know that usually you cna do
Choosing a model is hard - look around, learn, know that usually you can do
better than you currently do :-)
=item * often you need to talk to some other thread which blocks in the
@ -3205,7 +3205,7 @@ threads safely (or from signal contexts...).
=head2 COROUTINES
Libev is much more accomodating to coroutines ("cooperative threads"):
Libev is much more accommodating to coroutines ("cooperative threads"):
libev fully supports nesting calls to it's functions from different
coroutines (e.g. you can call C<ev_loop> on the same loop from two
different coroutines and switch freely between both coroutines running the
@ -3263,7 +3263,7 @@ fixed position in the storage array.
A change means an I/O watcher gets started or stopped, which requires
libev to recalculate its status (and possibly tell the kernel, depending
on backend and wether C<ev_io_set> was used).
on backend and whether C<ev_io_set> was used).
=item Activating one watcher (putting it into the pending state): O(1)
@ -3280,7 +3280,7 @@ watchers becomes O(1) w.r.t. priority handling.
=item Processing signals: O(max_signal_number)
Sending involves a syscall I<iff> there were no other C<ev_async_send>
Sending involves a system call I<iff> there were no other C<ev_async_send>
calls in the current loop iteration. Checking for async and signal events
involves iterating over all running async watchers or all signal numbers.
@ -3310,7 +3310,7 @@ is not recommended (and not reasonable). If your program needs to use
more than a hundred or so sockets, then likely it needs to use a totally
different implementation for windows, as libev offers the POSIX readiness
notification model, which cannot be implemented efficiently on windows
(microsoft monopoly games).
(Microsoft monopoly games).
=over 4
@ -3323,7 +3323,7 @@ requires a mapping from file descriptors to socket handles. See the
discussion of the C<EV_SELECT_USE_FD_SET>, C<EV_SELECT_IS_WINSOCKET> and
C<EV_FD_TO_WIN32_HANDLE> preprocessor symbols for more info.
The configuration for a "naked" win32 using the microsoft runtime
The configuration for a "naked" win32 using the Microsoft runtime
libraries and raw winsocket select is:
#define EV_USE_SELECT 1
@ -3338,7 +3338,7 @@ Windows has numerous arbitrary (and low) limits on things.
Early versions of winsocket's select only supported waiting for a maximum
of C<64> handles (probably owning to the fact that all windows kernels
can only wait for C<64> things at the same time internally; microsoft
can only wait for C<64> things at the same time internally; Microsoft
recommends spawning a chain of threads and wait for 63 handles and the
previous thread in each. Great).
@ -3347,11 +3347,11 @@ to some high number (e.g. C<2048>) before compiling the winsocket select
call (which might be in libev or elsewhere, for example, perl does its own
select emulation on windows).
Another limit is the number of file descriptors in the microsoft runtime
Another limit is the number of file descriptors in the Microsoft runtime
libraries, which by default is C<64> (there must be a hidden I<64> fetish
or something like this inside microsoft). You can increase this by calling
or something like this inside Microsoft). You can increase this by calling
C<_setmaxstdio>, which can increase this limit to C<2048> (another
arbitrary limit), but is broken in many versions of the microsoft runtime
arbitrary limit), but is broken in many versions of the Microsoft runtime
libraries.
This might get you to about C<512> or C<2048> sockets (depending on
@ -3418,14 +3418,14 @@ scared by this.
However, these are unavoidable for many reasons. For one, each compiler
has different warnings, and each user has different tastes regarding
warning options. "Warn-free" code therefore cannot be a goal except when
targetting a specific compiler and compiler-version.
targeting a specific compiler and compiler-version.
Another reason is that some compiler warnings require elaborate
workarounds, or other changes to the code that make it less clear and less
maintainable.
And of course, some compiler warnings are just plain stupid, or simply
wrong (because they don't actually warn about the cindition their message
wrong (because they don't actually warn about the condition their message
seems to warn about).
While libev is written to generate as few warnings as possible,
@ -3447,7 +3447,7 @@ in libev, then check twice: If valgrind reports something like:
==2274== possibly lost: 0 bytes in 0 blocks.
==2274== still reachable: 256 bytes in 1 blocks.
then there is no memory leak. Similarly, under some circumstances,
Then there is no memory leak. Similarly, under some circumstances,
valgrind might report kernel bugs as if it were a bug in libev, or it
might be confused (it is a very good tool, but only a tool).

Loading…
Cancel
Save