AnyEvent::Loop and $_

Mons Anderson mons at rambler-co.ru
Fri Feb 10 06:23:30 CET 2012


Hello, Marc.

I've found a bad condition, when io watcher in pure-perl loop became broken

If there is a modification of $_ in AE::io callback, then either io 
watcher never get called again or there will be a garbage instead of 
AE::Loop::io object and code will die.

I propose either localize $_ or use my variable

Istead of

    $_ && $_->[2]()
       for @{ $fds->[W][(pos) - 1] || [] };

Use

    for my $io ( @{ $fds->[W][(pos) - 1] || [] } ) {
       $io && $io->[2]();
    }


-- 
Mons Anderson aka Vladimir Perepelitsa
<mons at rambler-co.ru>
Skype: inthrax; ICQ: 99779956




More information about the anyevent mailing list