… | |
… | |
46 | in a tutorial or some gentle introduction, have a look at the |
46 | in a tutorial or some gentle introduction, have a look at the |
47 | L<AnyEvent::Intro> manpage. |
47 | L<AnyEvent::Intro> manpage. |
48 | |
48 | |
49 | =head1 SUPPORT |
49 | =head1 SUPPORT |
50 | |
50 | |
|
|
51 | An FAQ document is available as L<AnyEvent::FAQ>. |
|
|
52 | |
51 | There is a mailinglist for discussing all things AnyEvent, and an IRC |
53 | There also is a mailinglist for discussing all things AnyEvent, and an IRC |
52 | channel, too. |
54 | channel, too. |
53 | |
55 | |
54 | See the AnyEvent project page at the B<Schmorpforge Ta-Sa Software |
56 | See the AnyEvent project page at the B<Schmorpforge Ta-Sa Software |
55 | Repository>, at L<http://anyevent.schmorp.de>, for more info. |
57 | Repository>, at L<http://anyevent.schmorp.de>, for more info. |
56 | |
58 | |
… | |
… | |
83 | that isn't them. What's worse, all the potential users of your |
85 | that isn't them. What's worse, all the potential users of your |
84 | module are I<also> forced to use the same event loop you use. |
86 | module are I<also> forced to use the same event loop you use. |
85 | |
87 | |
86 | AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works |
88 | AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works |
87 | fine. AnyEvent + Tk works fine etc. etc. but none of these work together |
89 | fine. AnyEvent + Tk works fine etc. etc. but none of these work together |
88 | with the rest: POE + IO::Async? No go. Tk + Event? No go. Again: if |
90 | with the rest: POE + EV? No go. Tk + Event? No go. Again: if your module |
89 | your module uses one of those, every user of your module has to use it, |
91 | uses one of those, every user of your module has to use it, too. But if |
90 | too. But if your module uses AnyEvent, it works transparently with all |
92 | your module uses AnyEvent, it works transparently with all event models it |
91 | event models it supports (including stuff like IO::Async, as long as those |
93 | supports (including stuff like IO::Async, as long as those use one of the |
92 | use one of the supported event loops. It is easy to add new event loops |
94 | supported event loops. It is easy to add new event loops to AnyEvent, too, |
93 | to AnyEvent, too, so it is future-proof). |
95 | so it is future-proof). |
94 | |
96 | |
95 | In addition to being free of having to use I<the one and only true event |
97 | In addition to being free of having to use I<the one and only true event |
96 | model>, AnyEvent also is free of bloat and policy: with POE or similar |
98 | model>, AnyEvent also is free of bloat and policy: with POE or similar |
97 | modules, you get an enormous amount of code and strict rules you have to |
99 | modules, you get an enormous amount of code and strict rules you have to |
98 | follow. AnyEvent, on the other hand, is lean and to the point, by only |
100 | follow. AnyEvent, on the other hand, is lean and to the point, by only |
… | |
… | |
874 | AnyEvent::Impl::Glib based on Glib, slow but very stable. |
876 | AnyEvent::Impl::Glib based on Glib, slow but very stable. |
875 | AnyEvent::Impl::Tk based on Tk, very broken. |
877 | AnyEvent::Impl::Tk based on Tk, very broken. |
876 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
878 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
877 | AnyEvent::Impl::POE based on POE, very slow, some limitations. |
879 | AnyEvent::Impl::POE based on POE, very slow, some limitations. |
878 | 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. |
|
|
882 | AnyEvent::Impl::Cocoa based on Cocoa::EventLoop. |
|
|
883 | AnyEvent::Impl::FLTK based on FLTK. |
879 | |
884 | |
880 | =item Backends with special needs. |
885 | =item Backends with special needs. |
881 | |
886 | |
882 | Qt requires the Qt::Application to be instantiated first, but will |
887 | Qt requires the Qt::Application to be instantiated first, but will |
883 | otherwise be picked up automatically. As long as the main program |
888 | otherwise be picked up automatically. As long as the main program |
884 | instantiates the application before any AnyEvent watchers are created, |
889 | instantiates the application before any AnyEvent watchers are created, |
885 | everything should just work. |
890 | everything should just work. |
886 | |
891 | |
887 | AnyEvent::Impl::Qt based on Qt. |
892 | AnyEvent::Impl::Qt based on Qt. |
888 | |
|
|
889 | Support for IO::Async can only be partial, as it is too broken and |
|
|
890 | architecturally limited to even support the AnyEvent API. It also |
|
|
891 | is the only event loop that needs the loop to be set explicitly, so |
|
|
892 | it can only be used by a main program knowing about AnyEvent. See |
|
|
893 | L<AnyEvent::Impl::IOAsync> for the gory details. |
|
|
894 | |
|
|
895 | AnyEvent::Impl::IOAsync based on IO::Async, cannot be autoprobed. |
|
|
896 | |
893 | |
897 | =item Event loops that are indirectly supported via other backends. |
894 | =item Event loops that are indirectly supported via other backends. |
898 | |
895 | |
899 | Some event loops can be supported via other modules: |
896 | Some event loops can be supported via other modules: |
900 | |
897 | |
… | |
… | |
1155 | |
1152 | |
1156 | package AnyEvent; |
1153 | package AnyEvent; |
1157 | |
1154 | |
1158 | # basically a tuned-down version of common::sense |
1155 | # basically a tuned-down version of common::sense |
1159 | sub common_sense { |
1156 | sub common_sense { |
1160 | # from common:.sense 3.3 |
1157 | # from common:.sense 3.4 |
1161 | ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\x3c\x3f\x33\x00\x0f\xf3\x0f\xc0\xf0\xfc\x33\x00"; |
1158 | ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\x3c\x3f\x33\x00\x0f\xf0\x0f\xc0\xf0\xfc\x33\x00"; |
1162 | # use strict vars subs - NO UTF-8, as Util.pm doesn't like this atm. (uts46data.pl) |
1159 | # use strict vars subs - NO UTF-8, as Util.pm doesn't like this atm. (uts46data.pl) |
1163 | $^H |= 0x00000600; |
1160 | $^H |= 0x00000600; |
1164 | } |
1161 | } |
1165 | |
1162 | |
1166 | BEGIN { AnyEvent::common_sense } |
1163 | BEGIN { AnyEvent::common_sense } |
1167 | |
1164 | |
1168 | use Carp (); |
1165 | use Carp (); |
1169 | |
1166 | |
1170 | our $VERSION = '5.271'; |
1167 | our $VERSION = '5.34'; |
1171 | our $MODEL; |
1168 | our $MODEL; |
1172 | |
1169 | |
1173 | our $AUTOLOAD; |
1170 | our $AUTOLOAD; |
1174 | our @ISA; |
1171 | our @ISA; |
1175 | |
1172 | |
… | |
… | |
1213 | [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles |
1210 | [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles |
1214 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
1211 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
1215 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
1212 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
1216 | [Wx:: => AnyEvent::Impl::POE::], |
1213 | [Wx:: => AnyEvent::Impl::POE::], |
1217 | [Prima:: => AnyEvent::Impl::POE::], |
1214 | [Prima:: => AnyEvent::Impl::POE::], |
1218 | # IO::Async is just too broken - we would need workarounds for its |
|
|
1219 | # byzantine signal and broken child handling, among others. |
|
|
1220 | # IO::Async is rather hard to detect, as it doesn't have any |
|
|
1221 | # obvious default class. |
|
|
1222 | [IO::Async:: => AnyEvent::Impl::IOAsync::], # requires special main program |
|
|
1223 | [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # requires special main program |
1215 | [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], |
1224 | [IO::Async::Notifier:: => AnyEvent::Impl::IOAsync::], # requires special main program |
1216 | [Cocoa::EventLoop:: => AnyEvent::Impl::Cocoa::], |
1225 | [AnyEvent::Impl::IOAsync:: => AnyEvent::Impl::IOAsync::], # requires special main program |
1217 | [FLTK:: => AnyEvent::Impl::FLTK::], |
1226 | ); |
1218 | ); |
1227 | |
1219 | |
1228 | our %method = map +($_ => 1), |
1220 | our %method = map +($_ => 1), |
1229 | qw(io timer time now now_update signal child idle condvar one_event DESTROY); |
1221 | qw(io timer time now now_update signal child idle condvar one_event DESTROY); |
1230 | |
1222 | |
… | |
… | |
1289 | last; |
1281 | last; |
1290 | } |
1282 | } |
1291 | } |
1283 | } |
1292 | |
1284 | |
1293 | $MODEL |
1285 | $MODEL |
1294 | or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: EV, Event or Glib.\n"; |
1286 | or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?\n"; |
1295 | } |
1287 | } |
1296 | } |
1288 | } |
1297 | |
1289 | |
1298 | @models = (); # free probe data |
1290 | @models = (); # free probe data |
1299 | |
1291 | |
1300 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
1292 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
1301 | unshift @ISA, $MODEL; |
1293 | unshift @ISA, $MODEL; |
1302 | |
1294 | |
1303 | # now nuke some methods that are overriden by the backend. |
1295 | # now nuke some methods that are overridden by the backend. |
1304 | # SUPER is not allowed. |
1296 | # SUPER is not allowed. |
1305 | for (qw(time signal child idle)) { |
1297 | for (qw(time signal child idle)) { |
1306 | undef &{"AnyEvent::Base::$_"} |
1298 | undef &{"AnyEvent::Base::$_"} |
1307 | if defined &{"$MODEL\::$_"}; |
1299 | if defined &{"$MODEL\::$_"}; |
1308 | } |
1300 | } |
1309 | |
1301 | |
1310 | require AnyEvent::Strict if $ENV{PERL_ANYEVENT_STRICT}; |
1302 | if ($ENV{PERL_ANYEVENT_STRICT}) { |
|
|
1303 | eval { require AnyEvent::Strict }; |
|
|
1304 | warn "AnyEvent: cannot load AnyEvent::Strict: $@" |
|
|
1305 | if $@ && $VERBOSE; |
|
|
1306 | } |
1311 | |
1307 | |
1312 | (shift @post_detect)->() while @post_detect; |
1308 | (shift @post_detect)->() while @post_detect; |
1313 | |
1309 | |
1314 | *post_detect = sub(&) { |
1310 | *post_detect = sub(&) { |
1315 | shift->(); |
1311 | shift->(); |
… | |
… | |
1622 | # default implementation for ->child |
1618 | # default implementation for ->child |
1623 | |
1619 | |
1624 | our %PID_CB; |
1620 | our %PID_CB; |
1625 | our $CHLD_W; |
1621 | our $CHLD_W; |
1626 | our $CHLD_DELAY_W; |
1622 | our $CHLD_DELAY_W; |
1627 | our $WNOHANG; |
|
|
1628 | |
1623 | |
1629 | # used by many Impl's |
1624 | # used by many Impl's |
1630 | sub _emit_childstatus($$) { |
1625 | sub _emit_childstatus($$) { |
1631 | my (undef, $rpid, $rstatus) = @_; |
1626 | my (undef, $rpid, $rstatus) = @_; |
1632 | |
1627 | |
… | |
… | |
1639 | eval q{ # poor man's autoloading {} |
1634 | eval q{ # poor man's autoloading {} |
1640 | *_sigchld = sub { |
1635 | *_sigchld = sub { |
1641 | my $pid; |
1636 | my $pid; |
1642 | |
1637 | |
1643 | AnyEvent->_emit_childstatus ($pid, $?) |
1638 | AnyEvent->_emit_childstatus ($pid, $?) |
1644 | while ($pid = waitpid -1, $WNOHANG) > 0; |
1639 | while ($pid = waitpid -1, WNOHANG) > 0; |
1645 | }; |
1640 | }; |
1646 | |
1641 | |
1647 | *child = sub { |
1642 | *child = sub { |
1648 | my (undef, %arg) = @_; |
1643 | my (undef, %arg) = @_; |
1649 | |
1644 | |
1650 | defined (my $pid = $arg{pid} + 0) |
1645 | defined (my $pid = $arg{pid} + 0) |
1651 | or Carp::croak "required option 'pid' is missing"; |
1646 | or Carp::croak "required option 'pid' is missing"; |
1652 | |
1647 | |
1653 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
1648 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
1654 | |
|
|
1655 | # WNOHANG is almost cetrainly 1 everywhere |
|
|
1656 | $WNOHANG ||= $^O =~ /^(?:openbsd|netbsd|linux|freebsd|cygwin|MSWin32)$/ |
|
|
1657 | ? 1 |
|
|
1658 | : eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1; |
|
|
1659 | |
1649 | |
1660 | unless ($CHLD_W) { |
1650 | unless ($CHLD_W) { |
1661 | $CHLD_W = AE::signal CHLD => \&_sigchld; |
1651 | $CHLD_W = AE::signal CHLD => \&_sigchld; |
1662 | # child could be a zombie already, so make at least one round |
1652 | # child could be a zombie already, so make at least one round |
1663 | &_sigchld; |
1653 | &_sigchld; |
… | |
… | |
2658 | pronounced). |
2648 | pronounced). |
2659 | |
2649 | |
2660 | |
2650 | |
2661 | =head1 SEE ALSO |
2651 | =head1 SEE ALSO |
2662 | |
2652 | |
|
|
2653 | Tutorial/Introduction: L<AnyEvent::Intro>. |
|
|
2654 | |
|
|
2655 | FAQ: L<AnyEvent::FAQ>. |
|
|
2656 | |
2663 | Utility functions: L<AnyEvent::Util>. |
2657 | Utility functions: L<AnyEvent::Util>. |
2664 | |
2658 | |
2665 | Event modules: L<EV>, L<EV::Glib>, L<Glib::EV>, L<Event>, L<Glib::Event>, |
2659 | Event modules: L<EV>, L<EV::Glib>, L<Glib::EV>, L<Event>, L<Glib::Event>, |
2666 | L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. |
2660 | L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. |
2667 | |
2661 | |
… | |
… | |
2673 | Non-blocking file handles, sockets, TCP clients and |
2667 | Non-blocking file handles, sockets, TCP clients and |
2674 | servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>. |
2668 | servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>. |
2675 | |
2669 | |
2676 | Asynchronous DNS: L<AnyEvent::DNS>. |
2670 | Asynchronous DNS: L<AnyEvent::DNS>. |
2677 | |
2671 | |
2678 | Coroutine support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, |
2672 | Thread support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>. |
2679 | L<Coro::Event>, |
|
|
2680 | |
2673 | |
2681 | Nontrivial usage examples: L<AnyEvent::GPSD>, L<AnyEvent::XMPP>, |
2674 | Nontrivial usage examples: L<AnyEvent::GPSD>, L<AnyEvent::IRC>, |
2682 | L<AnyEvent::HTTP>. |
2675 | L<AnyEvent::HTTP>. |
2683 | |
2676 | |
2684 | |
2677 | |
2685 | =head1 AUTHOR |
2678 | =head1 AUTHOR |
2686 | |
2679 | |