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

Comparing libev/ev.pod (file contents):
Revision 1.300 by sf-exg, Sun Aug 29 16:13:12 2010 UTC vs.
Revision 1.306 by root, Mon Oct 18 07:36:05 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
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).
4397I suggest using suppression lists. 4398I suggest using suppression lists.
4398 4399
4399 4400
4400=head1 PORTABILITY NOTES 4401=head1 PORTABILITY NOTES
4401 4402
4403=head2 GNU/LINUX 32 BIT LIMITATIONS
4404
4405GNU/Linux is the only common platform that supports 64 bit file/large file
4406interfaces but I<disables> them by default.
4407
4408That means that libev compiled in the default environment doesn't support
4409files larger than 2GiB or so, which mainly affects C<ev_stat> watchers.
4410
4411Unfortunately, many programs try to work around this GNU/Linux issue
4412by enabling the large file API, which makes them incompatible with the
4413standard libev compiled for their system.
4414
4415Likewise, libev cannot enable the large file API itself as this would
4416suddenly make it incompatible to the default compile time environment,
4417i.e. all programs not using special compile switches.
4418
4419=head2 OS/X AND DARWIN BUGS
4420
4421The whole thing is a bug if you ask me - basically any system interface
4422you touch is broken, whether it is locales, poll, kqueue or even the
4423OpenGL drivers.
4424
4425=head3 C<kqueue> is buggy
4426
4427The kqueue syscall is broken in all known versions - most versions support
4428only sockets, many support pipes.
4429
4430Libev tries to work around this by not using C<kqueue> by default on
4431this rotten platform, but of course you can still ask for it when creating
4432a loop.
4433
4434=head3 C<poll> is buggy
4435
4436Instead of fixing C<kqueue>, Apple replaced their (working) C<poll>
4437implementation by something calling C<kqueue> internally around the 10.5.6
4438release, so now C<kqueue> I<and> C<poll> are broken.
4439
4440Libev tries to work around this by not using C<poll> by default on
4441this rotten platform, but of course you can still ask for it when creating
4442a loop.
4443
4444=head3 C<select> is buggy
4445
4446All that's left is C<select>, and of course Apple found a way to fuck this
4447one up as well: On OS/X, C<select> actively limits the number of file
4448descriptors you can pass in to 1024 - your program suddenly crashes when
4449you use more.
4450
4451There is an undocumented "workaround" for this - defining
4452C<_DARWIN_UNLIMITED_SELECT>, which libev tries to use, so select I<should>
4453work on OS/X.
4454
4455=head2 SOLARIS PROBLEMS AND WORKAROUNDS
4456
4457=head3 C<errno> reentrancy
4458
4459The default compile environment on Solaris is unfortunately so
4460thread-unsafe that you can't even use components/libraries compiled
4461without C<-D_REENTRANT> (as long as they use C<errno>), which, of course,
4462isn't defined by default.
4463
4464If you want to use libev in threaded environments you have to make sure
4465it's compiled with C<_REENTRANT> defined.
4466
4467=head3 Event port backend
4468
4469The scalable event interface for Solaris is called "event ports". Unfortunately,
4470this mechanism is very buggy. If you run into high CPU usage, your program
4471freezes or you get a large number of spurious wakeups, make sure you have
4472all the relevant and latest kernel patches applied. No, I don't know which
4473ones, but there are multiple ones.
4474
4475If you can't get it to work, you can try running the program by setting
4476the environment variable C<LIBEV_FLAGS=3> to only allow C<poll> and
4477C<select> backends.
4478
4479=head2 AIX POLL BUG
4480
4481AIX unfortunately has a broken C<poll.h> header. Libev works around
4482this by trying to avoid the poll backend altogether (i.e. it's not even
4483compiled in), which normally isn't a big problem as C<select> works fine
4484with large bitsets, and AIX is dead anyway.
4485
4402=head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS 4486=head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS
4487
4488=head3 General issues
4403 4489
4404Win32 doesn't support any of the standards (e.g. POSIX) that libev 4490Win32 doesn't support any of the standards (e.g. POSIX) that libev
4405requires, and its I/O model is fundamentally incompatible with the POSIX 4491requires, and its I/O model is fundamentally incompatible with the POSIX
4406model. Libev still offers limited functionality on this platform in 4492model. Libev still offers limited functionality on this platform in
4407the form of the C<EVBACKEND_SELECT> backend, and only supports socket 4493the form of the C<EVBACKEND_SELECT> backend, and only supports socket
4408descriptors. This only applies when using Win32 natively, not when using 4494descriptors. This only applies when using Win32 natively, not when using
4409e.g. cygwin. 4495e.g. cygwin. Actually, it only applies to the microsofts own compilers,
4496as every compielr comes with a slightly differently broken/incompatible
4497environment.
4410 4498
4411Lifting these limitations would basically require the full 4499Lifting these limitations would basically require the full
4412re-implementation of the I/O system. If you are into these kinds of 4500re-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 4501then 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). 4502also that glib is the slowest event library known to man).
4415 4503
4416There is no supported compilation method available on windows except 4504There is no supported compilation method available on windows except
4417embedding it into other applications. 4505embedding it into other applications.
4418 4506
4419Sensible signal handling is officially unsupported by Microsoft - libev 4507Sensible signal handling is officially unsupported by Microsoft - libev
4447you do I<not> compile the F<ev.c> or any other embedded source files!): 4535you do I<not> compile the F<ev.c> or any other embedded source files!):
4448 4536
4449 #include "evwrap.h" 4537 #include "evwrap.h"
4450 #include "ev.c" 4538 #include "ev.c"
4451 4539
4452=over 4
4453
4454=item The winsocket select function 4540=head3 The winsocket C<select> function
4455 4541
4456The winsocket C<select> function doesn't follow POSIX in that it 4542The winsocket C<select> function doesn't follow POSIX in that it
4457requires socket I<handles> and not socket I<file descriptors> (it is 4543requires socket I<handles> and not socket I<file descriptors> (it is
4458also extremely buggy). This makes select very inefficient, and also 4544also extremely buggy). This makes select very inefficient, and also
4459requires a mapping from file descriptors to socket handles (the Microsoft 4545requires a mapping from file descriptors to socket handles (the Microsoft
4468 #define EV_SELECT_IS_WINSOCKET 1 /* forces EV_SELECT_USE_FD_SET, too */ 4554 #define EV_SELECT_IS_WINSOCKET 1 /* forces EV_SELECT_USE_FD_SET, too */
4469 4555
4470Note that winsockets handling of fd sets is O(n), so you can easily get a 4556Note that winsockets handling of fd sets is O(n), so you can easily get a
4471complexity in the O(n²) range when using win32. 4557complexity in the O(n²) range when using win32.
4472 4558
4473=item Limited number of file descriptors 4559=head3 Limited number of file descriptors
4474 4560
4475Windows has numerous arbitrary (and low) limits on things. 4561Windows has numerous arbitrary (and low) limits on things.
4476 4562
4477Early versions of winsocket's select only supported waiting for a maximum 4563Early versions of winsocket's select only supported waiting for a maximum
4478of C<64> handles (probably owning to the fact that all windows kernels 4564of 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 4579runtime 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, 4580(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 4581you 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. 4582the cost of calling select (O(n²)) will likely make this unworkable.
4497 4583
4498=back
4499
4500=head2 PORTABILITY REQUIREMENTS 4584=head2 PORTABILITY REQUIREMENTS
4501 4585
4502In addition to a working ISO-C implementation and of course the 4586In addition to a working ISO-C implementation and of course the
4503backend-specific APIs, libev relies on a few additional extensions: 4587backend-specific APIs, libev relies on a few additional extensions:
4504 4588

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines