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.287 by root, Tue Aug 25 12:05:30 2009 UTC vs.
Revision 1.297 by root, Thu Nov 19 01:55:57 2009 UTC

362this "current" time will differ substantially from the real time, which 362this "current" time will differ substantially from the real time, which
363might affect timers and time-outs. 363might affect timers and time-outs.
364 364
365When this is the case, you can call this method, which will update the 365When this is the case, you can call this method, which will update the
366event loop's idea of "current time". 366event loop's idea of "current time".
367
368A typical example would be a script in a web server (e.g. C<mod_perl>) -
369when mod_perl executes the script, then the event loop will have the wrong
370idea about the "current time" (being potentially far in the past, when the
371script ran the last time). In that case you should arrange a call to C<<
372AnyEvent->now_update >> each time the web server process wakes up again
373(e.g. at the start of your script, or in a handler).
367 374
368Note that updating the time I<might> cause some events to be handled. 375Note that updating the time I<might> cause some events to be handled.
369 376
370=back 377=back
371 378
1106 1113
1107package AnyEvent; 1114package AnyEvent;
1108 1115
1109# basically a tuned-down version of common::sense 1116# basically a tuned-down version of common::sense
1110sub common_sense { 1117sub common_sense {
1111 # no warnings 1118 # from common:.sense 1.0
1112 ${^WARNING_BITS} ^= ${^WARNING_BITS}; 1119 ${^WARNING_BITS} = "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03";
1113 # use strict vars subs 1120 # use strict vars subs
1114 $^H |= 0x00000600; 1121 $^H |= 0x00000600;
1115} 1122}
1116 1123
1117BEGIN { AnyEvent::common_sense } 1124BEGIN { AnyEvent::common_sense }
1118 1125
1119use Carp (); 1126use Carp ();
1120 1127
1121our $VERSION = '5.112'; 1128our $VERSION = '5.21';
1122our $MODEL; 1129our $MODEL;
1123 1130
1124our $AUTOLOAD; 1131our $AUTOLOAD;
1125our @ISA; 1132our @ISA;
1126 1133
1127our @REGISTRY; 1134our @REGISTRY;
1128
1129our $WIN32;
1130 1135
1131our $VERBOSE; 1136our $VERBOSE;
1132 1137
1133BEGIN { 1138BEGIN {
1134 eval "sub WIN32(){ " . (($^O =~ /mswin32/i)*1) ." }"; 1139 eval "sub WIN32(){ " . (($^O =~ /mswin32/i)*1) ." }";
1343 1348
1344package AnyEvent::Base; 1349package AnyEvent::Base;
1345 1350
1346# default implementations for many methods 1351# default implementations for many methods
1347 1352
1348sub _time { 1353sub _time() {
1349 # probe for availability of Time::HiRes 1354 # probe for availability of Time::HiRes
1350 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { 1355 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") {
1351 warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8; 1356 warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8;
1352 *_time = \&Time::HiRes::time; 1357 *_time = \&Time::HiRes::time;
1353 # if (eval "use POSIX (); (POSIX::times())... 1358 # if (eval "use POSIX (); (POSIX::times())...
1373 1378
1374our $HAVE_ASYNC_INTERRUPT; 1379our $HAVE_ASYNC_INTERRUPT;
1375 1380
1376sub _have_async_interrupt() { 1381sub _have_async_interrupt() {
1377 $HAVE_ASYNC_INTERRUPT = 1*(!$ENV{PERL_ANYEVENT_AVOID_ASYNC_INTERRUPT} 1382 $HAVE_ASYNC_INTERRUPT = 1*(!$ENV{PERL_ANYEVENT_AVOID_ASYNC_INTERRUPT}
1378 && eval "use Async::Interrupt 1.0 (); 1") 1383 && eval "use Async::Interrupt 1.02 (); 1")
1379 unless defined $HAVE_ASYNC_INTERRUPT; 1384 unless defined $HAVE_ASYNC_INTERRUPT;
1380 1385
1381 $HAVE_ASYNC_INTERRUPT 1386 $HAVE_ASYNC_INTERRUPT
1382} 1387}
1383 1388
1386our ($SIG_COUNT, $SIG_TW); 1391our ($SIG_COUNT, $SIG_TW);
1387 1392
1388sub _signal_exec { 1393sub _signal_exec {
1389 $HAVE_ASYNC_INTERRUPT 1394 $HAVE_ASYNC_INTERRUPT
1390 ? $SIGPIPE_R->drain 1395 ? $SIGPIPE_R->drain
1391 : sysread $SIGPIPE_R, my $dummy, 9; 1396 : sysread $SIGPIPE_R, (my $dummy), 9;
1392 1397
1393 while (%SIG_EV) { 1398 while (%SIG_EV) {
1394 for (keys %SIG_EV) { 1399 for (keys %SIG_EV) {
1395 delete $SIG_EV{$_}; 1400 delete $SIG_EV{$_};
1396 $_->() for values %{ $SIG_CB{$_} || {} }; 1401 $_->() for values %{ $SIG_CB{$_} || {} };
2368As you can see, the AnyEvent + EV combination even beats the 2373As you can see, the AnyEvent + EV combination even beats the
2369hand-optimised "raw sockets benchmark", while AnyEvent + its pure perl 2374hand-optimised "raw sockets benchmark", while AnyEvent + its pure perl
2370backend easily beats IO::Lambda and POE. 2375backend easily beats IO::Lambda and POE.
2371 2376
2372And even the 100% non-blocking version written using the high-level (and 2377And even the 100% non-blocking version written using the high-level (and
2373slow :) L<AnyEvent::Handle> abstraction beats both POE and IO::Lambda by a 2378slow :) L<AnyEvent::Handle> abstraction beats both POE and IO::Lambda
2374large margin, even though it does all of DNS, tcp-connect and socket I/O 2379higher level ("unoptimised") abstractions by a large margin, even though
2375in a non-blocking way. 2380it does all of DNS, tcp-connect and socket I/O in a non-blocking way.
2376 2381
2377The two AnyEvent benchmarks programs can be found as F<eg/ae0.pl> and 2382The two AnyEvent benchmarks programs can be found as F<eg/ae0.pl> and
2378F<eg/ae2.pl> in the AnyEvent distribution, the remaining benchmarks are 2383F<eg/ae2.pl> in the AnyEvent distribution, the remaining benchmarks are
2379part of the IO::lambda distribution and were used without any changes. 2384part of the IO::Lambda distribution and were used without any changes.
2380 2385
2381 2386
2382=head1 SIGNALS 2387=head1 SIGNALS
2383 2388
2384AnyEvent currently installs handlers for these signals: 2389AnyEvent currently installs handlers for these signals:
2473lot less memory), but otherwise doesn't affect guard operation much. It is 2478lot less memory), but otherwise doesn't affect guard operation much. It is
2474purely used for performance. 2479purely used for performance.
2475 2480
2476=item L<JSON> and L<JSON::XS> 2481=item L<JSON> and L<JSON::XS>
2477 2482
2478This module is required when you want to read or write JSON data via 2483One of these modules is required when you want to read or write JSON data
2479L<AnyEvent::Handle>. It is also written in pure-perl, but can take 2484via L<AnyEvent::Handle>. It is also written in pure-perl, but can take
2480advantage of the ultra-high-speed L<JSON::XS> module when it is installed. 2485advantage of the ultra-high-speed L<JSON::XS> module when it is installed.
2481 2486
2482In fact, L<AnyEvent::Handle> will use L<JSON::XS> by default if it is 2487In fact, L<AnyEvent::Handle> will use L<JSON::XS> by default if it is
2483installed. 2488installed.
2484 2489

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines