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

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.241 by root, Fri Jul 17 18:08:35 2009 UTC vs.
Revision 1.246 by root, Sat Jul 18 15:51:52 2009 UTC

361invocation, and callback invocation will be synchronous. Synchronous means 361invocation, and callback invocation will be synchronous. Synchronous means
362that it might take a while until the signal gets handled by the process, 362that it might take a while until the signal gets handled by the process,
363but it is guaranteed not to interrupt any other callbacks. 363but it is guaranteed not to interrupt any other callbacks.
364 364
365The main advantage of using these watchers is that you can share a signal 365The main advantage of using these watchers is that you can share a signal
366between multiple watchers. 366between multiple watchers, and AnyEvent will ensure that signals will not
367interrupt your program at bad times.
367 368
368This watcher might use C<%SIG>, so programs overwriting those signals 369This watcher might use C<%SIG> (depending on the event loop used),
369directly will likely not work correctly. 370so programs overwriting those signals directly will likely not work
371correctly.
372
373Also note that many event loops (e.g. Glib, Tk, Qt, IO::Async) do not
374support attaching callbacks to signals, which is a pity, as you cannot do
375race-free signal handling in perl. AnyEvent will try to do it's best, but
376in some cases, signals will be delayed. The maximum time a signal might
377be delayed is specified in C<$AnyEvent::MAX_SIGNAL_LATENCY> (default: 10
378seconds). This variable can be changed only before the first signal
379watcher is created, and should be left alone otherwise. Higher values
380will cause fewer spurious wake-ups, which is better for power and CPU
381saving. All these problems can be avoided by installing the optional
382L<Async::Interrupt> module.
370 383
371Example: exit on SIGINT 384Example: exit on SIGINT
372 385
373 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 }); 386 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 });
374 387
403 416
404This means you cannot create a child watcher as the very first 417This means you cannot create a child watcher as the very first
405thing in an AnyEvent program, you I<have> to create at least one 418thing in an AnyEvent program, you I<have> to create at least one
406watcher before you C<fork> the child (alternatively, you can call 419watcher before you C<fork> the child (alternatively, you can call
407C<AnyEvent::detect>). 420C<AnyEvent::detect>).
421
422As most event loops do not support waiting for child events, they will be
423emulated by AnyEvent in most cases, in which the latency and race problems
424mentioned in the description of signal watchers apply.
408 425
409Example: fork a process and wait for it 426Example: fork a process and wait for it
410 427
411 my $done = AnyEvent->condvar; 428 my $done = AnyEvent->condvar;
412 429
1024 1041
1025=cut 1042=cut
1026 1043
1027package AnyEvent; 1044package AnyEvent;
1028 1045
1046# basically a tuned-down version of common::sense
1047sub common_sense {
1029no warnings; 1048 # no warnings
1049 ${^WARNING_BITS} ^= ${^WARNING_BITS};
1030use strict qw(vars subs); 1050 # use strict vars subs
1051 $^H |= 0x00000600;
1052}
1053
1054BEGIN { AnyEvent::common_sense }
1031 1055
1032use Carp (); 1056use Carp ();
1033 1057
1034our $VERSION = 4.83; 1058our $VERSION = 4.85;
1035our $MODEL; 1059our $MODEL;
1036 1060
1037our $AUTOLOAD; 1061our $AUTOLOAD;
1038our @ISA; 1062our @ISA;
1039 1063
1040our @REGISTRY; 1064our @REGISTRY;
1041 1065
1042our $WIN32; 1066our $WIN32;
1067
1068our $VERBOSE;
1043 1069
1044BEGIN { 1070BEGIN {
1045 eval "sub WIN32(){ " . (($^O =~ /mswin32/i)*1) ." }"; 1071 eval "sub WIN32(){ " . (($^O =~ /mswin32/i)*1) ." }";
1046 eval "sub TAINT(){ " . (${^TAINT}*1) . " }"; 1072 eval "sub TAINT(){ " . (${^TAINT}*1) . " }";
1047 1073
1048 delete @ENV{grep /^PERL_ANYEVENT_/, keys %ENV} 1074 delete @ENV{grep /^PERL_ANYEVENT_/, keys %ENV}
1049 if ${^TAINT}; 1075 if ${^TAINT};
1050}
1051 1076
1052our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; 1077 $VERBOSE = $ENV{PERL_ANYEVENT_VERBOSE}*1;
1078
1079}
1080
1081our $MAX_SIGNAL_LATENCY = 10;
1053 1082
1054our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred 1083our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred
1055 1084
1056{ 1085{
1057 my $idx; 1086 my $idx;
1108 @post_detect = grep $_ != ${$_[0]}, @post_detect; 1137 @post_detect = grep $_ != ${$_[0]}, @post_detect;
1109} 1138}
1110 1139
1111sub detect() { 1140sub detect() {
1112 unless ($MODEL) { 1141 unless ($MODEL) {
1113 no strict 'refs';
1114 local $SIG{__DIE__}; 1142 local $SIG{__DIE__};
1115 1143
1116 if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) { 1144 if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) {
1117 my $model = "AnyEvent::Impl::$1"; 1145 my $model = "AnyEvent::Impl::$1";
1118 if (eval "require $model") { 1146 if (eval "require $model") {
1119 $MODEL = $model; 1147 $MODEL = $model;
1120 warn "AnyEvent: loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it.\n" if $verbose > 1; 1148 warn "AnyEvent: loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it.\n" if $VERBOSE >= 2;
1121 } else { 1149 } else {
1122 warn "AnyEvent: unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@" if $verbose; 1150 warn "AnyEvent: unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@" if $VERBOSE;
1123 } 1151 }
1124 } 1152 }
1125 1153
1126 # check for already loaded models 1154 # check for already loaded models
1127 unless ($MODEL) { 1155 unless ($MODEL) {
1128 for (@REGISTRY, @models) { 1156 for (@REGISTRY, @models) {
1129 my ($package, $model) = @$_; 1157 my ($package, $model) = @$_;
1130 if (${"$package\::VERSION"} > 0) { 1158 if (${"$package\::VERSION"} > 0) {
1131 if (eval "require $model") { 1159 if (eval "require $model") {
1132 $MODEL = $model; 1160 $MODEL = $model;
1133 warn "AnyEvent: autodetected model '$model', using it.\n" if $verbose > 1; 1161 warn "AnyEvent: autodetected model '$model', using it.\n" if $VERBOSE >= 2;
1134 last; 1162 last;
1135 } 1163 }
1136 } 1164 }
1137 } 1165 }
1138 1166
1143 my ($package, $model) = @$_; 1171 my ($package, $model) = @$_;
1144 if (eval "require $package" 1172 if (eval "require $package"
1145 and ${"$package\::VERSION"} > 0 1173 and ${"$package\::VERSION"} > 0
1146 and eval "require $model") { 1174 and eval "require $model") {
1147 $MODEL = $model; 1175 $MODEL = $model;
1148 warn "AnyEvent: autoprobed model '$model', using it.\n" if $verbose > 1; 1176 warn "AnyEvent: autoprobed model '$model', using it.\n" if $VERBOSE >= 2;
1149 last; 1177 last;
1150 } 1178 }
1151 } 1179 }
1152 1180
1153 $MODEL 1181 $MODEL
1198 1226
1199package AnyEvent::Base; 1227package AnyEvent::Base;
1200 1228
1201# default implementations for many methods 1229# default implementations for many methods
1202 1230
1203BEGIN { 1231sub _time {
1232 # probe for availability of Time::HiRes
1204 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { 1233 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") {
1234 warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8;
1205 *_time = \&Time::HiRes::time; 1235 *_time = \&Time::HiRes::time;
1206 # if (eval "use POSIX (); (POSIX::times())... 1236 # if (eval "use POSIX (); (POSIX::times())...
1207 } else { 1237 } else {
1238 warn "AnyEvent: using built-in time(), WARNING, no sub-second resolution!\n" if $VERBOSE;
1208 *_time = sub { time }; # epic fail 1239 *_time = sub { time }; # epic fail
1209 } 1240 }
1241
1242 &_time
1210} 1243}
1211 1244
1212sub time { _time } 1245sub time { _time }
1213sub now { _time } 1246sub now { _time }
1214sub now_update { } 1247sub now_update { }
1219 bless { @_ == 3 ? (_ae_cb => $_[2]) : () }, "AnyEvent::CondVar" 1252 bless { @_ == 3 ? (_ae_cb => $_[2]) : () }, "AnyEvent::CondVar"
1220} 1253}
1221 1254
1222# default implementation for ->signal 1255# default implementation for ->signal
1223 1256
1257our $HAVE_ASYNC_INTERRUPT;
1224our ($SIGPIPE_R, $SIGPIPE_W, %SIG_CB, %SIG_EV, $SIG_IO); 1258our ($SIGPIPE_R, $SIGPIPE_W, %SIG_CB, %SIG_EV, $SIG_IO);
1259our (%SIG_ASY, %SIG_ASY_W);
1260our ($SIG_COUNT, $SIG_TW);
1225 1261
1226sub _signal_exec { 1262sub _signal_exec {
1263 $HAVE_ASYNC_INTERRUPT
1264 ? $SIGPIPE_R->drain
1227 sysread $SIGPIPE_R, my $dummy, 4; 1265 : sysread $SIGPIPE_R, my $dummy, 9;
1228 1266
1229 while (%SIG_EV) { 1267 while (%SIG_EV) {
1230 for (keys %SIG_EV) { 1268 for (keys %SIG_EV) {
1231 delete $SIG_EV{$_}; 1269 delete $SIG_EV{$_};
1232 $_->() for values %{ $SIG_CB{$_} || {} }; 1270 $_->() for values %{ $SIG_CB{$_} || {} };
1233 } 1271 }
1234 } 1272 }
1235} 1273}
1236 1274
1275# install a dumym wakeupw atcher to reduce signal catching latency
1276sub _sig_add() {
1277 unless ($SIG_COUNT++) {
1278 # try to align timer on a full-second boundary, if possible
1279 my $NOW = AnyEvent->now;
1280
1281 $SIG_TW = AnyEvent->timer (
1282 after => $MAX_SIGNAL_LATENCY - ($NOW - int $NOW),
1283 interval => $MAX_SIGNAL_LATENCY,
1284 cb => sub { }, # just for the PERL_ASYNC_CHECK
1285 );
1286 }
1287}
1288
1289sub _sig_del {
1290 undef $SIG_TW
1291 unless --$SIG_COUNT;
1292}
1293
1294sub _signal {
1295 my (undef, %arg) = @_;
1296
1297 my $signal = uc $arg{signal}
1298 or Carp::croak "required option 'signal' is missing";
1299
1300 $SIG_CB{$signal}{$arg{cb}} = $arg{cb};
1301
1302 if ($HAVE_ASYNC_INTERRUPT) {
1303 # async::interrupt
1304
1305 $SIG_ASY{$signal} ||= do {
1306 my $asy = new Async::Interrupt
1307 cb => sub { undef $SIG_EV{$signal} },
1308 signal => $signal,
1309 pipe => [$SIGPIPE_R->filenos],
1310 ;
1311 $asy->pipe_autodrain (0);
1312
1313 $asy
1314 };
1315
1316 } else {
1317 # pure perl
1318
1319 $SIG{$signal} ||= sub {
1320 local $!;
1321 syswrite $SIGPIPE_W, "\x00", 1 unless %SIG_EV;
1322 undef $SIG_EV{$signal};
1323 };
1324
1325 # can't do signal processing without introducing races in pure perl,
1326 # so limit the signal latency.
1327 _sig_add;
1328 }
1329
1330 bless [$signal, $arg{cb}], "AnyEvent::Base::signal"
1331}
1332
1237sub signal { 1333sub signal {
1238 my (undef, %arg) = @_; 1334 # probe for availability of Async::Interrupt
1335 if (!$ENV{PERL_ANYEVENT_AVOID_ASYNC_INTERRUPT} && eval "use Async::Interrupt 0.6 (); 1") {
1336 warn "AnyEvent: using Async::Interrupt for race-free signal handling.\n" if $VERBOSE >= 8;
1239 1337
1240 unless ($SIGPIPE_R) { 1338 $HAVE_ASYNC_INTERRUPT = 1;
1339 $SIGPIPE_R = new Async::Interrupt::EventPipe;
1340 $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R->fileno, poll => "r", cb => \&_signal_exec);
1341
1342 } else {
1343 warn "AnyEvent: using emulated perl signal handling with latency timer.\n" if $VERBOSE >= 8;
1344
1241 require Fcntl; 1345 require Fcntl;
1242 1346
1243 if (AnyEvent::WIN32) { 1347 if (AnyEvent::WIN32) {
1244 require AnyEvent::Util; 1348 require AnyEvent::Util;
1245 1349
1260 or Carp::croak "AnyEvent: unable to create a signal reporting pipe: $!\n"; 1364 or Carp::croak "AnyEvent: unable to create a signal reporting pipe: $!\n";
1261 1365
1262 $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R, poll => "r", cb => \&_signal_exec); 1366 $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R, poll => "r", cb => \&_signal_exec);
1263 } 1367 }
1264 1368
1265 my $signal = uc $arg{signal} 1369 *signal = \&_signal;
1266 or Carp::croak "required option 'signal' is missing"; 1370 &signal
1267
1268 $SIG_CB{$signal}{$arg{cb}} = $arg{cb};
1269 $SIG{$signal} ||= sub {
1270 local $!;
1271 syswrite $SIGPIPE_W, "\x00", 1 unless %SIG_EV;
1272 undef $SIG_EV{$signal};
1273 };
1274
1275 bless [$signal, $arg{cb}], "AnyEvent::Base::signal"
1276} 1371}
1277 1372
1278sub AnyEvent::Base::signal::DESTROY { 1373sub AnyEvent::Base::signal::DESTROY {
1279 my ($signal, $cb) = @{$_[0]}; 1374 my ($signal, $cb) = @{$_[0]};
1280 1375
1376 _sig_del;
1377
1281 delete $SIG_CB{$signal}{$cb}; 1378 delete $SIG_CB{$signal}{$cb};
1282 1379
1380 $HAVE_ASYNC_INTERRUPT
1381 ? delete $SIG_ASY{$signal}
1283 # delete doesn't work with older perls - they then 1382 : # delete doesn't work with older perls - they then
1284 # print weird messages, or just unconditionally exit 1383 # print weird messages, or just unconditionally exit
1285 # instead of getting the default action. 1384 # instead of getting the default action.
1385 undef $SIG{$signal}
1286 undef $SIG{$signal} unless keys %{ $SIG_CB{$signal} }; 1386 unless keys %{ $SIG_CB{$signal} };
1287} 1387}
1288 1388
1289# default implementation for ->child 1389# default implementation for ->child
1290 1390
1291our %PID_CB; 1391our %PID_CB;
1293our $CHLD_DELAY_W; 1393our $CHLD_DELAY_W;
1294our $WNOHANG; 1394our $WNOHANG;
1295 1395
1296sub _sigchld { 1396sub _sigchld {
1297 while (0 < (my $pid = waitpid -1, $WNOHANG)) { 1397 while (0 < (my $pid = waitpid -1, $WNOHANG)) {
1398 $_->($pid, $?)
1298 $_->($pid, $?) for (values %{ $PID_CB{$pid} || {} }), 1399 for values %{ $PID_CB{$pid} || {} },
1299 (values %{ $PID_CB{0} || {} }); 1400 values %{ $PID_CB{0} || {} };
1300 } 1401 }
1301} 1402}
1302 1403
1303sub child { 1404sub child {
1304 my (undef, %arg) = @_; 1405 my (undef, %arg) = @_;
1306 defined (my $pid = $arg{pid} + 0) 1407 defined (my $pid = $arg{pid} + 0)
1307 or Carp::croak "required option 'pid' is missing"; 1408 or Carp::croak "required option 'pid' is missing";
1308 1409
1309 $PID_CB{$pid}{$arg{cb}} = $arg{cb}; 1410 $PID_CB{$pid}{$arg{cb}} = $arg{cb};
1310 1411
1412 # WNOHANG is almost cetrainly 1 everywhere
1413 $WNOHANG ||= $^O =~ /^(?:openbsd|netbsd|linux|freebsd|cygwin|MSWin32)$/
1414 ? 1
1311 $WNOHANG ||= eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1; 1415 : eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1;
1312 1416
1313 unless ($CHLD_W) { 1417 unless ($CHLD_W) {
1314 $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld); 1418 $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld);
1315 # child could be a zombie already, so make at least one round 1419 # child could be a zombie already, so make at least one round
1316 &_sigchld; 1420 &_sigchld;
1368 1472
1369our @ISA = AnyEvent::CondVar::Base::; 1473our @ISA = AnyEvent::CondVar::Base::;
1370 1474
1371package AnyEvent::CondVar::Base; 1475package AnyEvent::CondVar::Base;
1372 1476
1373use overload 1477#use overload
1374 '&{}' => sub { my $self = shift; sub { $self->send (@_) } }, 1478# '&{}' => sub { my $self = shift; sub { $self->send (@_) } },
1375 fallback => 1; 1479# fallback => 1;
1480
1481# save 300+ kilobytes by dirtily hardcoding overloading
1482${"AnyEvent::CondVar::Base::OVERLOAD"}{dummy}++; # Register with magic by touching.
1483*{'AnyEvent::CondVar::Base::()'} = sub { }; # "Make it findable via fetchmethod."
1484*{'AnyEvent::CondVar::Base::(&{}'} = sub { my $self = shift; sub { $self->send (@_) } }; # &{}
1485${'AnyEvent::CondVar::Base::()'} = 1; # fallback
1376 1486
1377our $WAITING; 1487our $WAITING;
1378 1488
1379sub _send { 1489sub _send {
1380 # nop 1490 # nop
1471C<PERL_ANYEVENT_MODEL>. 1581C<PERL_ANYEVENT_MODEL>.
1472 1582
1473When set to C<2> or higher, cause AnyEvent to report to STDERR which event 1583When set to C<2> or higher, cause AnyEvent to report to STDERR which event
1474model it chooses. 1584model it chooses.
1475 1585
1586When set to C<8> or higher, then AnyEvent will report extra information on
1587which optional modules it loads and how it implements certain features.
1588
1476=item C<PERL_ANYEVENT_STRICT> 1589=item C<PERL_ANYEVENT_STRICT>
1477 1590
1478AnyEvent does not do much argument checking by default, as thorough 1591AnyEvent does not do much argument checking by default, as thorough
1479argument checking is very costly. Setting this variable to a true value 1592argument checking is very costly. Setting this variable to a true value
1480will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly 1593will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly
1481check the arguments passed to most method calls. If it finds any problems, 1594check the arguments passed to most method calls. If it finds any problems,
1482it will croak. 1595it will croak.
1483 1596
1484In other words, enables "strict" mode. 1597In other words, enables "strict" mode.
1485 1598
1486Unlike C<use strict>, it is definitely recommended to keep it off in 1599Unlike C<use strict> (or it's modern cousin, C<< use L<common::sense>
1487production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while 1600>>, it is definitely recommended to keep it off in production. Keeping
1488developing programs can be very useful, however. 1601C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs
1602can be very useful, however.
1489 1603
1490=item C<PERL_ANYEVENT_MODEL> 1604=item C<PERL_ANYEVENT_MODEL>
1491 1605
1492This can be used to specify the event model to be used by AnyEvent, before 1606This can be used to specify the event model to be used by AnyEvent, before
1493auto detection and -probing kicks in. It must be a string consisting 1607auto detection and -probing kicks in. It must be a string consisting
1555 1669
1556When neither C<ca_file> nor C<ca_path> was specified during 1670When neither C<ca_file> nor C<ca_path> was specified during
1557L<AnyEvent::TLS> context creation, and either of these environment 1671L<AnyEvent::TLS> context creation, and either of these environment
1558variables exist, they will be used to specify CA certificate locations 1672variables exist, they will be used to specify CA certificate locations
1559instead of a system-dependent default. 1673instead of a system-dependent default.
1674
1675=item C<PERL_ANYEVENT_AVOID_GUARD> and C<PERL_ANYEVENT_AVOID_ASYNC_INTERRUPT>
1676
1677When these are set to C<1>, then the respective modules are not
1678loaded. Mostly good for testing AnyEvent itself.
1560 1679
1561=back 1680=back
1562 1681
1563=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE 1682=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE
1564 1683
2132 if $SIG{CHLD} eq 'IGNORE'; 2251 if $SIG{CHLD} eq 'IGNORE';
2133 2252
2134$SIG{PIPE} = sub { } 2253$SIG{PIPE} = sub { }
2135 unless defined $SIG{PIPE}; 2254 unless defined $SIG{PIPE};
2136 2255
2256=head1 RECOMMENDED/OPTIONAL MODULES
2257
2258One of AnyEvent's main goals is to be 100% Pure-Perl(tm): only perl (and
2259it's built-in modules) are required to use it.
2260
2261That does not mean that AnyEvent won't take advantage of some additional
2262modules if they are installed.
2263
2264This section epxlains which additional modules will be used, and how they
2265affect AnyEvent's operetion.
2266
2267=over 4
2268
2269=item L<Async::Interrupt>
2270
2271This slightly arcane module is used to implement fast signal handling: To
2272my knowledge, there is no way to do completely race-free and quick
2273signal handling in pure perl. To ensure that signals still get
2274delivered, AnyEvent will start an interval timer to wake up perl (and
2275catch the signals) with soemd elay (default is 10 seconds, look for
2276C<$AnyEvent::MAX_SIGNAL_LATENCY>).
2277
2278If this module is available, then it will be used to implement signal
2279catching, which means that signals will not be delayed, and the event loop
2280will not be interrupted regularly, which is more efficient (And good for
2281battery life on laptops).
2282
2283This affects not just the pure-perl event loop, but also other event loops
2284that have no signal handling on their own (e.g. Glib, Tk, Qt).
2285
2286=item L<EV>
2287
2288This module isn't really "optional", as it is simply one of the backend
2289event loops that AnyEvent can use. However, it is simply the best event
2290loop available in terms of features, speed and stability: It supports
2291the AnyEvent API optimally, implements all the watcher types in XS, does
2292automatic timer adjustments even when no monotonic clock is available,
2293can take avdantage of advanced kernel interfaces such as C<epoll> and
2294C<kqueue>, and is the fastest backend I<by far>. You can even embed
2295L<Glib>/L<Gtk2> in it (or vice versa, see L<EV::Glib> and L<Glib::EV>).
2296
2297=item L<Guard>
2298
2299The guard module, when used, will be used to implement
2300C<AnyEvent::Util::guard>. This speeds up guards considerably (and uses a
2301lot less memory), but otherwise doesn't affect guard operation much. It is
2302purely used for performance.
2303
2304=item L<JSON> and L<JSON::XS>
2305
2306This module is required when you want to read or write JSON data via
2307L<AnyEvent::Handle>. It is also written in pure-perl, but can take
2308advantage of the ulta-high-speed L<JSON::XS> module when it is installed.
2309
2310In fact, L<AnyEvent::Handle> will use L<JSON::XS> by default if it is
2311installed.
2312
2313=item L<Net::SSLeay>
2314
2315Implementing TLS/SSL in Perl is certainly interesting, but not very
2316worthwhile: If this module is installed, then L<AnyEvent::Handle> (with
2317the help of L<AnyEvent::TLS>), gains the ability to do TLS/SSL.
2318
2319=item L<Time::HiRes>
2320
2321This module is part of perl since release 5.008. It will be used when the
2322chosen event library does not come with a timing source on it's own. The
2323pure-perl event loop (L<AnyEvent::Impl::Perl>) will additionally use it to
2324try to use a monotonic clock for timing stability.
2325
2326=back
2327
2328
2137=head1 FORK 2329=head1 FORK
2138 2330
2139Most event libraries are not fork-safe. The ones who are usually are 2331Most event libraries are not fork-safe. The ones who are usually are
2140because they rely on inefficient but fork-safe C<select> or C<poll> 2332because they rely on inefficient but fork-safe C<select> or C<poll>
2141calls. Only L<EV> is fully fork-aware. 2333calls. Only L<EV> is fully fork-aware.
2142 2334
2143If you have to fork, you must either do so I<before> creating your first 2335If you have to fork, you must either do so I<before> creating your first
2144watcher OR you must not use AnyEvent at all in the child. 2336watcher OR you must not use AnyEvent at all in the child OR you must do
2337something completely out of the scope of AnyEvent.
2145 2338
2146 2339
2147=head1 SECURITY CONSIDERATIONS 2340=head1 SECURITY CONSIDERATIONS
2148 2341
2149AnyEvent can be forced to load any event model via 2342AnyEvent can be forced to load any event model via

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines