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

Comparing libev/ev.pod (file contents):
Revision 1.298 by sf-exg, Sat Jul 31 23:00:11 2010 UTC vs.
Revision 1.304 by root, Thu Oct 14 04:30:46 2010 UTC

2123Example: Call a callback every hour, or, more precisely, whenever the 2123Example: Call a callback every hour, or, more precisely, whenever the
2124system time is divisible by 3600. The callback invocation times have 2124system time is divisible by 3600. The callback invocation times have
2125potentially a lot of jitter, but good long-term stability. 2125potentially a lot of jitter, but good long-term stability.
2126 2126
2127 static void 2127 static void
2128 clock_cb (struct ev_loop *loop, ev_io *w, int revents) 2128 clock_cb (struct ev_loop *loop, ev_periodic *w, int revents)
2129 { 2129 {
2130 ... its now a full hour (UTC, or TAI or whatever your clock follows) 2130 ... its now a full hour (UTC, or TAI or whatever your clock follows)
2131 } 2131 }
2132 2132
2133 ev_periodic hourly_tick; 2133 ev_periodic hourly_tick;
2965C<ev_default_fork> cheats and calls it in the wrong process, the fork 2965C<ev_default_fork> cheats and calls it in the wrong process, the fork
2966handlers will be invoked, too, of course. 2966handlers will be invoked, too, of course.
2967 2967
2968=head3 The special problem of life after fork - how is it possible? 2968=head3 The special problem of life after fork - how is it possible?
2969 2969
2970Most uses of C<fork()> consist of forking, then some simple calls to ste 2970Most 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 2971up/change the process environment, followed by a call to C<exec()>. This
2972sequence should be handled by libev without any problems. 2972sequence should be handled by libev without any problems.
2973 2973
2974This changes when the application actually wants to do event handling 2974This changes when the application actually wants to do event handling
2975in the child, or both parent in child, in effect "continuing" after the 2975in the child, or both parent in child, in effect "continuing" after the
3009believe me. 3009believe me.
3010 3010
3011=back 3011=back
3012 3012
3013 3013
3014=head2 C<ev_async> - how to wake up another event loop 3014=head2 C<ev_async> - how to wake up an event loop
3015 3015
3016In general, you cannot use an C<ev_loop> from multiple threads or other 3016In general, you cannot use an C<ev_loop> from multiple threads or other
3017asynchronous sources such as signal handlers (as opposed to multiple event 3017asynchronous sources such as signal handlers (as opposed to multiple event
3018loops - those are of course safe to use in different threads). 3018loops - those are of course safe to use in different threads).
3019 3019
3020Sometimes, however, you need to wake up another event loop you do not 3020Sometimes, 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 3021for 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 3022watchers 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 3023it by calling C<ev_async_send>, which is thread- and signal safe.
3024safe.
3025 3024
3026This functionality is very similar to C<ev_signal> watchers, as signals, 3025This functionality is very similar to C<ev_signal> watchers, as signals,
3027too, are asynchronous in nature, and signals, too, will be compressed 3026too, 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 3027(i.e. the number of callback invocations may be less than the number of
3029C<ev_async_sent> calls). 3028C<ev_async_sent> calls).
3885EV_PREPARE_ENABLE, EV_CHECK_ENABLE, EV_FORK_ENABLE, EV_SIGNAL_ENABLE, 3884EV_PREPARE_ENABLE, EV_CHECK_ENABLE, EV_FORK_ENABLE, EV_SIGNAL_ENABLE,
3886EV_ASYNC_ENABLE, EV_CHILD_ENABLE. 3885EV_ASYNC_ENABLE, EV_CHILD_ENABLE.
3887 3886
3888If undefined or defined to be C<1> (and the platform supports it), then 3887If undefined or defined to be C<1> (and the platform supports it), then
3889the respective watcher type is supported. If defined to be C<0>, then it 3888the respective watcher type is supported. If defined to be C<0>, then it
3890is not. Disabling watcher types mainly saves codesize. 3889is not. Disabling watcher types mainly saves code size.
3891 3890
3892=item EV_FEATURES 3891=item EV_FEATURES
3893 3892
3894If you need to shave off some kilobytes of code at the expense of some 3893If you need to shave off some kilobytes of code at the expense of some
3895speed (but with the full API), you can define this symbol to request 3894speed (but with the full API), you can define this symbol to request
3915 3914
3916=item C<1> - faster/larger code 3915=item C<1> - faster/larger code
3917 3916
3918Use larger code to speed up some operations. 3917Use larger code to speed up some operations.
3919 3918
3920Currently this is used to override some inlining decisions (enlarging the roughly 3919Currently this is used to override some inlining decisions (enlarging the
392130% code size on amd64. 3920code size by roughly 30% on amd64).
3922 3921
3923When optimising for size, use of compiler flags such as C<-Os> with 3922When optimising for size, use of compiler flags such as C<-Os> with
3924gcc recommended, as well as C<-DNDEBUG>, as libev contains a number of 3923gcc is recommended, as well as C<-DNDEBUG>, as libev contains a number of
3925assertions. 3924assertions.
3926 3925
3927=item C<2> - faster/larger data structures 3926=item C<2> - faster/larger data structures
3928 3927
3929Replaces the small 2-heap for timer management by a faster 4-heap, larger 3928Replaces the small 2-heap for timer management by a faster 4-heap, larger
3930hash table sizes and so on. This will usually further increase codesize 3929hash table sizes and so on. This will usually further increase code size
3931and can additionally have an effect on the size of data structures at 3930and can additionally have an effect on the size of data structures at
3932runtime. 3931runtime.
3933 3932
3934=item C<4> - full API configuration 3933=item C<4> - full API configuration
3935 3934
3972I/O watcher then might come out at only 5Kb. 3971I/O watcher then might come out at only 5Kb.
3973 3972
3974=item EV_AVOID_STDIO 3973=item EV_AVOID_STDIO
3975 3974
3976If this is set to C<1> at compiletime, then libev will avoid using stdio 3975If this is set to C<1> at compiletime, then libev will avoid using stdio
3977functions (printf, scanf, perror etc.). This will increase the codesize 3976functions (printf, scanf, perror etc.). This will increase the code size
3978somewhat, but if your program doesn't otherwise depend on stdio and your 3977somewhat, but if your program doesn't otherwise depend on stdio and your
3979libc allows it, this avoids linking in the stdio library which is quite 3978libc allows it, this avoids linking in the stdio library which is quite
3980big. 3979big.
3981 3980
3982Note that error messages might become less precise when this option is 3981Note that error messages might become less precise when this option is
4042will be C<0>. 4041will be C<0>.
4043 4042
4044=item EV_COMMON 4043=item EV_COMMON
4045 4044
4046By default, all watchers have a C<void *data> member. By redefining 4045By 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 4046this 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, 4047members. You have to define it each time you include one of the files,
4049though, and it must be identical each time. 4048though, and it must be identical each time.
4050 4049
4051For example, the perl EV module uses something like this: 4050For example, the perl EV module uses something like this:
4052 4051
4351maintainable. 4350maintainable.
4352 4351
4353And of course, some compiler warnings are just plain stupid, or simply 4352And of course, some compiler warnings are just plain stupid, or simply
4354wrong (because they don't actually warn about the condition their message 4353wrong (because they don't actually warn about the condition their message
4355seems to warn about). For example, certain older gcc versions had some 4354seems to warn about). For example, certain older gcc versions had some
4356warnings that resulted an extreme number of false positives. These have 4355warnings that resulted in an extreme number of false positives. These have
4357been fixed, but some people still insist on making code warn-free with 4356been fixed, but some people still insist on making code warn-free with
4358such buggy versions. 4357such buggy versions.
4359 4358
4360While libev is written to generate as few warnings as possible, 4359While 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 4360"warn-free" code is not a goal, and it is recommended not to build libev
4397I suggest using suppression lists. 4396I suggest using suppression lists.
4398 4397
4399 4398
4400=head1 PORTABILITY NOTES 4399=head1 PORTABILITY NOTES
4401 4400
4401=head2 GNU/LINUX 32 BIT LIMITATIONS
4402
4403GNU/Linux is the only common platform that supports 64 bit file/large file
4404interfaces but I<disables> them by default.
4405
4406That means that libev compiled in the default environment doesn't support
4407files larger than 2GiB or so, which mainly affects C<ev_stat> watchers.
4408
4409Unfortunately, many programs try to work around this GNU/Linux issue
4410by enabling the large file API, which makes them incompatible with the
4411standard libev compiled for their system.
4412
4413Likewise, libev cannot enable the large file API itself as this would
4414suddenly make it incompatible to the default compile time environment,
4415i.e. all programs not using special compile switches.
4416
4417=head2 OS/X AND DARWIN BUGS
4418
4419The whole thing is a bug if you ask me - basically any system interface
4420you touch is broken, whether it is locales, poll, kqueue or even the
4421OpenGL drivers.
4422
4423=head3 C<kqueue> is buggy
4424
4425The kqueue syscall is broken in all known versions - most versions support
4426only sockets, many support pipes.
4427
4428Libev tries to work around this by not using C<kqueue> by default on
4429this rotten platform, but of course you can still ask for it when creating
4430a loop.
4431
4432=head3 C<poll> is buggy
4433
4434Instead of fixing C<kqueue>, Apple replaced their (working) C<poll>
4435implementation by something calling C<kqueue> internally around the 10.5.6
4436release, so now C<kqueue> I<and> C<poll> are broken.
4437
4438Libev tries to work around this by not using C<poll> by default on
4439this rotten platform, but of course you can still ask for it when creating
4440a loop.
4441
4442=head3 C<select> is buggy
4443
4444All that's left is C<select>, and of course Apple found a way to fuck this
4445one up as well: On OS/X, C<select> actively limits the number of file
4446descriptors you can pass in to 1024 - your program suddenyl crashes when
4447you use more.
4448
4449There is an undocumented "workaround" for this - defining
4450C<_DARWIN_UNLIMITED_SELECT>, which libev tries to use, so select I<should>
4451work on OS/X.
4452
4453=head2 SOLARIS PROBLEMS AND WORKAROUNDS
4454
4455=head3 C<errno> reentrancy
4456
4457The default compile environment on Solaris is unfortunately so
4458thread-unsafe that you can't even use components/libraries compiled
4459without C<-D_REENTRANT> (as long as they use C<errno>), which, of course,
4460isn't defined by default.
4461
4462If you want to use libev in threaded environments you have to make sure
4463it's compiled with C<_REENTRANT> defined.
4464
4465=head3 Event port backend
4466
4467The scalable event interface for Solaris is called "event ports". Unfortunately,
4468this mechanism is very buggy. If you run into high CPU usage, your program
4469freezes or you get a large number of spurious wakeups, make sure you have
4470all the relevant and latest kernel patches applied. No, I don't know which
4471ones, but there are multiple ones.
4472
4473If you can't get it to work, you can try running the program with
4474C<LIBEV_FLAGS=3> to only allow C<poll> and C<select> backends.
4475
4476=head2 AIX POLL BUG
4477
4478AIX unfortunately has a broken C<poll.h> header. Libev works around
4479this by trying to avoid the poll backend altogether (i.e. it's not even
4480compiled in), which normally isn't a big problem as C<select> works fine
4481with large bitsets, and AIX is dead anyway.
4482
4402=head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS 4483=head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS
4484
4485=head3 General issues
4403 4486
4404Win32 doesn't support any of the standards (e.g. POSIX) that libev 4487Win32 doesn't support any of the standards (e.g. POSIX) that libev
4405requires, and its I/O model is fundamentally incompatible with the POSIX 4488requires, and its I/O model is fundamentally incompatible with the POSIX
4406model. Libev still offers limited functionality on this platform in 4489model. Libev still offers limited functionality on this platform in
4407the form of the C<EVBACKEND_SELECT> backend, and only supports socket 4490the form of the C<EVBACKEND_SELECT> backend, and only supports socket
4408descriptors. This only applies when using Win32 natively, not when using 4491descriptors. This only applies when using Win32 natively, not when using
4409e.g. cygwin. 4492e.g. cygwin. Actually, it only applies to the microsofts own compilers,
4493as every compielr comes with a slightly differently broken/incompatible
4494environment.
4410 4495
4411Lifting these limitations would basically require the full 4496Lifting these limitations would basically require the full
4412re-implementation of the I/O system. If you are into these kinds of 4497re-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 4498then 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). 4499also that glib is the slowest event library known to man).
4415 4500
4416There is no supported compilation method available on windows except 4501There is no supported compilation method available on windows except
4417embedding it into other applications. 4502embedding it into other applications.
4418 4503
4419Sensible signal handling is officially unsupported by Microsoft - libev 4504Sensible signal handling is officially unsupported by Microsoft - libev
4447you do I<not> compile the F<ev.c> or any other embedded source files!): 4532you do I<not> compile the F<ev.c> or any other embedded source files!):
4448 4533
4449 #include "evwrap.h" 4534 #include "evwrap.h"
4450 #include "ev.c" 4535 #include "ev.c"
4451 4536
4452=over 4
4453
4454=item The winsocket select function 4537=head3 The winsocket C<select> function
4455 4538
4456The winsocket C<select> function doesn't follow POSIX in that it 4539The winsocket C<select> function doesn't follow POSIX in that it
4457requires socket I<handles> and not socket I<file descriptors> (it is 4540requires socket I<handles> and not socket I<file descriptors> (it is
4458also extremely buggy). This makes select very inefficient, and also 4541also extremely buggy). This makes select very inefficient, and also
4459requires a mapping from file descriptors to socket handles (the Microsoft 4542requires a mapping from file descriptors to socket handles (the Microsoft
4468 #define EV_SELECT_IS_WINSOCKET 1 /* forces EV_SELECT_USE_FD_SET, too */ 4551 #define EV_SELECT_IS_WINSOCKET 1 /* forces EV_SELECT_USE_FD_SET, too */
4469 4552
4470Note that winsockets handling of fd sets is O(n), so you can easily get a 4553Note that winsockets handling of fd sets is O(n), so you can easily get a
4471complexity in the O(n²) range when using win32. 4554complexity in the O(n²) range when using win32.
4472 4555
4473=item Limited number of file descriptors 4556=head3 Limited number of file descriptors
4474 4557
4475Windows has numerous arbitrary (and low) limits on things. 4558Windows has numerous arbitrary (and low) limits on things.
4476 4559
4477Early versions of winsocket's select only supported waiting for a maximum 4560Early versions of winsocket's select only supported waiting for a maximum
4478of C<64> handles (probably owning to the fact that all windows kernels 4561of 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 4576runtime 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, 4577(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 4578you 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. 4579the cost of calling select (O(n²)) will likely make this unworkable.
4497 4580
4498=back
4499
4500=head2 PORTABILITY REQUIREMENTS 4581=head2 PORTABILITY REQUIREMENTS
4501 4582
4502In addition to a working ISO-C implementation and of course the 4583In addition to a working ISO-C implementation and of course the
4503backend-specific APIs, libev relies on a few additional extensions: 4584backend-specific APIs, libev relies on a few additional extensions:
4504 4585

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines