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

Comparing libev/ev.pod (file contents):
Revision 1.299 by sf-exg, Sat Aug 28 21:42:12 2010 UTC vs.
Revision 1.309 by root, Thu Oct 21 09:23:21 2010 UTC

439of course I<doesn't>, and epoll just loves to report events for totally 439of course I<doesn't>, and epoll just loves to report events for totally
440I<different> file descriptors (even already closed ones, so one cannot 440I<different> file descriptors (even already closed ones, so one cannot
441even remove them from the set) than registered in the set (especially 441even remove them from the set) than registered in the set (especially
442on SMP systems). Libev tries to counter these spurious notifications by 442on SMP systems). Libev tries to counter these spurious notifications by
443employing an additional generation counter and comparing that against the 443employing an additional generation counter and comparing that against the
444events to filter out spurious ones, recreating the set when required. 444events to filter out spurious ones, recreating the set when required. Last
445not least, it also refuses to work with some file descriptors which work
446perfectly fine with C<select> (files, many character devices...).
445 447
446While stopping, setting and starting an I/O watcher in the same iteration 448While stopping, setting and starting an I/O watcher in the same iteration
447will result in some caching, there is still a system call per such 449will result in some caching, there is still a system call per such
448incident (because the same I<file descriptor> could point to a different 450incident (because the same I<file descriptor> could point to a different
449I<file description> now), so its best to avoid that. Also, C<dup ()>'ed 451I<file description> now), so its best to avoid that. Also, C<dup ()>'ed
952These two functions can be used to associate arbitrary data with a loop, 954These two functions can be used to associate arbitrary data with a loop,
953and are intended solely for the C<invoke_pending_cb>, C<release> and 955and are intended solely for the C<invoke_pending_cb>, C<release> and
954C<acquire> callbacks described above, but of course can be (ab-)used for 956C<acquire> callbacks described above, but of course can be (ab-)used for
955any other purpose as well. 957any other purpose as well.
956 958
957=item ev_loop_verify (loop) 959=item ev_verify (loop)
958 960
959This function only does something when C<EV_VERIFY> support has been 961This function only does something when C<EV_VERIFY> support has been
960compiled in, which is the default for non-minimal builds. It tries to go 962compiled in, which is the default for non-minimal builds. It tries to go
961through all internal structures and checks them for validity. If anything 963through all internal structures and checks them for validity. If anything
962is found to be inconsistent, it will print an error message to standard 964is found to be inconsistent, it will print an error message to standard
2123Example: Call a callback every hour, or, more precisely, whenever the 2125Example: Call a callback every hour, or, more precisely, whenever the
2124system time is divisible by 3600. The callback invocation times have 2126system time is divisible by 3600. The callback invocation times have
2125potentially a lot of jitter, but good long-term stability. 2127potentially a lot of jitter, but good long-term stability.
2126 2128
2127 static void 2129 static void
2128 clock_cb (struct ev_loop *loop, ev_io *w, int revents) 2130 clock_cb (struct ev_loop *loop, ev_periodic *w, int revents)
2129 { 2131 {
2130 ... its now a full hour (UTC, or TAI or whatever your clock follows) 2132 ... its now a full hour (UTC, or TAI or whatever your clock follows)
2131 } 2133 }
2132 2134
2133 ev_periodic hourly_tick; 2135 ev_periodic hourly_tick;
2965C<ev_default_fork> cheats and calls it in the wrong process, the fork 2967C<ev_default_fork> cheats and calls it in the wrong process, the fork
2966handlers will be invoked, too, of course. 2968handlers will be invoked, too, of course.
2967 2969
2968=head3 The special problem of life after fork - how is it possible? 2970=head3 The special problem of life after fork - how is it possible?
2969 2971
2970Most uses of C<fork()> consist of forking, then some simple calls to ste 2972Most uses of C<fork()> consist of forking, then some simple calls to set
2971up/change the process environment, followed by a call to C<exec()>. This 2973up/change the process environment, followed by a call to C<exec()>. This
2972sequence should be handled by libev without any problems. 2974sequence should be handled by libev without any problems.
2973 2975
2974This changes when the application actually wants to do event handling 2976This changes when the application actually wants to do event handling
2975in the child, or both parent in child, in effect "continuing" after the 2977in the child, or both parent in child, in effect "continuing" after the
3009believe me. 3011believe me.
3010 3012
3011=back 3013=back
3012 3014
3013 3015
3014=head2 C<ev_async> - how to wake up another event loop 3016=head2 C<ev_async> - how to wake up an event loop
3015 3017
3016In general, you cannot use an C<ev_loop> from multiple threads or other 3018In general, you cannot use an C<ev_loop> from multiple threads or other
3017asynchronous sources such as signal handlers (as opposed to multiple event 3019asynchronous sources such as signal handlers (as opposed to multiple event
3018loops - those are of course safe to use in different threads). 3020loops - those are of course safe to use in different threads).
3019 3021
3020Sometimes, however, you need to wake up another event loop you do not 3022Sometimes, however, you need to wake up an event loop you do not control,
3021control, for example because it belongs to another thread. This is what 3023for example because it belongs to another thread. This is what C<ev_async>
3022C<ev_async> watchers do: as long as the C<ev_async> watcher is active, you 3024watchers do: as long as the C<ev_async> watcher is active, you can signal
3023can signal it by calling C<ev_async_send>, which is thread- and signal 3025it by calling C<ev_async_send>, which is thread- and signal safe.
3024safe.
3025 3026
3026This functionality is very similar to C<ev_signal> watchers, as signals, 3027This functionality is very similar to C<ev_signal> watchers, as signals,
3027too, are asynchronous in nature, and signals, too, will be compressed 3028too, are asynchronous in nature, and signals, too, will be compressed
3028(i.e. the number of callback invocations may be less than the number of 3029(i.e. the number of callback invocations may be less than the number of
3029C<ev_async_sent> calls). 3030C<ev_async_sent> calls).
3390Associates a different C<struct ev_loop> with this watcher. You can only 3391Associates a different C<struct ev_loop> with this watcher. You can only
3391do this when the watcher is inactive (and not pending either). 3392do this when the watcher is inactive (and not pending either).
3392 3393
3393=item w->set ([arguments]) 3394=item w->set ([arguments])
3394 3395
3395Basically the same as C<ev_TYPE_set>, with the same arguments. Must be 3396Basically the same as C<ev_TYPE_set>, with the same arguments. Either this
3396called at least once. Unlike the C counterpart, an active watcher gets 3397method or a suitable start method must be called at least once. Unlike the
3397automatically stopped and restarted when reconfiguring it with this 3398C counterpart, an active watcher gets automatically stopped and restarted
3398method. 3399when reconfiguring it with this method.
3399 3400
3400=item w->start () 3401=item w->start ()
3401 3402
3402Starts the watcher. Note that there is no C<loop> argument, as the 3403Starts the watcher. Note that there is no C<loop> argument, as the
3403constructor already stores the event loop. 3404constructor already stores the event loop.
3404 3405
3406=item w->start ([arguments])
3407
3408Instead of calling C<set> and C<start> methods separately, it is often
3409convenient to wrap them in one call. Uses the same type of arguments as
3410the configure C<set> method of the watcher.
3411
3405=item w->stop () 3412=item w->stop ()
3406 3413
3407Stops the watcher if it is active. Again, no C<loop> argument. 3414Stops the watcher if it is active. Again, no C<loop> argument.
3408 3415
3409=item w->again () (C<ev::timer>, C<ev::periodic> only) 3416=item w->again () (C<ev::timer>, C<ev::periodic> only)
3421 3428
3422=back 3429=back
3423 3430
3424=back 3431=back
3425 3432
3426Example: Define a class with an IO and idle watcher, start one of them in 3433Example: Define a class with two I/O and idle watchers, start the I/O
3427the constructor. 3434watchers in the constructor.
3428 3435
3429 class myclass 3436 class myclass
3430 { 3437 {
3431 ev::io io ; void io_cb (ev::io &w, int revents); 3438 ev::io io ; void io_cb (ev::io &w, int revents);
3439 ev::io2 io2 ; void io2_cb (ev::io &w, int revents);
3432 ev::idle idle; void idle_cb (ev::idle &w, int revents); 3440 ev::idle idle; void idle_cb (ev::idle &w, int revents);
3433 3441
3434 myclass (int fd) 3442 myclass (int fd)
3435 { 3443 {
3436 io .set <myclass, &myclass::io_cb > (this); 3444 io .set <myclass, &myclass::io_cb > (this);
3445 io2 .set <myclass, &myclass::io2_cb > (this);
3437 idle.set <myclass, &myclass::idle_cb> (this); 3446 idle.set <myclass, &myclass::idle_cb> (this);
3438 3447
3439 io.start (fd, ev::READ); 3448 io.set (fd, ev::WRITE); // configure the watcher
3449 io.start (); // start it whenever convenient
3450
3451 io2.start (fd, ev::READ); // set + start in one call
3440 } 3452 }
3441 }; 3453 };
3442 3454
3443 3455
3444=head1 OTHER LANGUAGE BINDINGS 3456=head1 OTHER LANGUAGE BINDINGS
4028The default is C<1>, unless C<EV_FEATURES> overrides it, in which case it 4040The default is C<1>, unless C<EV_FEATURES> overrides it, in which case it
4029will be C<0>. 4041will be C<0>.
4030 4042
4031=item EV_VERIFY 4043=item EV_VERIFY
4032 4044
4033Controls how much internal verification (see C<ev_loop_verify ()>) will 4045Controls how much internal verification (see C<ev_verify ()>) will
4034be done: If set to C<0>, no internal verification code will be compiled 4046be done: If set to C<0>, no internal verification code will be compiled
4035in. If set to C<1>, then verification code will be compiled in, but not 4047in. If set to C<1>, then verification code will be compiled in, but not
4036called. If set to C<2>, then the internal verification code will be 4048called. If set to C<2>, then the internal verification code will be
4037called once per loop, which can slow down libev. If set to C<3>, then the 4049called once per loop, which can slow down libev. If set to C<3>, then the
4038verification code will be called very frequently, which will slow down 4050verification code will be called very frequently, which will slow down
4042will be C<0>. 4054will be C<0>.
4043 4055
4044=item EV_COMMON 4056=item EV_COMMON
4045 4057
4046By default, all watchers have a C<void *data> member. By redefining 4058By default, all watchers have a C<void *data> member. By redefining
4047this macro to a something else you can include more and other types of 4059this macro to something else you can include more and other types of
4048members. You have to define it each time you include one of the files, 4060members. You have to define it each time you include one of the files,
4049though, and it must be identical each time. 4061though, and it must be identical each time.
4050 4062
4051For example, the perl EV module uses something like this: 4063For example, the perl EV module uses something like this:
4052 4064
4351maintainable. 4363maintainable.
4352 4364
4353And of course, some compiler warnings are just plain stupid, or simply 4365And of course, some compiler warnings are just plain stupid, or simply
4354wrong (because they don't actually warn about the condition their message 4366wrong (because they don't actually warn about the condition their message
4355seems to warn about). For example, certain older gcc versions had some 4367seems to warn about). For example, certain older gcc versions had some
4356warnings that resulted an extreme number of false positives. These have 4368warnings that resulted in an extreme number of false positives. These have
4357been fixed, but some people still insist on making code warn-free with 4369been fixed, but some people still insist on making code warn-free with
4358such buggy versions. 4370such buggy versions.
4359 4371
4360While libev is written to generate as few warnings as possible, 4372While libev is written to generate as few warnings as possible,
4361"warn-free" code is not a goal, and it is recommended not to build libev 4373"warn-free" code is not a goal, and it is recommended not to build libev
4397I suggest using suppression lists. 4409I suggest using suppression lists.
4398 4410
4399 4411
4400=head1 PORTABILITY NOTES 4412=head1 PORTABILITY NOTES
4401 4413
4414=head2 GNU/LINUX 32 BIT LIMITATIONS
4415
4416GNU/Linux is the only common platform that supports 64 bit file/large file
4417interfaces but I<disables> them by default.
4418
4419That means that libev compiled in the default environment doesn't support
4420files larger than 2GiB or so, which mainly affects C<ev_stat> watchers.
4421
4422Unfortunately, many programs try to work around this GNU/Linux issue
4423by enabling the large file API, which makes them incompatible with the
4424standard libev compiled for their system.
4425
4426Likewise, libev cannot enable the large file API itself as this would
4427suddenly make it incompatible to the default compile time environment,
4428i.e. all programs not using special compile switches.
4429
4430=head2 OS/X AND DARWIN BUGS
4431
4432The whole thing is a bug if you ask me - basically any system interface
4433you touch is broken, whether it is locales, poll, kqueue or even the
4434OpenGL drivers.
4435
4436=head3 C<kqueue> is buggy
4437
4438The kqueue syscall is broken in all known versions - most versions support
4439only sockets, many support pipes.
4440
4441Libev tries to work around this by not using C<kqueue> by default on
4442this rotten platform, but of course you can still ask for it when creating
4443a loop.
4444
4445=head3 C<poll> is buggy
4446
4447Instead of fixing C<kqueue>, Apple replaced their (working) C<poll>
4448implementation by something calling C<kqueue> internally around the 10.5.6
4449release, so now C<kqueue> I<and> C<poll> are broken.
4450
4451Libev tries to work around this by not using C<poll> by default on
4452this rotten platform, but of course you can still ask for it when creating
4453a loop.
4454
4455=head3 C<select> is buggy
4456
4457All that's left is C<select>, and of course Apple found a way to fuck this
4458one up as well: On OS/X, C<select> actively limits the number of file
4459descriptors you can pass in to 1024 - your program suddenly crashes when
4460you use more.
4461
4462There is an undocumented "workaround" for this - defining
4463C<_DARWIN_UNLIMITED_SELECT>, which libev tries to use, so select I<should>
4464work on OS/X.
4465
4466=head2 SOLARIS PROBLEMS AND WORKAROUNDS
4467
4468=head3 C<errno> reentrancy
4469
4470The default compile environment on Solaris is unfortunately so
4471thread-unsafe that you can't even use components/libraries compiled
4472without C<-D_REENTRANT> (as long as they use C<errno>), which, of course,
4473isn't defined by default.
4474
4475If you want to use libev in threaded environments you have to make sure
4476it's compiled with C<_REENTRANT> defined.
4477
4478=head3 Event port backend
4479
4480The scalable event interface for Solaris is called "event ports". Unfortunately,
4481this mechanism is very buggy. If you run into high CPU usage, your program
4482freezes or you get a large number of spurious wakeups, make sure you have
4483all the relevant and latest kernel patches applied. No, I don't know which
4484ones, but there are multiple ones.
4485
4486If you can't get it to work, you can try running the program by setting
4487the environment variable C<LIBEV_FLAGS=3> to only allow C<poll> and
4488C<select> backends.
4489
4490=head2 AIX POLL BUG
4491
4492AIX unfortunately has a broken C<poll.h> header. Libev works around
4493this by trying to avoid the poll backend altogether (i.e. it's not even
4494compiled in), which normally isn't a big problem as C<select> works fine
4495with large bitsets, and AIX is dead anyway.
4496
4402=head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS 4497=head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS
4498
4499=head3 General issues
4403 4500
4404Win32 doesn't support any of the standards (e.g. POSIX) that libev 4501Win32 doesn't support any of the standards (e.g. POSIX) that libev
4405requires, and its I/O model is fundamentally incompatible with the POSIX 4502requires, and its I/O model is fundamentally incompatible with the POSIX
4406model. Libev still offers limited functionality on this platform in 4503model. Libev still offers limited functionality on this platform in
4407the form of the C<EVBACKEND_SELECT> backend, and only supports socket 4504the form of the C<EVBACKEND_SELECT> backend, and only supports socket
4408descriptors. This only applies when using Win32 natively, not when using 4505descriptors. This only applies when using Win32 natively, not when using
4409e.g. cygwin. 4506e.g. cygwin. Actually, it only applies to the microsofts own compilers,
4507as every compielr comes with a slightly differently broken/incompatible
4508environment.
4410 4509
4411Lifting these limitations would basically require the full 4510Lifting these limitations would basically require the full
4412re-implementation of the I/O system. If you are into these kinds of 4511re-implementation of the I/O system. If you are into this kind of thing,
4413things, then note that glib does exactly that for you in a very portable 4512then note that glib does exactly that for you in a very portable way (note
4414way (note also that glib is the slowest event library known to man). 4513also that glib is the slowest event library known to man).
4415 4514
4416There is no supported compilation method available on windows except 4515There is no supported compilation method available on windows except
4417embedding it into other applications. 4516embedding it into other applications.
4418 4517
4419Sensible signal handling is officially unsupported by Microsoft - libev 4518Sensible signal handling is officially unsupported by Microsoft - libev
4447you do I<not> compile the F<ev.c> or any other embedded source files!): 4546you do I<not> compile the F<ev.c> or any other embedded source files!):
4448 4547
4449 #include "evwrap.h" 4548 #include "evwrap.h"
4450 #include "ev.c" 4549 #include "ev.c"
4451 4550
4452=over 4
4453
4454=item The winsocket select function 4551=head3 The winsocket C<select> function
4455 4552
4456The winsocket C<select> function doesn't follow POSIX in that it 4553The winsocket C<select> function doesn't follow POSIX in that it
4457requires socket I<handles> and not socket I<file descriptors> (it is 4554requires socket I<handles> and not socket I<file descriptors> (it is
4458also extremely buggy). This makes select very inefficient, and also 4555also extremely buggy). This makes select very inefficient, and also
4459requires a mapping from file descriptors to socket handles (the Microsoft 4556requires a mapping from file descriptors to socket handles (the Microsoft
4468 #define EV_SELECT_IS_WINSOCKET 1 /* forces EV_SELECT_USE_FD_SET, too */ 4565 #define EV_SELECT_IS_WINSOCKET 1 /* forces EV_SELECT_USE_FD_SET, too */
4469 4566
4470Note that winsockets handling of fd sets is O(n), so you can easily get a 4567Note that winsockets handling of fd sets is O(n), so you can easily get a
4471complexity in the O(n²) range when using win32. 4568complexity in the O(n²) range when using win32.
4472 4569
4473=item Limited number of file descriptors 4570=head3 Limited number of file descriptors
4474 4571
4475Windows has numerous arbitrary (and low) limits on things. 4572Windows has numerous arbitrary (and low) limits on things.
4476 4573
4477Early versions of winsocket's select only supported waiting for a maximum 4574Early versions of winsocket's select only supported waiting for a maximum
4478of C<64> handles (probably owning to the fact that all windows kernels 4575of C<64> handles (probably owning to the fact that all windows kernels
4493runtime libraries. This might get you to about C<512> or C<2048> sockets 4590runtime libraries. This might get you to about C<512> or C<2048> sockets
4494(depending on windows version and/or the phase of the moon). To get more, 4591(depending on windows version and/or the phase of the moon). To get more,
4495you need to wrap all I/O functions and provide your own fd management, but 4592you need to wrap all I/O functions and provide your own fd management, but
4496the cost of calling select (O(n²)) will likely make this unworkable. 4593the cost of calling select (O(n²)) will likely make this unworkable.
4497 4594
4498=back
4499
4500=head2 PORTABILITY REQUIREMENTS 4595=head2 PORTABILITY REQUIREMENTS
4501 4596
4502In addition to a working ISO-C implementation and of course the 4597In addition to a working ISO-C implementation and of course the
4503backend-specific APIs, libev relies on a few additional extensions: 4598backend-specific APIs, libev relies on a few additional extensions:
4504 4599
4542watchers. 4637watchers.
4543 4638
4544=item C<double> must hold a time value in seconds with enough accuracy 4639=item C<double> must hold a time value in seconds with enough accuracy
4545 4640
4546The type C<double> is used to represent timestamps. It is required to 4641The type C<double> is used to represent timestamps. It is required to
4547have at least 51 bits of mantissa (and 9 bits of exponent), which is good 4642have at least 51 bits of mantissa (and 9 bits of exponent), which is
4548enough for at least into the year 4000. This requirement is fulfilled by 4643good enough for at least into the year 4000 with millisecond accuracy
4644(the design goal for libev). This requirement is overfulfilled by
4549implementations implementing IEEE 754, which is basically all existing 4645implementations using IEEE 754, which is basically all existing ones. With
4550ones. With IEEE 754 doubles, you get microsecond accuracy until at least 4646IEEE 754 doubles, you get microsecond accuracy until at least 2200.
45512200.
4552 4647
4553=back 4648=back
4554 4649
4555If you know of other additional requirements drop me a note. 4650If you know of other additional requirements drop me a note.
4556 4651

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines