ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.174 by root, Thu Jul 24 06:40:22 2008 UTC vs.
Revision 1.180 by root, Sat Sep 6 07:00:45 2008 UTC

850=cut 850=cut
851 851
852package AnyEvent; 852package AnyEvent;
853 853
854no warnings; 854no warnings;
855use strict; 855use strict qw(vars subs);
856 856
857use Carp; 857use Carp;
858 858
859our $VERSION = 4.22; 859our $VERSION = 4.233;
860our $MODEL; 860our $MODEL;
861 861
862our $AUTOLOAD; 862our $AUTOLOAD;
863our @ISA; 863our @ISA;
864 864
1016 1016
1017package AnyEvent::Base; 1017package AnyEvent::Base;
1018 1018
1019# default implementation for now and time 1019# default implementation for now and time
1020 1020
1021use Time::HiRes (); 1021BEGIN {
1022 if (eval "use Time::HiRes (); time (); 1") {
1023 *_time = \&Time::HiRes::time;
1024 # if (eval "use POSIX (); (POSIX::times())...
1025 } else {
1026 *_time = \&CORE::time; # epic fail
1027 }
1028}
1022 1029
1023sub time { Time::HiRes::time } 1030sub time { _time }
1024sub now { Time::HiRes::time } 1031sub now { _time }
1025 1032
1026# default implementation for ->condvar 1033# default implementation for ->condvar
1027 1034
1028sub condvar { 1035sub condvar {
1029 bless { @_ == 3 ? (_ae_cb => $_[2]) : () }, AnyEvent::CondVar:: 1036 bless { @_ == 3 ? (_ae_cb => $_[2]) : () }, AnyEvent::CondVar::
1168 1175
1169# undocumented/compatibility with pre-3.4 1176# undocumented/compatibility with pre-3.4
1170*broadcast = \&send; 1177*broadcast = \&send;
1171*wait = \&_wait; 1178*wait = \&_wait;
1172 1179
1180=head1 ERROR AND EXCEPTION HANDLING
1181
1182In general, AnyEvent does not do any error handling - it relies on the
1183caller to do that if required. The L<AnyEvent::Strict> module (see also
1184the C<PERL_ANYEVENT_STRICT> environment variable, below) provides strict
1185checking of all AnyEvent methods, however, which is highly useful during
1186development.
1187
1188As for exception handling (i.e. runtime errors and exceptions thrown while
1189executing a callback), this is not only highly event-loop specific, but
1190also not in any way wrapped by this module, as this is the job of the main
1191program.
1192
1193The pure perl event loop simply re-throws the exception (usually
1194within C<< condvar->recv >>), the L<Event> and L<EV> modules call C<<
1195$Event/EV::DIED->() >>, L<Glib> uses C<< install_exception_handler >> and
1196so on.
1197
1198=head1 ENVIRONMENT VARIABLES
1199
1200The following environment variables are used by this module or its
1201submodules:
1202
1203=over 4
1204
1205=item C<PERL_ANYEVENT_VERBOSE>
1206
1207By default, AnyEvent will be completely silent except in fatal
1208conditions. You can set this environment variable to make AnyEvent more
1209talkative.
1210
1211When set to C<1> or higher, causes AnyEvent to warn about unexpected
1212conditions, such as not being able to load the event model specified by
1213C<PERL_ANYEVENT_MODEL>.
1214
1215When set to C<2> or higher, cause AnyEvent to report to STDERR which event
1216model it chooses.
1217
1218=item C<PERL_ANYEVENT_STRICT>
1219
1220AnyEvent does not do much argument checking by default, as thorough
1221argument checking is very costly. Setting this variable to a true value
1222will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly
1223check the arguments passed to most method calls. If it finds any problems
1224it will croak.
1225
1226In other words, enables "strict" mode.
1227
1228Unlike C<use strict>, it is definitely recommended ot keep it off in
1229production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while
1230developing programs can be very useful, however.
1231
1232=item C<PERL_ANYEVENT_MODEL>
1233
1234This can be used to specify the event model to be used by AnyEvent, before
1235auto detection and -probing kicks in. It must be a string consisting
1236entirely of ASCII letters. The string C<AnyEvent::Impl::> gets prepended
1237and the resulting module name is loaded and if the load was successful,
1238used as event model. If it fails to load AnyEvent will proceed with
1239auto detection and -probing.
1240
1241This functionality might change in future versions.
1242
1243For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you
1244could start your program like this:
1245
1246 PERL_ANYEVENT_MODEL=Perl perl ...
1247
1248=item C<PERL_ANYEVENT_PROTOCOLS>
1249
1250Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences
1251for IPv4 or IPv6. The default is unspecified (and might change, or be the result
1252of auto probing).
1253
1254Must be set to a comma-separated list of protocols or address families,
1255current supported: C<ipv4> and C<ipv6>. Only protocols mentioned will be
1256used, and preference will be given to protocols mentioned earlier in the
1257list.
1258
1259This variable can effectively be used for denial-of-service attacks
1260against local programs (e.g. when setuid), although the impact is likely
1261small, as the program has to handle connection errors already-
1262
1263Examples: C<PERL_ANYEVENT_PROTOCOLS=ipv4,ipv6> - prefer IPv4 over IPv6,
1264but support both and try to use both. C<PERL_ANYEVENT_PROTOCOLS=ipv4>
1265- only support IPv4, never try to resolve or contact IPv6
1266addresses. C<PERL_ANYEVENT_PROTOCOLS=ipv6,ipv4> support either IPv4 or
1267IPv6, but prefer IPv6 over IPv4.
1268
1269=item C<PERL_ANYEVENT_EDNS0>
1270
1271Used by L<AnyEvent::DNS> to decide whether to use the EDNS0 extension
1272for DNS. This extension is generally useful to reduce DNS traffic, but
1273some (broken) firewalls drop such DNS packets, which is why it is off by
1274default.
1275
1276Setting this variable to C<1> will cause L<AnyEvent::DNS> to announce
1277EDNS0 in its DNS requests.
1278
1279=item C<PERL_ANYEVENT_MAX_FORKS>
1280
1281The maximum number of child processes that C<AnyEvent::Util::fork_call>
1282will create in parallel.
1283
1284=back
1285
1173=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE 1286=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE
1174 1287
1175This is an advanced topic that you do not normally need to use AnyEvent in 1288This is an advanced topic that you do not normally need to use AnyEvent in
1176a module. This section is only of use to event loop authors who want to 1289a module. This section is only of use to event loop authors who want to
1177provide AnyEvent compatibility. 1290provide AnyEvent compatibility.
1210 1323
1211I<rxvt-unicode> also cheats a bit by not providing blocking access to 1324I<rxvt-unicode> also cheats a bit by not providing blocking access to
1212condition variables: code blocking while waiting for a condition will 1325condition variables: code blocking while waiting for a condition will
1213C<die>. This still works with most modules/usages, and blocking calls must 1326C<die>. This still works with most modules/usages, and blocking calls must
1214not be done in an interactive application, so it makes sense. 1327not be done in an interactive application, so it makes sense.
1215
1216=head1 ENVIRONMENT VARIABLES
1217
1218The following environment variables are used by this module:
1219
1220=over 4
1221
1222=item C<PERL_ANYEVENT_VERBOSE>
1223
1224By default, AnyEvent will be completely silent except in fatal
1225conditions. You can set this environment variable to make AnyEvent more
1226talkative.
1227
1228When set to C<1> or higher, causes AnyEvent to warn about unexpected
1229conditions, such as not being able to load the event model specified by
1230C<PERL_ANYEVENT_MODEL>.
1231
1232When set to C<2> or higher, cause AnyEvent to report to STDERR which event
1233model it chooses.
1234
1235=item C<PERL_ANYEVENT_STRICT>
1236
1237AnyEvent does not do much argument checking by default, as thorough
1238argument checking is very costly. Setting this variable to a true value
1239will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly
1240check the arguments passed to most method calls. If it finds any problems
1241it will croak.
1242
1243In other words, enables "strict" mode.
1244
1245Unlike C<use strict> it is definitely recommended ot keep it off in
1246production.
1247
1248=item C<PERL_ANYEVENT_MODEL>
1249
1250This can be used to specify the event model to be used by AnyEvent, before
1251auto detection and -probing kicks in. It must be a string consisting
1252entirely of ASCII letters. The string C<AnyEvent::Impl::> gets prepended
1253and the resulting module name is loaded and if the load was successful,
1254used as event model. If it fails to load AnyEvent will proceed with
1255auto detection and -probing.
1256
1257This functionality might change in future versions.
1258
1259For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you
1260could start your program like this:
1261
1262 PERL_ANYEVENT_MODEL=Perl perl ...
1263
1264=item C<PERL_ANYEVENT_PROTOCOLS>
1265
1266Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences
1267for IPv4 or IPv6. The default is unspecified (and might change, or be the result
1268of auto probing).
1269
1270Must be set to a comma-separated list of protocols or address families,
1271current supported: C<ipv4> and C<ipv6>. Only protocols mentioned will be
1272used, and preference will be given to protocols mentioned earlier in the
1273list.
1274
1275This variable can effectively be used for denial-of-service attacks
1276against local programs (e.g. when setuid), although the impact is likely
1277small, as the program has to handle connection errors already-
1278
1279Examples: C<PERL_ANYEVENT_PROTOCOLS=ipv4,ipv6> - prefer IPv4 over IPv6,
1280but support both and try to use both. C<PERL_ANYEVENT_PROTOCOLS=ipv4>
1281- only support IPv4, never try to resolve or contact IPv6
1282addresses. C<PERL_ANYEVENT_PROTOCOLS=ipv6,ipv4> support either IPv4 or
1283IPv6, but prefer IPv6 over IPv4.
1284
1285=item C<PERL_ANYEVENT_EDNS0>
1286
1287Used by L<AnyEvent::DNS> to decide whether to use the EDNS0 extension
1288for DNS. This extension is generally useful to reduce DNS traffic, but
1289some (broken) firewalls drop such DNS packets, which is why it is off by
1290default.
1291
1292Setting this variable to C<1> will cause L<AnyEvent::DNS> to announce
1293EDNS0 in its DNS requests.
1294
1295=item C<PERL_ANYEVENT_MAX_FORKS>
1296
1297The maximum number of child processes that C<AnyEvent::Util::fork_call>
1298will create in parallel.
1299
1300=back
1301 1328
1302=head1 EXAMPLE PROGRAM 1329=head1 EXAMPLE PROGRAM
1303 1330
1304The following program uses an I/O watcher to read data from STDIN, a timer 1331The following program uses an I/O watcher to read data from STDIN, a timer
1305to display a message once per second, and a condition variable to quit the 1332to display a message once per second, and a condition variable to quit the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines