… | |
… | |
878 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
878 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
879 | AnyEvent::Impl::POE based on POE, very slow, some limitations. |
879 | AnyEvent::Impl::POE based on POE, very slow, some limitations. |
880 | AnyEvent::Impl::Irssi used when running within irssi. |
880 | AnyEvent::Impl::Irssi used when running within irssi. |
881 | AnyEvent::Impl::IOAsync based on IO::Async. |
881 | AnyEvent::Impl::IOAsync based on IO::Async. |
882 | AnyEvent::Impl::Cocoa based on Cocoa::EventLoop. |
882 | AnyEvent::Impl::Cocoa based on Cocoa::EventLoop. |
883 | AnyEvent::Impl::FLTK based on FLTK. |
883 | AnyEvent::Impl::FLTK2 based on FLTK (fltk 2 binding). |
884 | |
884 | |
885 | =item Backends with special needs. |
885 | =item Backends with special needs. |
886 | |
886 | |
887 | Qt requires the Qt::Application to be instantiated first, but will |
887 | Qt requires the Qt::Application to be instantiated first, but will |
888 | otherwise be picked up automatically. As long as the main program |
888 | otherwise be picked up automatically. As long as the main program |
… | |
… | |
933 | |
933 | |
934 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
934 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
935 | if necessary. You should only call this function right before you would |
935 | if necessary. You should only call this function right before you would |
936 | have created an AnyEvent watcher anyway, that is, as late as possible at |
936 | have created an AnyEvent watcher anyway, that is, as late as possible at |
937 | runtime, and not e.g. during initialisation of your module. |
937 | runtime, and not e.g. during initialisation of your module. |
|
|
938 | |
|
|
939 | The effect of calling this function is as if a watcher had been created |
|
|
940 | (specifically, actions that happen "when the first watcher is created" |
|
|
941 | happen when calling detetc as well). |
938 | |
942 | |
939 | If you need to do some initialisation before AnyEvent watchers are |
943 | If you need to do some initialisation before AnyEvent watchers are |
940 | created, use C<post_detect>. |
944 | created, use C<post_detect>. |
941 | |
945 | |
942 | =item $guard = AnyEvent::post_detect { BLOCK } |
946 | =item $guard = AnyEvent::post_detect { BLOCK } |
… | |
… | |
1005 | # AnyEvent not yet initialised, so make sure to load Coro::AnyEvent |
1009 | # AnyEvent not yet initialised, so make sure to load Coro::AnyEvent |
1006 | # as soon as it is |
1010 | # as soon as it is |
1007 | push @AnyEvent::post_detect, sub { require Coro::AnyEvent }; |
1011 | push @AnyEvent::post_detect, sub { require Coro::AnyEvent }; |
1008 | } |
1012 | } |
1009 | |
1013 | |
1010 | =item AnyEvent::postpone BLOCK |
1014 | =item AnyEvent::postpone { BLOCK } |
1011 | |
1015 | |
1012 | Arranges for the block to be executed as soon as possible, but not before |
1016 | Arranges for the block to be executed as soon as possible, but not before |
1013 | the call itself returns. In practise, the block will be executed just |
1017 | the call itself returns. In practise, the block will be executed just |
1014 | before the event loop polls for new events, or shortly afterwards. |
1018 | before the event loop polls for new events, or shortly afterwards. |
1015 | |
1019 | |
… | |
… | |
1202 | |
1206 | |
1203 | BEGIN { AnyEvent::common_sense } |
1207 | BEGIN { AnyEvent::common_sense } |
1204 | |
1208 | |
1205 | use Carp (); |
1209 | use Carp (); |
1206 | |
1210 | |
1207 | our $VERSION = '5.34'; |
1211 | our $VERSION = '6.01'; |
1208 | our $MODEL; |
1212 | our $MODEL; |
1209 | |
1213 | |
1210 | our $AUTOLOAD; |
|
|
1211 | our @ISA; |
1214 | our @ISA; |
1212 | |
1215 | |
1213 | our @REGISTRY; |
1216 | our @REGISTRY; |
1214 | |
1217 | |
1215 | our $VERBOSE; |
1218 | our $VERBOSE; |
… | |
… | |
1235 | $PROTOCOL{$_} = ++$idx |
1238 | $PROTOCOL{$_} = ++$idx |
1236 | for reverse split /\s*,\s*/, |
1239 | for reverse split /\s*,\s*/, |
1237 | $ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6"; |
1240 | $ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6"; |
1238 | } |
1241 | } |
1239 | |
1242 | |
|
|
1243 | our @post_detect; |
|
|
1244 | |
|
|
1245 | sub post_detect(&) { |
|
|
1246 | my ($cb) = @_; |
|
|
1247 | |
|
|
1248 | push @post_detect, $cb; |
|
|
1249 | |
|
|
1250 | defined wantarray |
|
|
1251 | ? bless \$cb, "AnyEvent::Util::postdetect" |
|
|
1252 | : () |
|
|
1253 | } |
|
|
1254 | |
|
|
1255 | sub AnyEvent::Util::postdetect::DESTROY { |
|
|
1256 | @post_detect = grep $_ != ${$_[0]}, @post_detect; |
|
|
1257 | } |
|
|
1258 | |
|
|
1259 | our $POSTPONE_W; |
|
|
1260 | our @POSTPONE; |
|
|
1261 | |
|
|
1262 | sub _postpone_exec { |
|
|
1263 | undef $POSTPONE_W; |
|
|
1264 | |
|
|
1265 | &{ shift @POSTPONE } |
|
|
1266 | while @POSTPONE; |
|
|
1267 | } |
|
|
1268 | |
|
|
1269 | sub postpone(&) { |
|
|
1270 | push @POSTPONE, shift; |
|
|
1271 | |
|
|
1272 | $POSTPONE_W ||= AE::timer (0, 0, \&_postpone_exec); |
|
|
1273 | |
|
|
1274 | () |
|
|
1275 | } |
|
|
1276 | |
1240 | my @models = ( |
1277 | our @models = ( |
1241 | [EV:: => AnyEvent::Impl::EV:: , 1], |
1278 | [EV:: => AnyEvent::Impl::EV:: , 1], |
1242 | [AnyEvent::Loop:: => AnyEvent::Impl::Perl:: , 1], |
1279 | [AnyEvent::Loop:: => AnyEvent::Impl::Perl:: , 1], |
1243 | # everything below here will not (normally) be autoprobed |
1280 | # everything below here will not (normally) be autoprobed |
1244 | # as the pure perl backend should work everywhere |
1281 | # as the pure perl backend should work everywhere |
1245 | # and is usually faster |
1282 | # and is usually faster |
… | |
… | |
1250 | [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles |
1287 | [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles |
1251 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
1288 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
1252 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
1289 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
1253 | [Wx:: => AnyEvent::Impl::POE::], |
1290 | [Wx:: => AnyEvent::Impl::POE::], |
1254 | [Prima:: => AnyEvent::Impl::POE::], |
1291 | [Prima:: => AnyEvent::Impl::POE::], |
1255 | [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], |
1292 | [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # a bitch to autodetect |
1256 | [Cocoa::EventLoop:: => AnyEvent::Impl::Cocoa::], |
1293 | [Cocoa::EventLoop:: => AnyEvent::Impl::Cocoa::], |
1257 | [FLTK:: => AnyEvent::Impl::FLTK::], |
1294 | [FLTK:: => AnyEvent::Impl::FLTK2::], |
1258 | ); |
1295 | ); |
1259 | |
1296 | |
1260 | our %method = map +($_ => 1), |
1297 | our @isa_hook; |
|
|
1298 | |
|
|
1299 | sub _isa_set { |
|
|
1300 | my @pkg = ("AnyEvent", (map $_->[0], grep defined, @isa_hook), $MODEL); |
|
|
1301 | |
|
|
1302 | @{"$pkg[$_-1]::ISA"} = $pkg[$_] |
|
|
1303 | for 1 .. $#pkg; |
|
|
1304 | |
|
|
1305 | grep $_ && $_->[1], @isa_hook |
|
|
1306 | and AE::_reset (); |
|
|
1307 | } |
|
|
1308 | |
|
|
1309 | # used for hooking AnyEvent::Strict and AnyEvent::Debug::Wrap into the class hierarchy |
|
|
1310 | sub _isa_hook($$;$) { |
|
|
1311 | my ($i, $pkg, $reset_ae) = @_; |
|
|
1312 | |
|
|
1313 | $isa_hook[$i] = $pkg ? [$pkg, $reset_ae] : undef; |
|
|
1314 | |
|
|
1315 | _isa_set; |
|
|
1316 | } |
|
|
1317 | |
|
|
1318 | # all autoloaded methods reserve the complete glob, not just the method slot. |
|
|
1319 | # due to bugs in perls method cache implementation. |
1261 | qw(io timer time now now_update signal child idle condvar DESTROY); |
1320 | our @methods = qw(io timer time now now_update signal child idle condvar); |
1262 | |
|
|
1263 | our @post_detect; |
|
|
1264 | |
|
|
1265 | sub post_detect(&) { |
|
|
1266 | my ($cb) = @_; |
|
|
1267 | |
|
|
1268 | push @post_detect, $cb; |
|
|
1269 | |
|
|
1270 | defined wantarray |
|
|
1271 | ? bless \$cb, "AnyEvent::Util::postdetect" |
|
|
1272 | : () |
|
|
1273 | } |
|
|
1274 | |
|
|
1275 | sub AnyEvent::Util::postdetect::DESTROY { |
|
|
1276 | @post_detect = grep $_ != ${$_[0]}, @post_detect; |
|
|
1277 | } |
|
|
1278 | |
1321 | |
1279 | sub detect() { |
1322 | sub detect() { |
|
|
1323 | local $!; # for good measure |
|
|
1324 | local $SIG{__DIE__}; # we use eval |
|
|
1325 | |
1280 | # free some memory |
1326 | # free some memory |
1281 | *detect = sub () { $MODEL }; |
1327 | *detect = sub () { $MODEL }; |
|
|
1328 | # undef &func doesn't correctly update the method cache. grmbl. |
|
|
1329 | # so we delete the whole glob. grmbl. |
|
|
1330 | # otoh, perl doesn't let me undef an active usb, but it lets me free |
|
|
1331 | # a glob with an active sub. hrm. i hope it works, but perl is |
|
|
1332 | # usually buggy in this department. sigh. |
|
|
1333 | delete @{"AnyEvent::"}{@methods}; |
|
|
1334 | undef @methods; |
1282 | |
1335 | |
1283 | local $!; # for good measure |
|
|
1284 | local $SIG{__DIE__}; |
|
|
1285 | |
|
|
1286 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) { |
1336 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z0-9:]+)$/) { |
1287 | my $model = "AnyEvent::Impl::$1"; |
1337 | my $model = $1; |
|
|
1338 | $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//; |
1288 | if (eval "require $model") { |
1339 | if (eval "require $model") { |
1289 | $MODEL = $model; |
1340 | $MODEL = $model; |
1290 | warn "AnyEvent: loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it.\n" if $VERBOSE >= 2; |
1341 | warn "AnyEvent: loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it.\n" if $VERBOSE >= 2; |
1291 | } else { |
1342 | } else { |
1292 | warn "AnyEvent: unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@" if $VERBOSE; |
1343 | warn "AnyEvent: unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@" if $VERBOSE; |
… | |
… | |
1325 | $MODEL |
1376 | $MODEL |
1326 | or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?\n"; |
1377 | or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?\n"; |
1327 | } |
1378 | } |
1328 | } |
1379 | } |
1329 | |
1380 | |
1330 | @models = (); # free probe data |
1381 | # free memory only needed for probing |
|
|
1382 | undef @models; |
|
|
1383 | undef @REGISTRY; |
1331 | |
1384 | |
1332 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
1385 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
1333 | unshift @ISA, $MODEL; |
|
|
1334 | |
1386 | |
1335 | # now nuke some methods that are overridden by the backend. |
1387 | # now nuke some methods that are overridden by the backend. |
1336 | # SUPER is not allowed. |
1388 | # SUPER usage is not allowed in these. |
1337 | for (qw(time signal child idle)) { |
1389 | for (qw(time signal child idle)) { |
1338 | undef &{"AnyEvent::Base::$_"} |
1390 | undef &{"AnyEvent::Base::$_"} |
1339 | if defined &{"$MODEL\::$_"}; |
1391 | if defined &{"$MODEL\::$_"}; |
1340 | } |
1392 | } |
1341 | |
1393 | |
|
|
1394 | _isa_set; |
|
|
1395 | |
1342 | if ($ENV{PERL_ANYEVENT_STRICT}) { |
1396 | if ($ENV{PERL_ANYEVENT_STRICT}) { |
1343 | eval { require AnyEvent::Strict }; |
1397 | require AnyEvent::Strict; |
1344 | warn "AnyEvent: cannot load AnyEvent::Strict: $@" |
|
|
1345 | if $@ && $VERBOSE; |
|
|
1346 | } |
1398 | } |
1347 | |
1399 | |
|
|
1400 | if ($ENV{PERL_ANYEVENT_DEBUG_WRAP}) { |
|
|
1401 | require AnyEvent::Debug; |
|
|
1402 | AnyEvent::Debug::wrap ($ENV{PERL_ANYEVENT_DEBUG_WRAP}); |
|
|
1403 | } |
|
|
1404 | |
|
|
1405 | if (exists $ENV{PERL_ANYEVENT_DEBUG_SHELL}) { |
|
|
1406 | require AnyEvent::Socket; |
|
|
1407 | require AnyEvent::Debug; |
|
|
1408 | |
|
|
1409 | my $shell = $ENV{PERL_ANYEVENT_DEBUG_SHELL}; |
|
|
1410 | $shell =~ s/\$\$/$$/g; |
|
|
1411 | |
|
|
1412 | my ($host, $service) = AnyEvent::Socket::parse_hostport ($shell); |
|
|
1413 | $AnyEvent::Debug::SHELL = AnyEvent::Debug::shell ($host, $service); |
|
|
1414 | } |
|
|
1415 | |
1348 | (shift @post_detect)->() while @post_detect; |
1416 | (shift @post_detect)->() while @post_detect; |
|
|
1417 | undef @post_detect; |
1349 | |
1418 | |
1350 | *post_detect = sub(&) { |
1419 | *post_detect = sub(&) { |
1351 | shift->(); |
1420 | shift->(); |
1352 | |
1421 | |
1353 | undef |
1422 | undef |
1354 | }; |
1423 | }; |
1355 | |
1424 | |
1356 | $MODEL |
1425 | $MODEL |
1357 | } |
1426 | } |
1358 | |
1427 | |
1359 | sub AUTOLOAD { |
1428 | for my $name (@methods) { |
1360 | (my $func = $AUTOLOAD) =~ s/.*://; |
1429 | *$name = sub { |
1361 | |
|
|
1362 | $method{$func} |
|
|
1363 | or Carp::croak "$func: not a valid AnyEvent class method"; |
|
|
1364 | |
|
|
1365 | detect; |
1430 | detect; |
1366 | |
1431 | # we use goto because |
1367 | my $class = shift; |
1432 | # a) it makes the thunk more transparent |
1368 | $class->$func (@_); |
1433 | # b) it allows us to delete the thunk later |
1369 | } |
1434 | goto &{ UNIVERSAL::can AnyEvent => "SUPER::$name" } |
1370 | |
1435 | }; |
1371 | our $POSTPONE_W; |
|
|
1372 | our @POSTPONE; |
|
|
1373 | |
|
|
1374 | sub _postpone_exec { |
|
|
1375 | undef $POSTPONE_W; |
|
|
1376 | (pop @POSTPONE)->() |
|
|
1377 | while @POSTPONE; |
|
|
1378 | } |
|
|
1379 | |
|
|
1380 | sub postpone(&) { |
|
|
1381 | push @POSTPONE, shift; |
|
|
1382 | |
|
|
1383 | $POSTPONE_W ||= AE::timer (0, 0, \&_postpone_exec); |
|
|
1384 | |
|
|
1385 | () |
|
|
1386 | } |
1436 | } |
1387 | |
1437 | |
1388 | # utility function to dup a filehandle. this is used by many backends |
1438 | # utility function to dup a filehandle. this is used by many backends |
1389 | # to support binding more than one watcher per filehandle (they usually |
1439 | # to support binding more than one watcher per filehandle (they usually |
1390 | # allow only one watcher per fd, so we dup it to get a different one). |
1440 | # allow only one watcher per fd, so we dup it to get a different one). |
… | |
… | |
1414 | |
1464 | |
1415 | package AE; |
1465 | package AE; |
1416 | |
1466 | |
1417 | our $VERSION = $AnyEvent::VERSION; |
1467 | our $VERSION = $AnyEvent::VERSION; |
1418 | |
1468 | |
|
|
1469 | sub _reset() { |
|
|
1470 | eval q{ |
1419 | # fall back to the main API by default - backends and AnyEvent::Base |
1471 | # fall back to the main API by default - backends and AnyEvent::Base |
1420 | # implementations can overwrite these. |
1472 | # implementations can overwrite these. |
1421 | |
1473 | |
1422 | sub io($$$) { |
1474 | sub io($$$) { |
1423 | AnyEvent->io (fh => $_[0], poll => $_[1] ? "w" : "r", cb => $_[2]) |
1475 | AnyEvent->io (fh => $_[0], poll => $_[1] ? "w" : "r", cb => $_[2]) |
1424 | } |
1476 | } |
1425 | |
1477 | |
1426 | sub timer($$$) { |
1478 | sub timer($$$) { |
1427 | AnyEvent->timer (after => $_[0], interval => $_[1], cb => $_[2]) |
1479 | AnyEvent->timer (after => $_[0], interval => $_[1], cb => $_[2]) |
1428 | } |
1480 | } |
1429 | |
1481 | |
1430 | sub signal($$) { |
1482 | sub signal($$) { |
1431 | AnyEvent->signal (signal => $_[0], cb => $_[1]) |
1483 | AnyEvent->signal (signal => $_[0], cb => $_[1]) |
1432 | } |
1484 | } |
1433 | |
1485 | |
1434 | sub child($$) { |
1486 | sub child($$) { |
1435 | AnyEvent->child (pid => $_[0], cb => $_[1]) |
1487 | AnyEvent->child (pid => $_[0], cb => $_[1]) |
1436 | } |
1488 | } |
1437 | |
1489 | |
1438 | sub idle($) { |
1490 | sub idle($) { |
1439 | AnyEvent->idle (cb => $_[0]) |
1491 | AnyEvent->idle (cb => $_[0]); |
1440 | } |
1492 | } |
1441 | |
1493 | |
1442 | sub cv(;&) { |
1494 | sub cv(;&) { |
1443 | AnyEvent->condvar (@_ ? (cb => $_[0]) : ()) |
1495 | AnyEvent->condvar (@_ ? (cb => $_[0]) : ()) |
1444 | } |
1496 | } |
1445 | |
1497 | |
1446 | sub now() { |
1498 | sub now() { |
1447 | AnyEvent->now |
1499 | AnyEvent->now |
1448 | } |
1500 | } |
1449 | |
1501 | |
1450 | sub now_update() { |
1502 | sub now_update() { |
1451 | AnyEvent->now_update |
1503 | AnyEvent->now_update |
1452 | } |
1504 | } |
1453 | |
1505 | |
1454 | sub time() { |
1506 | sub time() { |
1455 | AnyEvent->time |
1507 | AnyEvent->time |
|
|
1508 | } |
|
|
1509 | |
|
|
1510 | *postpone = \&AnyEvent::postpone; |
|
|
1511 | }; |
|
|
1512 | die if $@; |
1456 | } |
1513 | } |
|
|
1514 | |
|
|
1515 | BEGIN { _reset } |
1457 | |
1516 | |
1458 | package AnyEvent::Base; |
1517 | package AnyEvent::Base; |
1459 | |
1518 | |
1460 | # default implementations for many methods |
1519 | # default implementations for many methods |
1461 | |
1520 | |
1462 | sub time { |
1521 | sub time { |
1463 | eval q{ # poor man's autoloading {} |
1522 | eval q{ # poor man's autoloading {} |
1464 | # probe for availability of Time::HiRes |
1523 | # probe for availability of Time::HiRes |
1465 | if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { |
1524 | if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { |
1466 | warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8; |
1525 | warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8; |
|
|
1526 | *time = sub { Time::HiRes::time () }; |
1467 | *AE::time = \&Time::HiRes::time; |
1527 | *AE::time = \& Time::HiRes::time ; |
1468 | # if (eval "use POSIX (); (POSIX::times())... |
1528 | # if (eval "use POSIX (); (POSIX::times())... |
1469 | } else { |
1529 | } else { |
1470 | warn "AnyEvent: using built-in time(), WARNING, no sub-second resolution!\n" if $VERBOSE; |
1530 | warn "AnyEvent: using built-in time(), WARNING, no sub-second resolution!\n" if $VERBOSE; |
|
|
1531 | *time = sub { CORE::time }; |
1471 | *AE::time = sub (){ time }; # epic fail |
1532 | *AE::time = sub (){ CORE::time }; |
1472 | } |
1533 | } |
1473 | |
1534 | |
1474 | *time = sub { AE::time }; # different prototypes |
1535 | *now = \&time; |
1475 | }; |
1536 | }; |
1476 | die if $@; |
1537 | die if $@; |
1477 | |
1538 | |
1478 | &time |
1539 | &time |
1479 | } |
1540 | } |
1480 | |
1541 | |
1481 | *now = \&time; |
1542 | *now = \&time; |
1482 | |
|
|
1483 | sub now_update { } |
1543 | sub now_update { } |
1484 | |
1544 | |
1485 | sub _poll { |
1545 | sub _poll { |
1486 | Carp::croak "$AnyEvent::MODEL does not support blocking waits. Caught"; |
1546 | Carp::croak "$AnyEvent::MODEL does not support blocking waits. Caught"; |
1487 | } |
1547 | } |
… | |
… | |
1665 | : sysread $SIGPIPE_R, (my $dummy), 9; |
1725 | : sysread $SIGPIPE_R, (my $dummy), 9; |
1666 | |
1726 | |
1667 | while (%SIG_EV) { |
1727 | while (%SIG_EV) { |
1668 | for (keys %SIG_EV) { |
1728 | for (keys %SIG_EV) { |
1669 | delete $SIG_EV{$_}; |
1729 | delete $SIG_EV{$_}; |
1670 | $_->() for values %{ $SIG_CB{$_} || {} }; |
1730 | &$_ for values %{ $SIG_CB{$_} || {} }; |
1671 | } |
1731 | } |
1672 | } |
1732 | } |
1673 | }; |
1733 | }; |
1674 | }; |
1734 | }; |
1675 | die if $@; |
1735 | die if $@; |
… | |
… | |
1742 | |
1802 | |
1743 | my ($cb, $w, $rcb) = $arg{cb}; |
1803 | my ($cb, $w, $rcb) = $arg{cb}; |
1744 | |
1804 | |
1745 | $rcb = sub { |
1805 | $rcb = sub { |
1746 | if ($cb) { |
1806 | if ($cb) { |
1747 | $w = _time; |
1807 | $w = AE::time; |
1748 | &$cb; |
1808 | &$cb; |
1749 | $w = _time - $w; |
1809 | $w = AE::time - $w; |
1750 | |
1810 | |
1751 | # never use more then 50% of the time for the idle watcher, |
1811 | # never use more then 50% of the time for the idle watcher, |
1752 | # within some limits |
1812 | # within some limits |
1753 | $w = 0.0001 if $w < 0.0001; |
1813 | $w = 0.0001 if $w < 0.0001; |
1754 | $w = 5 if $w > 5; |
1814 | $w = 5 if $w > 5; |
… | |
… | |
1923 | Unlike C<use strict> (or its modern cousin, C<< use L<common::sense> |
1983 | Unlike C<use strict> (or its modern cousin, C<< use L<common::sense> |
1924 | >>, it is definitely recommended to keep it off in production. Keeping |
1984 | >>, it is definitely recommended to keep it off in production. Keeping |
1925 | C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs |
1985 | C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs |
1926 | can be very useful, however. |
1986 | can be very useful, however. |
1927 | |
1987 | |
|
|
1988 | =item C<PERL_ANYEVENT_DEBUG_SHELL> |
|
|
1989 | |
|
|
1990 | If this env variable is set, then its contents will be interpreted by |
|
|
1991 | C<AnyEvent::Socket::parse_hostport> (after replacing every occurance of |
|
|
1992 | C<$$> by the process pid) and an C<AnyEvent::Debug::shell> is bound on |
|
|
1993 | that port. The shell object is saved in C<$AnyEvent::Debug::SHELL>. |
|
|
1994 | |
|
|
1995 | This takes place when the first watcher is created. |
|
|
1996 | |
|
|
1997 | For example, to bind a debug shell on a unix domain socket in |
|
|
1998 | F<< /tmp/debug<pid>.sock >>, you could use this: |
|
|
1999 | |
|
|
2000 | PERL_ANYEVENT_DEBUG_SHELL=unix/:/tmp/debug\$\$.sock perlprog |
|
|
2001 | |
|
|
2002 | Note that creating sockets in F</tmp> is very unsafe on multiuser |
|
|
2003 | systems. |
|
|
2004 | |
|
|
2005 | =item C<PERL_ANYEVENT_DEBUG_WRAP> |
|
|
2006 | |
|
|
2007 | Can be set to C<0>, C<1> or C<2> and enables wrapping of all watchers for |
|
|
2008 | debugging purposes. See C<AnyEvent::Debug::wrap> for details. |
|
|
2009 | |
1928 | =item C<PERL_ANYEVENT_MODEL> |
2010 | =item C<PERL_ANYEVENT_MODEL> |
1929 | |
2011 | |
1930 | This can be used to specify the event model to be used by AnyEvent, before |
2012 | This can be used to specify the event model to be used by AnyEvent, before |
1931 | auto detection and -probing kicks in. It must be a string consisting |
2013 | auto detection and -probing kicks in. |
1932 | entirely of ASCII letters. The string C<AnyEvent::Impl::> gets prepended |
2014 | |
|
|
2015 | It normally is a string consisting entirely of ASCII letters (e.g. C<EV> |
|
|
2016 | or C<IOAsync>). The string C<AnyEvent::Impl::> gets prepended and the |
1933 | and the resulting module name is loaded and if the load was successful, |
2017 | resulting module name is loaded and - if the load was successful - used as |
1934 | used as event model. If it fails to load AnyEvent will proceed with |
2018 | event model backend. If it fails to load then AnyEvent will proceed with |
1935 | auto detection and -probing. |
2019 | auto detection and -probing. |
1936 | |
2020 | |
1937 | This functionality might change in future versions. |
2021 | If the string ends with C<::> instead (e.g. C<AnyEvent::Impl::EV::>) then |
|
|
2022 | nothing gets prepended and the module name is used as-is (hint: C<::> at |
|
|
2023 | the end of a string designates a module name and quotes it appropriately). |
1938 | |
2024 | |
1939 | For example, to force the pure perl model (L<AnyEvent::Loop::Perl>) you |
2025 | For example, to force the pure perl model (L<AnyEvent::Loop::Perl>) you |
1940 | could start your program like this: |
2026 | could start your program like this: |
1941 | |
2027 | |
1942 | PERL_ANYEVENT_MODEL=Perl perl ... |
2028 | PERL_ANYEVENT_MODEL=Perl perl ... |
… | |
… | |
2334 | (even when used without AnyEvent), but most event loops have acceptable |
2420 | (even when used without AnyEvent), but most event loops have acceptable |
2335 | performance with or without AnyEvent. |
2421 | performance with or without AnyEvent. |
2336 | |
2422 | |
2337 | =item * The overhead AnyEvent adds is usually much smaller than the overhead of |
2423 | =item * The overhead AnyEvent adds is usually much smaller than the overhead of |
2338 | the actual event loop, only with extremely fast event loops such as EV |
2424 | the actual event loop, only with extremely fast event loops such as EV |
2339 | adds AnyEvent significant overhead. |
2425 | does AnyEvent add significant overhead. |
2340 | |
2426 | |
2341 | =item * You should avoid POE like the plague if you want performance or |
2427 | =item * You should avoid POE like the plague if you want performance or |
2342 | reasonable memory usage. |
2428 | reasonable memory usage. |
2343 | |
2429 | |
2344 | =back |
2430 | =back |