--- AnyEvent/lib/AnyEvent.pm 2009/07/31 20:16:29 1.269 +++ AnyEvent/lib/AnyEvent.pm 2009/08/09 13:27:23 1.277 @@ -808,12 +808,11 @@ =item Backends that are autoprobed when no other event loop can be found. EV is the preferred backend when no other event loop seems to be in -use. If EV is not installed, then AnyEvent will try Event, and, failing -that, will fall back to its own pure-perl implementation, which is -available everywhere as it comes with AnyEvent itself. +use. If EV is not installed, then AnyEvent will fall back to its own +pure-perl implementation, which is available everywhere as it comes with +AnyEvent itself. AnyEvent::Impl::EV based on EV (interface to libev, best choice). - AnyEvent::Impl::Event based on Event, very stable, few glitches. AnyEvent::Impl::Perl pure-perl implementation, fast and portable. =item Backends that are transparently being picked up when they are used. @@ -824,6 +823,7 @@ when the main program loads an event module before anything starts to create watchers. Nothing special needs to be done by the main program. + AnyEvent::Impl::Event based on Event, very stable, few glitches. AnyEvent::Impl::Glib based on Glib, slow but very stable. AnyEvent::Impl::Tk based on Tk, very broken. AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. @@ -1117,7 +1117,7 @@ use Carp (); -our $VERSION = 4.9; +our $VERSION = 4.92; our $MODEL; our $AUTOLOAD; @@ -1153,11 +1153,11 @@ my @models = ( [EV:: => AnyEvent::Impl::EV:: , 1], - [Event:: => AnyEvent::Impl::Event::, 1], [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl:: , 1], # everything below here will not (normally) be autoprobed # as the pureperl backend should work everywhere # and is usually faster + [Event:: => AnyEvent::Impl::Event::, 1], [Glib:: => AnyEvent::Impl::Glib:: , 1], # becomes extremely slow with many watchers [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy [Irssi:: => AnyEvent::Impl::Irssi::], # Irssi has a bogus "Event" package @@ -1170,9 +1170,10 @@ # byzantine signal and broken child handling, among others. # IO::Async is rather hard to detect, as it doesn't have any # obvious default class. -# [0, IO::Async:: => AnyEvent::Impl::IOAsync::], # requires special main program -# [0, IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # requires special main program -# [0, IO::Async::Notifier:: => AnyEvent::Impl::IOAsync::], # requires special main program + [IO::Async:: => AnyEvent::Impl::IOAsync::], # requires special main program + [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # requires special main program + [IO::Async::Notifier:: => AnyEvent::Impl::IOAsync::], # requires special main program + [AnyEvent::Impl::IOAsync:: => AnyEvent::Impl::IOAsync::], # requires special main program ); our %method = map +($_ => 1), @@ -1289,6 +1290,50 @@ ($fh2, $rw) } +############################################################################# +# "new" API, currently only emulation of it +############################################################################# + +package AE; + +our $VERSION = $AnyEvent::VERSION; + +sub io($$$) { + AnyEvent->io (fh => $_[0], poll => $_[1] ? "w" : "r", cb => $_[2]) +} + +sub timer($$$) { + AnyEvent->timer (after => $_[0], interval => $_[1], cb => $_[2]) +} + +sub signal($$) { + AnyEvent->signal (signal => $_[0], cb => $_[1]) +} + +sub child($$) { + AnyEvent->child (pid => $_[0], cb => $_[1]) +} + +sub idle($) { + AnyEvent->idle (cb => $_[0]) +} + +sub cv(;&) { + AnyEvent->condvar (@_ ? (cb => $_[0]) : ()) +} + +sub now() { + AnyEvent->now +} + +sub now_update() { + AnyEvent->now_update +} + +sub time() { + AnyEvent->time +} + package AnyEvent::Base; # default implementations for many methods @@ -1350,13 +1395,13 @@ sub _sig_add() { unless ($SIG_COUNT++) { # try to align timer on a full-second boundary, if possible - my $NOW = AnyEvent->now; + my $NOW = AE::now; - $SIG_TW = AnyEvent->timer ( - after => $MAX_SIGNAL_LATENCY - ($NOW - int $NOW), - interval => $MAX_SIGNAL_LATENCY, - cb => sub { }, # just for the PERL_ASYNC_CHECK - ); + $SIG_TW = AE::timer + $MAX_SIGNAL_LATENCY - ($NOW - int $NOW), + $MAX_SIGNAL_LATENCY, + sub { } # just for the PERL_ASYNC_CHECK + ; } } @@ -1403,7 +1448,7 @@ warn "AnyEvent: using Async::Interrupt for race-free signal handling.\n" if $VERBOSE >= 8; $SIGPIPE_R = new Async::Interrupt::EventPipe; - $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R->fileno, poll => "r", cb => \&_signal_exec); + $SIG_IO = AE::io $SIGPIPE_R->fileno, 0, \&_signal_exec; } else { warn "AnyEvent: using emulated perl signal handling with latency timer.\n" if $VERBOSE >= 8; @@ -1429,7 +1474,7 @@ $SIGPIPE_R or Carp::croak "AnyEvent: unable to create a signal reporting pipe: $!\n"; - $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R, poll => "r", cb => \&_signal_exec); + $SIG_IO = AE::io $SIGPIPE_R, 0, \&_signal_exec; } *signal = sub { @@ -1528,7 +1573,7 @@ : eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1; unless ($CHLD_W) { - $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld); + $CHLD_W = AE::signal CHLD => \&_sigchld; # child could be a zombie already, so make at least one round &_sigchld; } @@ -1564,7 +1609,7 @@ $w = 0.0001 if $w < 0.0001; $w = 5 if $w > 5; - $w = AnyEvent->timer (after => $w, cb => $rcb); + $w = AE::timer $w, 0, $rcb; } else { # clean up... undef $w; @@ -1572,7 +1617,7 @@ } }; - $w = AnyEvent->timer (after => 0.05, cb => $rcb); + $w = AE::timer 0.05, 0, $rcb; bless \\$cb, "AnyEvent::Base::idle" } @@ -1642,6 +1687,7 @@ and $cv->{_ae_cb} = shift and $cv->{_ae_sent} and (delete $cv->{_ae_cb})->($cv); + $cv->{_ae_cb} } @@ -1659,48 +1705,6 @@ *broadcast = \&send; *wait = \&_wait; -############################################################################# -# "new" API, currently only emulation of it -############################################################################# - -package AE; - -sub io($$$) { - AnyEvent->io (fh => $_[0], poll => $_[1] ? "w" : "r", cb => $_[2]) -} - -sub timer($$$) { - AnyEvent->timer (after => $_[0], interval => $_[1], cb => $_[2]); -} - -sub signal($$) { - AnyEvent->signal (signal => $_[0], cb => $_[1]); -} - -sub child($$) { - AnyEvent->child (pid => $_[0], cb => $_[1]); -} - -sub idle($) { - AnyEvent->idle (cb => $_[0]); -} - -sub cv() { - AnyEvent->condvar -} - -sub now() { - AnyEvent->now -} - -sub now_update() { - AnyEvent->now_update -} - -sub time() { - AnyEvent->time -} - =head1 ERROR AND EXCEPTION HANDLING In general, AnyEvent does not do any error handling - it relies on the