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

Comparing AnyEvent/README (file contents):
Revision 1.55 by root, Mon Sep 14 05:05:09 2009 UTC vs.
Revision 1.57 by root, Sat Dec 5 02:52:03 2009 UTC

354 time, which might affect timers and time-outs. 354 time, which might affect timers and time-outs.
355 355
356 When this is the case, you can call this method, which will update 356 When this is the case, you can call this method, which will update
357 the event loop's idea of "current time". 357 the event loop's idea of "current time".
358 358
359 A typical example would be a script in a web server (e.g.
360 "mod_perl") - when mod_perl executes the script, then the event loop
361 will have the wrong idea about the "current time" (being potentially
362 far in the past, when the script ran the last time). In that case
363 you should arrange a call to "AnyEvent->now_update" each time the
364 web server process wakes up again (e.g. at the start of your script,
365 or in a handler).
366
359 Note that updating the time *might* cause some events to be handled. 367 Note that updating the time *might* cause some events to be handled.
360 368
361 SIGNAL WATCHERS 369 SIGNAL WATCHERS
362 $w = AnyEvent->signal (signal => <uppercase_signal_name>, cb => <callback>); 370 $w = AnyEvent->signal (signal => <uppercase_signal_name>, cb => <callback>);
363 371
383 correctly. 391 correctly.
384 392
385 Example: exit on SIGINT 393 Example: exit on SIGINT
386 394
387 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).
388 411
389 Signal Races, Delays and Workarounds 412 Signal Races, Delays and Workarounds
390 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
391 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
392 race-free signal handling in perl, requiring C libraries for this. 415 race-free signal handling in perl, requiring C libraries for this.
1701 it's built-in modules) are required to use it. 1724 it's built-in modules) are required to use it.
1702 1725
1703 That does not mean that AnyEvent won't take advantage of some additional 1726 That does not mean that AnyEvent won't take advantage of some additional
1704 modules if they are installed. 1727 modules if they are installed.
1705 1728
1706 This section epxlains which additional modules will be used, and how 1729 This section explains which additional modules will be used, and how
1707 they affect AnyEvent's operetion. 1730 they affect AnyEvent's operation.
1708 1731
1709 Async::Interrupt 1732 Async::Interrupt
1710 This slightly arcane module is used to implement fast signal 1733 This slightly arcane module is used to implement fast signal
1711 handling: To my knowledge, there is no way to do completely 1734 handling: To my knowledge, there is no way to do completely
1712 race-free and quick signal handling in pure perl. To ensure that 1735 race-free and quick signal handling in pure perl. To ensure that
1715 10 seconds, look for $AnyEvent::MAX_SIGNAL_LATENCY). 1738 10 seconds, look for $AnyEvent::MAX_SIGNAL_LATENCY).
1716 1739
1717 If this module is available, then it will be used to implement 1740 If this module is available, then it will be used to implement
1718 signal catching, which means that signals will not be delayed, and 1741 signal catching, which means that signals will not be delayed, and
1719 the event loop will not be interrupted regularly, which is more 1742 the event loop will not be interrupted regularly, which is more
1720 efficient (And good for battery life on laptops). 1743 efficient (and good for battery life on laptops).
1721 1744
1722 This affects not just the pure-perl event loop, but also other event 1745 This affects not just the pure-perl event loop, but also other event
1723 loops that have no signal handling on their own (e.g. Glib, Tk, Qt). 1746 loops that have no signal handling on their own (e.g. Glib, Tk, Qt).
1724 1747
1725 Some event loops (POE, Event, Event::Lib) offer signal watchers 1748 Some event loops (POE, Event, Event::Lib) offer signal watchers
1767FORK 1790FORK
1768 Most event libraries are not fork-safe. The ones who are usually are 1791 Most event libraries are not fork-safe. The ones who are usually are
1769 because they rely on inefficient but fork-safe "select" or "poll" calls. 1792 because they rely on inefficient but fork-safe "select" or "poll" calls.
1770 Only EV is fully fork-aware. 1793 Only EV is fully fork-aware.
1771 1794
1795 This means that, in general, you cannot fork and do event processing in
1796 the child if a watcher was created before the fork (which in turn
1797 initialises the event library).
1798
1772 If you have to fork, you must either do so *before* creating your first 1799 If you have to fork, you must either do so *before* creating your first
1773 watcher OR you must not use AnyEvent at all in the child OR you must do 1800 watcher OR you must not use AnyEvent at all in the child OR you must do
1774 something completely out of the scope of AnyEvent. 1801 something completely out of the scope of AnyEvent.
1802
1803 The problem of doing event processing in the parent *and* the child is
1804 much more complicated: even for backends that *are* fork-aware or
1805 fork-safe, their behaviour is not usually what you want: fork clones all
1806 watchers, that means all timers, I/O watchers etc. are active in both
1807 parent and child, which is almost never what you want.
1775 1808
1776SECURITY CONSIDERATIONS 1809SECURITY CONSIDERATIONS
1777 AnyEvent can be forced to load any event model via 1810 AnyEvent can be forced to load any event model via
1778 $ENV{PERL_ANYEVENT_MODEL}. While this cannot (to my knowledge) be used 1811 $ENV{PERL_ANYEVENT_MODEL}. While this cannot (to my knowledge) be used
1779 to execute arbitrary code or directly gain access, it can easily be used 1812 to execute arbitrary code or directly gain access, it can easily be used

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines