ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/README
(Generate patch)

Comparing AnyEvent/README (file contents):
Revision 1.56 by root, Thu Nov 19 01:55:57 2009 UTC vs.
Revision 1.58 by root, Sun Dec 20 22:49:52 2009 UTC

391 correctly. 391 correctly.
392 392
393 Example: exit on SIGINT 393 Example: exit on SIGINT
394 394
395 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 }); 395 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 });
396
397 Restart Behaviour
398 While restart behaviour is up to the event loop implementation, most
399 will not restart syscalls (that includes Async::Interrupt and AnyEvent's
400 pure perl implementation).
401
402 Safe/Unsafe Signals
403 Perl signals can be either "safe" (synchronous to opcode handling) or
404 "unsafe" (asynchronous) - the former might get delayed indefinitely, the
405 latter might corrupt your memory.
406
407 AnyEvent signal handlers are, in addition, synchronous to the event
408 loop, i.e. they will not interrupt your running perl program but will
409 only be called as part of the normal event handling (just like timer,
410 I/O etc. callbacks, too).
396 411
397 Signal Races, Delays and Workarounds 412 Signal Races, Delays and Workarounds
398 Many event loops (e.g. Glib, Tk, Qt, IO::Async) do not support attaching 413 Many event loops (e.g. Glib, Tk, Qt, IO::Async) do not support attaching
399 callbacks to signals in a generic way, which is a pity, as you cannot do 414 callbacks to signals in a generic way, which is a pity, as you cannot do
400 race-free signal handling in perl, requiring C libraries for this. 415 race-free signal handling in perl, requiring C libraries for this.
904 You should check $AnyEvent::MODEL before adding to this array, 919 You should check $AnyEvent::MODEL before adding to this array,
905 though: if it is defined then the event loop has already been 920 though: if it is defined then the event loop has already been
906 detected, and the array will be ignored. 921 detected, and the array will be ignored.
907 922
908 Best use "AnyEvent::post_detect { BLOCK }" when your application 923 Best use "AnyEvent::post_detect { BLOCK }" when your application
909 allows it,as it takes care of these details. 924 allows it, as it takes care of these details.
910 925
911 This variable is mainly useful for modules that can do something 926 This variable is mainly useful for modules that can do something
912 useful when AnyEvent is used and thus want to know when it is 927 useful when AnyEvent is used and thus want to know when it is
913 initialised, but do not need to even load it by default. This array 928 initialised, but do not need to even load it by default. This array
914 provides the means to hook into AnyEvent passively, without loading 929 provides the means to hook into AnyEvent passively, without loading
915 it. 930 it.
931
932 Example: To load Coro::AnyEvent whenever Coro and AnyEvent are used
933 together, you could put this into Coro (this is the actual code used
934 by Coro to accomplish this):
935
936 if (defined $AnyEvent::MODEL) {
937 # AnyEvent already initialised, so load Coro::AnyEvent
938 require Coro::AnyEvent;
939 } else {
940 # AnyEvent not yet initialised, so make sure to load Coro::AnyEvent
941 # as soon as it is
942 push @AnyEvent::post_detect, sub { require Coro::AnyEvent };
943 }
916 944
917WHAT TO DO IN A MODULE 945WHAT TO DO IN A MODULE
918 As a module author, you should "use AnyEvent" and call AnyEvent methods 946 As a module author, you should "use AnyEvent" and call AnyEvent methods
919 freely, but you should not load a specific event module or rely on it. 947 freely, but you should not load a specific event module or rely on it.
920 948
1709 it's built-in modules) are required to use it. 1737 it's built-in modules) are required to use it.
1710 1738
1711 That does not mean that AnyEvent won't take advantage of some additional 1739 That does not mean that AnyEvent won't take advantage of some additional
1712 modules if they are installed. 1740 modules if they are installed.
1713 1741
1714 This section epxlains which additional modules will be used, and how 1742 This section explains which additional modules will be used, and how
1715 they affect AnyEvent's operetion. 1743 they affect AnyEvent's operation.
1716 1744
1717 Async::Interrupt 1745 Async::Interrupt
1718 This slightly arcane module is used to implement fast signal 1746 This slightly arcane module is used to implement fast signal
1719 handling: To my knowledge, there is no way to do completely 1747 handling: To my knowledge, there is no way to do completely
1720 race-free and quick signal handling in pure perl. To ensure that 1748 race-free and quick signal handling in pure perl. To ensure that
1723 10 seconds, look for $AnyEvent::MAX_SIGNAL_LATENCY). 1751 10 seconds, look for $AnyEvent::MAX_SIGNAL_LATENCY).
1724 1752
1725 If this module is available, then it will be used to implement 1753 If this module is available, then it will be used to implement
1726 signal catching, which means that signals will not be delayed, and 1754 signal catching, which means that signals will not be delayed, and
1727 the event loop will not be interrupted regularly, which is more 1755 the event loop will not be interrupted regularly, which is more
1728 efficient (And good for battery life on laptops). 1756 efficient (and good for battery life on laptops).
1729 1757
1730 This affects not just the pure-perl event loop, but also other event 1758 This affects not just the pure-perl event loop, but also other event
1731 loops that have no signal handling on their own (e.g. Glib, Tk, Qt). 1759 loops that have no signal handling on their own (e.g. Glib, Tk, Qt).
1732 1760
1733 Some event loops (POE, Event, Event::Lib) offer signal watchers 1761 Some event loops (POE, Event, Event::Lib) offer signal watchers
1775FORK 1803FORK
1776 Most event libraries are not fork-safe. The ones who are usually are 1804 Most event libraries are not fork-safe. The ones who are usually are
1777 because they rely on inefficient but fork-safe "select" or "poll" calls. 1805 because they rely on inefficient but fork-safe "select" or "poll" calls.
1778 Only EV is fully fork-aware. 1806 Only EV is fully fork-aware.
1779 1807
1808 This means that, in general, you cannot fork and do event processing in
1809 the child if a watcher was created before the fork (which in turn
1810 initialises the event library).
1811
1780 If you have to fork, you must either do so *before* creating your first 1812 If you have to fork, you must either do so *before* creating your first
1781 watcher OR you must not use AnyEvent at all in the child OR you must do 1813 watcher OR you must not use AnyEvent at all in the child OR you must do
1782 something completely out of the scope of AnyEvent. 1814 something completely out of the scope of AnyEvent.
1815
1816 The problem of doing event processing in the parent *and* the child is
1817 much more complicated: even for backends that *are* fork-aware or
1818 fork-safe, their behaviour is not usually what you want: fork clones all
1819 watchers, that means all timers, I/O watchers etc. are active in both
1820 parent and child, which is almost never what you want.
1783 1821
1784SECURITY CONSIDERATIONS 1822SECURITY CONSIDERATIONS
1785 AnyEvent can be forced to load any event model via 1823 AnyEvent can be forced to load any event model via
1786 $ENV{PERL_ANYEVENT_MODEL}. While this cannot (to my knowledge) be used 1824 $ENV{PERL_ANYEVENT_MODEL}. While this cannot (to my knowledge) be used
1787 to execute arbitrary code or directly gain access, it can easily be used 1825 to execute arbitrary code or directly gain access, it can easily be used

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines