… | |
… | |
1049 | It should use C<postpone>: |
1049 | It should use C<postpone>: |
1050 | |
1050 | |
1051 | AnyEvent::postpone { $cb->(undef) }, return # signal error to callback, later |
1051 | AnyEvent::postpone { $cb->(undef) }, return # signal error to callback, later |
1052 | if $some_error_condition; |
1052 | if $some_error_condition; |
1053 | |
1053 | |
|
|
1054 | =item AnyEvent::log $level, $msg[, @args] |
|
|
1055 | |
|
|
1056 | Log the given C<$msg> at the given C<$level>. |
|
|
1057 | |
|
|
1058 | Loads AnyEvent::Log on first use and calls C<AnyEvent::Log::log> - |
|
|
1059 | consequently, look at the L<AnyEvent::Log> documentation for details. |
|
|
1060 | |
1054 | =back |
1061 | =back |
1055 | |
1062 | |
1056 | =head1 WHAT TO DO IN A MODULE |
1063 | =head1 WHAT TO DO IN A MODULE |
1057 | |
1064 | |
1058 | As a module author, you should C<use AnyEvent> and call AnyEvent methods |
1065 | As a module author, you should C<use AnyEvent> and call AnyEvent methods |
… | |
… | |
1224 | |
1231 | |
1225 | delete @ENV{grep /^PERL_ANYEVENT_/, keys %ENV} |
1232 | delete @ENV{grep /^PERL_ANYEVENT_/, keys %ENV} |
1226 | if ${^TAINT}; |
1233 | if ${^TAINT}; |
1227 | |
1234 | |
1228 | $VERBOSE = $ENV{PERL_ANYEVENT_VERBOSE}*1; |
1235 | $VERBOSE = $ENV{PERL_ANYEVENT_VERBOSE}*1; |
1229 | |
|
|
1230 | } |
1236 | } |
1231 | |
1237 | |
1232 | our $MAX_SIGNAL_LATENCY = 10; |
1238 | our $MAX_SIGNAL_LATENCY = 10; |
1233 | |
1239 | |
1234 | our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred |
1240 | our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred |
… | |
… | |
1270 | push @POSTPONE, shift; |
1276 | push @POSTPONE, shift; |
1271 | |
1277 | |
1272 | $POSTPONE_W ||= AE::timer (0, 0, \&_postpone_exec); |
1278 | $POSTPONE_W ||= AE::timer (0, 0, \&_postpone_exec); |
1273 | |
1279 | |
1274 | () |
1280 | () |
|
|
1281 | } |
|
|
1282 | |
|
|
1283 | sub log($$;@) { |
|
|
1284 | require AnyEvent::Log; |
|
|
1285 | # AnyEvent::Log overwrites this function |
|
|
1286 | goto &log; |
1275 | } |
1287 | } |
1276 | |
1288 | |
1277 | our @models = ( |
1289 | our @models = ( |
1278 | [EV:: => AnyEvent::Impl::EV:: , 1], |
1290 | [EV:: => AnyEvent::Impl::EV:: , 1], |
1279 | [AnyEvent::Loop:: => AnyEvent::Impl::Perl:: , 1], |
1291 | [AnyEvent::Loop:: => AnyEvent::Impl::Perl:: , 1], |
… | |
… | |
1338 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z0-9:]+)$/) { |
1350 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z0-9:]+)$/) { |
1339 | my $model = $1; |
1351 | my $model = $1; |
1340 | $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//; |
1352 | $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//; |
1341 | if (eval "require $model") { |
1353 | if (eval "require $model") { |
1342 | $MODEL = $model; |
1354 | $MODEL = $model; |
1343 | warn "AnyEvent: loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it.\n" if $VERBOSE >= 2; |
1355 | AnyEvent::log 7 => "loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it." |
|
|
1356 | if $VERBOSE >= 7; |
1344 | } else { |
1357 | } else { |
1345 | warn "AnyEvent: unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@" if $VERBOSE; |
1358 | AnyEvent::log warn => "unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@"; |
1346 | } |
1359 | } |
1347 | } |
1360 | } |
1348 | |
1361 | |
1349 | # check for already loaded models |
1362 | # check for already loaded models |
1350 | unless ($MODEL) { |
1363 | unless ($MODEL) { |
1351 | for (@REGISTRY, @models) { |
1364 | for (@REGISTRY, @models) { |
1352 | my ($package, $model) = @$_; |
1365 | my ($package, $model) = @$_; |
1353 | if (${"$package\::VERSION"} > 0) { |
1366 | if (${"$package\::VERSION"} > 0) { |
1354 | if (eval "require $model") { |
1367 | if (eval "require $model") { |
1355 | $MODEL = $model; |
1368 | $MODEL = $model; |
1356 | warn "AnyEvent: autodetected model '$model', using it.\n" if $VERBOSE >= 2; |
1369 | AnyEvent::log 7 => "autodetected model '$model', using it." |
|
|
1370 | if $VERBOSE >= 7; |
1357 | last; |
1371 | last; |
1358 | } |
1372 | } |
1359 | } |
1373 | } |
1360 | } |
1374 | } |
1361 | |
1375 | |
… | |
… | |
1368 | and eval "require $package" |
1382 | and eval "require $package" |
1369 | and ${"$package\::VERSION"} > 0 |
1383 | and ${"$package\::VERSION"} > 0 |
1370 | and eval "require $model" |
1384 | and eval "require $model" |
1371 | ) { |
1385 | ) { |
1372 | $MODEL = $model; |
1386 | $MODEL = $model; |
1373 | warn "AnyEvent: autoloaded model '$model', using it.\n" if $VERBOSE >= 2; |
1387 | AnyEvent::log 7 => "autoloaded model '$model', using it." |
|
|
1388 | if $VERBOSE >= 7; |
1374 | last; |
1389 | last; |
1375 | } |
1390 | } |
1376 | } |
1391 | } |
1377 | |
1392 | |
1378 | $MODEL |
1393 | $MODEL |
1379 | or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?\n"; |
1394 | or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?"; |
1380 | } |
1395 | } |
1381 | } |
1396 | } |
1382 | |
1397 | |
1383 | # free memory only needed for probing |
1398 | # free memory only needed for probing |
1384 | undef @models; |
1399 | undef @models; |
… | |
… | |
1508 | sub time() { |
1523 | sub time() { |
1509 | AnyEvent->time |
1524 | AnyEvent->time |
1510 | } |
1525 | } |
1511 | |
1526 | |
1512 | *postpone = \&AnyEvent::postpone; |
1527 | *postpone = \&AnyEvent::postpone; |
|
|
1528 | *log = \&AnyEvent::log; |
1513 | }; |
1529 | }; |
1514 | die if $@; |
1530 | die if $@; |
1515 | } |
1531 | } |
1516 | |
1532 | |
1517 | BEGIN { _reset } |
1533 | BEGIN { _reset } |
… | |
… | |
1522 | |
1538 | |
1523 | sub time { |
1539 | sub time { |
1524 | eval q{ # poor man's autoloading {} |
1540 | eval q{ # poor man's autoloading {} |
1525 | # probe for availability of Time::HiRes |
1541 | # probe for availability of Time::HiRes |
1526 | if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { |
1542 | if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { |
1527 | warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8; |
1543 | AnyEvent::log 8 => "AnyEvent: using Time::HiRes for sub-second timing accuracy." |
|
|
1544 | if $AnyEvent::VERBOSE >= 8; |
1528 | *time = sub { Time::HiRes::time () }; |
1545 | *time = sub { Time::HiRes::time () }; |
1529 | *AE::time = \& Time::HiRes::time ; |
1546 | *AE::time = \& Time::HiRes::time ; |
1530 | # if (eval "use POSIX (); (POSIX::times())... |
1547 | # if (eval "use POSIX (); (POSIX::times())... |
1531 | } else { |
1548 | } else { |
1532 | warn "AnyEvent: using built-in time(), WARNING, no sub-second resolution!\n" if $VERBOSE; |
1549 | AnyEvent::log critical => "using built-in time(), WARNING, no sub-second resolution!"; |
1533 | *time = sub { CORE::time }; |
1550 | *time = sub { CORE::time }; |
1534 | *AE::time = sub (){ CORE::time }; |
1551 | *AE::time = sub (){ CORE::time }; |
1535 | } |
1552 | } |
1536 | |
1553 | |
1537 | *now = \&time; |
1554 | *now = \&time; |
… | |
… | |
1635 | |
1652 | |
1636 | sub signal { |
1653 | sub signal { |
1637 | eval q{ # poor man's autoloading {} |
1654 | eval q{ # poor man's autoloading {} |
1638 | # probe for availability of Async::Interrupt |
1655 | # probe for availability of Async::Interrupt |
1639 | if (_have_async_interrupt) { |
1656 | if (_have_async_interrupt) { |
1640 | warn "AnyEvent: using Async::Interrupt for race-free signal handling.\n" if $VERBOSE >= 8; |
1657 | AnyEvent::log 8 => "using Async::Interrupt for race-free signal handling." |
|
|
1658 | if $AnyEvent::VERBOSE >= 8; |
1641 | |
1659 | |
1642 | $SIGPIPE_R = new Async::Interrupt::EventPipe; |
1660 | $SIGPIPE_R = new Async::Interrupt::EventPipe; |
1643 | $SIG_IO = AE::io $SIGPIPE_R->fileno, 0, \&_signal_exec; |
1661 | $SIG_IO = AE::io $SIGPIPE_R->fileno, 0, \&_signal_exec; |
1644 | |
1662 | |
1645 | } else { |
1663 | } else { |
1646 | warn "AnyEvent: using emulated perl signal handling with latency timer.\n" if $VERBOSE >= 8; |
1664 | AnyEvent::log 8 => "using emulated perl signal handling with latency timer." |
|
|
1665 | if $AnyEvent::VERBOSE >= 8; |
1647 | |
1666 | |
1648 | if (AnyEvent::WIN32) { |
1667 | if (AnyEvent::WIN32) { |
1649 | require AnyEvent::Util; |
1668 | require AnyEvent::Util; |
1650 | |
1669 | |
1651 | ($SIGPIPE_R, $SIGPIPE_W) = AnyEvent::Util::portable_pipe (); |
1670 | ($SIGPIPE_R, $SIGPIPE_W) = AnyEvent::Util::portable_pipe (); |
… | |
… | |
1960 | |
1979 | |
1961 | By default, AnyEvent will be completely silent except in fatal |
1980 | By default, AnyEvent will be completely silent except in fatal |
1962 | conditions. You can set this environment variable to make AnyEvent more |
1981 | conditions. You can set this environment variable to make AnyEvent more |
1963 | talkative. |
1982 | talkative. |
1964 | |
1983 | |
1965 | When set to C<1> or higher, causes AnyEvent to warn about unexpected |
1984 | When set to C<5> or higher, causes AnyEvent to warn about unexpected |
1966 | conditions, such as not being able to load the event model specified by |
1985 | conditions, such as not being able to load the event model specified by |
1967 | C<PERL_ANYEVENT_MODEL>. |
1986 | C<PERL_ANYEVENT_MODEL>. |
1968 | |
1987 | |
1969 | When set to C<2> or higher, cause AnyEvent to report to STDERR which event |
1988 | When set to C<7> or higher, cause AnyEvent to report to STDERR which event |
1970 | model it chooses. |
1989 | model it chooses. |
1971 | |
1990 | |
1972 | When set to C<8> or higher, then AnyEvent will report extra information on |
1991 | When set to C<8> or higher, then AnyEvent will report extra information on |
1973 | which optional modules it loads and how it implements certain features. |
1992 | which optional modules it loads and how it implements certain features. |
1974 | |
1993 | |
… | |
… | |
2807 | |
2826 | |
2808 | Tutorial/Introduction: L<AnyEvent::Intro>. |
2827 | Tutorial/Introduction: L<AnyEvent::Intro>. |
2809 | |
2828 | |
2810 | FAQ: L<AnyEvent::FAQ>. |
2829 | FAQ: L<AnyEvent::FAQ>. |
2811 | |
2830 | |
2812 | Utility functions: L<AnyEvent::Util>. |
2831 | Utility functions: L<AnyEvent::Util> (misc. grab-bag), L<AnyEvent::Log> |
|
|
2832 | (simply logging). |
2813 | |
2833 | |
|
|
2834 | Development/Debugging: L<AnyEvent::Strict> (stricter checking), |
|
|
2835 | L<AnyEvent::Debug> (interactive shell, watcher tracing). |
|
|
2836 | |
2814 | Event modules: L<AnyEvent::Loop>, L<EV>, L<EV::Glib>, L<Glib::EV>, |
2837 | Supported event modules: L<AnyEvent::Loop>, L<EV>, L<EV::Glib>, |
2815 | L<Event>, L<Glib::Event>, L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. |
2838 | L<Glib::EV>, L<Event>, L<Glib::Event>, L<Glib>, L<Tk>, L<Event::Lib>, |
|
|
2839 | L<Qt>, L<POE>, L<FLTK>. |
2816 | |
2840 | |
2817 | Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>, |
2841 | Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>, |
2818 | L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, |
2842 | L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, |
2819 | L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>, |
2843 | L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>, |
2820 | L<AnyEvent::Impl::POE>, L<AnyEvent::Impl::IOAsync>, L<Anyevent::Impl::Irssi>. |
2844 | L<AnyEvent::Impl::POE>, L<AnyEvent::Impl::IOAsync>, L<Anyevent::Impl::Irssi>, |
|
|
2845 | L<AnyEvent::Impl::FLTK>. |
2821 | |
2846 | |
2822 | Non-blocking file handles, sockets, TCP clients and |
2847 | Non-blocking handles, pipes, stream sockets, TCP clients and |
2823 | servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>. |
2848 | servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>. |
2824 | |
2849 | |
2825 | Asynchronous DNS: L<AnyEvent::DNS>. |
2850 | Asynchronous DNS: L<AnyEvent::DNS>. |
2826 | |
2851 | |
2827 | Thread support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>. |
2852 | Thread support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>. |