… | |
… | |
1167 | |
1167 | |
1168 | BEGIN { AnyEvent::common_sense } |
1168 | BEGIN { AnyEvent::common_sense } |
1169 | |
1169 | |
1170 | use Carp (); |
1170 | use Carp (); |
1171 | |
1171 | |
1172 | our $VERSION = '5.271'; |
1172 | our $VERSION = '5.29'; |
1173 | our $MODEL; |
1173 | our $MODEL; |
1174 | |
1174 | |
1175 | our $AUTOLOAD; |
1175 | our $AUTOLOAD; |
1176 | our @ISA; |
1176 | our @ISA; |
1177 | |
1177 | |
… | |
… | |
1291 | last; |
1291 | last; |
1292 | } |
1292 | } |
1293 | } |
1293 | } |
1294 | |
1294 | |
1295 | $MODEL |
1295 | $MODEL |
1296 | or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: EV, Event or Glib.\n"; |
1296 | or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?\n"; |
1297 | } |
1297 | } |
1298 | } |
1298 | } |
1299 | |
1299 | |
1300 | @models = (); # free probe data |
1300 | @models = (); # free probe data |
1301 | |
1301 | |
1302 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
1302 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
1303 | unshift @ISA, $MODEL; |
1303 | unshift @ISA, $MODEL; |
1304 | |
1304 | |
1305 | # now nuke some methods that are overriden by the backend. |
1305 | # now nuke some methods that are overridden by the backend. |
1306 | # SUPER is not allowed. |
1306 | # SUPER is not allowed. |
1307 | for (qw(time signal child idle)) { |
1307 | for (qw(time signal child idle)) { |
1308 | undef &{"AnyEvent::Base::$_"} |
1308 | undef &{"AnyEvent::Base::$_"} |
1309 | if defined &{"$MODEL\::$_"}; |
1309 | if defined &{"$MODEL\::$_"}; |
1310 | } |
1310 | } |
1311 | |
1311 | |
1312 | require AnyEvent::Strict if $ENV{PERL_ANYEVENT_STRICT}; |
1312 | if ($ENV{PERL_ANYEVENT_STRICT}) { |
|
|
1313 | eval { require AnyEvent::Strict }; |
|
|
1314 | warn "AnyEvent: cannot load AnyEvent::Strict: $@" |
|
|
1315 | if $@ && $VERBOSE; |
|
|
1316 | } |
1313 | |
1317 | |
1314 | (shift @post_detect)->() while @post_detect; |
1318 | (shift @post_detect)->() while @post_detect; |
1315 | |
1319 | |
1316 | *post_detect = sub(&) { |
1320 | *post_detect = sub(&) { |
1317 | shift->(); |
1321 | shift->(); |
… | |
… | |
1624 | # default implementation for ->child |
1628 | # default implementation for ->child |
1625 | |
1629 | |
1626 | our %PID_CB; |
1630 | our %PID_CB; |
1627 | our $CHLD_W; |
1631 | our $CHLD_W; |
1628 | our $CHLD_DELAY_W; |
1632 | our $CHLD_DELAY_W; |
1629 | our $WNOHANG; |
|
|
1630 | |
1633 | |
1631 | # used by many Impl's |
1634 | # used by many Impl's |
1632 | sub _emit_childstatus($$) { |
1635 | sub _emit_childstatus($$) { |
1633 | my (undef, $rpid, $rstatus) = @_; |
1636 | my (undef, $rpid, $rstatus) = @_; |
1634 | |
1637 | |
… | |
… | |
1641 | eval q{ # poor man's autoloading {} |
1644 | eval q{ # poor man's autoloading {} |
1642 | *_sigchld = sub { |
1645 | *_sigchld = sub { |
1643 | my $pid; |
1646 | my $pid; |
1644 | |
1647 | |
1645 | AnyEvent->_emit_childstatus ($pid, $?) |
1648 | AnyEvent->_emit_childstatus ($pid, $?) |
1646 | while ($pid = waitpid -1, $WNOHANG) > 0; |
1649 | while ($pid = waitpid -1, WNOHANG) > 0; |
1647 | }; |
1650 | }; |
1648 | |
1651 | |
1649 | *child = sub { |
1652 | *child = sub { |
1650 | my (undef, %arg) = @_; |
1653 | my (undef, %arg) = @_; |
1651 | |
1654 | |
1652 | defined (my $pid = $arg{pid} + 0) |
1655 | defined (my $pid = $arg{pid} + 0) |
1653 | or Carp::croak "required option 'pid' is missing"; |
1656 | or Carp::croak "required option 'pid' is missing"; |
1654 | |
1657 | |
1655 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
1658 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
1656 | |
|
|
1657 | # WNOHANG is almost cetrainly 1 everywhere |
|
|
1658 | $WNOHANG ||= $^O =~ /^(?:openbsd|netbsd|linux|freebsd|cygwin|MSWin32)$/ |
|
|
1659 | ? 1 |
|
|
1660 | : eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1; |
|
|
1661 | |
1659 | |
1662 | unless ($CHLD_W) { |
1660 | unless ($CHLD_W) { |
1663 | $CHLD_W = AE::signal CHLD => \&_sigchld; |
1661 | $CHLD_W = AE::signal CHLD => \&_sigchld; |
1664 | # child could be a zombie already, so make at least one round |
1662 | # child could be a zombie already, so make at least one round |
1665 | &_sigchld; |
1663 | &_sigchld; |