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

Comparing EV/EV.pm (file contents):
Revision 1.40 by root, Fri Nov 16 05:04:36 2007 UTC vs.
Revision 1.46 by root, Fri Nov 23 05:00:44 2007 UTC

57package EV; 57package EV;
58 58
59use strict; 59use strict;
60 60
61BEGIN { 61BEGIN {
62 our $VERSION = '0.9'; 62 our $VERSION = '1.2';
63 use XSLoader; 63 use XSLoader;
64 XSLoader::load "EV", $VERSION; 64 XSLoader::load "EV", $VERSION;
65} 65}
66 66
67@EV::Io::ISA = 67@EV::Io::ISA =
93 93
94Returns the time the last event loop iteration has been started. This 94Returns the time the last event loop iteration has been started. This
95is the time that (relative) timers are based on, and refering to it is 95is the time that (relative) timers are based on, and refering to it is
96usually faster then calling EV::time. 96usually faster then calling EV::time.
97 97
98=item $method = EV::ev_method 98=item $method = EV::method
99 99
100Returns an integer describing the backend used by libev (EV::METHOD_SELECT 100Returns an integer describing the backend used by libev (EV::METHOD_SELECT
101or EV::METHOD_EPOLL). 101or EV::METHOD_EPOLL).
102 102
103=item EV::loop [$flags] 103=item EV::loop [$flags]
493 # do nothing unless active 493 # do nothing unless active
494 $dispatcher->{_event_queue_h} 494 $dispatcher->{_event_queue_h}
495 or return; 495 or return;
496 496
497 # make the dispatcher handle any outstanding stuff 497 # make the dispatcher handle any outstanding stuff
498 ... not shown
498 499
499 # create an IO watcher for each and every socket 500 # create an IO watcher for each and every socket
500 @snmp_watcher = ( 501 @snmp_watcher = (
501 (map { EV::io $_, EV::READ, sub { } } 502 (map { EV::io $_, EV::READ, sub { } }
502 keys %{ $dispatcher->{_descriptors} }), 503 keys %{ $dispatcher->{_descriptors} }),
504
505 EV::timer +($event->[Net::SNMP::Dispatcher::_ACTIVE]
506 ? $event->[Net::SNMP::Dispatcher::_TIME] - EV::now : 0),
507 0, sub { },
503 ); 508 );
504
505 # if there are any timeouts, also create a timer
506 push @snmp_watcher, EV::timer $event->[Net::SNMP::Dispatcher::_TIME] - EV::now, 0, sub { }
507 if $event->[Net::SNMP::Dispatcher::_ACTIVE];
508 }; 509 };
509 510
510The callbacks are irrelevant, the only purpose of those watchers is 511The callbacks are irrelevant (and are not even being called), the
511to wake up the process as soon as one of those events occurs (socket 512only purpose of those watchers is to wake up the process as soon as
512readable, or timer timed out). The corresponding EV::check watcher will then 513one of those events occurs (socket readable, or timer timed out). The
513clean up: 514corresponding EV::check watcher will then clean up:
514 515
515 our $snmp_check = EV::check sub { 516 our $snmp_check = EV::check sub {
516 # destroy all watchers 517 # destroy all watchers
517 @snmp_watcher = (); 518 @snmp_watcher = ();
518 519
519 # make the dispatcher handle any new stuff 520 # make the dispatcher handle any new stuff
521 ... not shown
520 }; 522 };
521 523
522The callbacks of the created watchers will not be called as the watchers 524The callbacks of the created watchers will not be called as the watchers
523are destroyed before this cna happen (remember EV::check gets called 525are destroyed before this cna happen (remember EV::check gets called
524first). 526first).
527 529
528=back 530=back
529 531
530=head1 THREADS 532=head1 THREADS
531 533
532Threads are not supported by this in any way. Perl pseudo-threads is evil 534Threads are not supported by this module in any way. Perl pseudo-threads
533stuff and must die. 535is evil stuff and must die. As soon as Perl gains real threads I will work
536on thread support for it.
537
538=head1 FORK
539
540Most of the "improved" event delivering mechanisms of modern operating
541systems have quite a few problems with fork(2) (to put it bluntly: it is
542not supported and usually destructive). Libev makes it possible to work
543around this by having a function that recreates the kernel state after
544fork in the child.
545
546On non-win32 platforms, this module requires the pthread_atfork
547functionality to do this automatically for you. This function is quite
548buggy on most BSDs, though, so YMMV. The overhead for this is quite
549negligible, because everything the function currently does is set a flag
550that is checked only when the event loop gets used the next time, so when
551you do fork but not use EV, the overhead is minimal.
552
553On win32, there is no notion of fork so all this doesn't apply, of course.
534 554
535=cut 555=cut
536 556
537our $DIED = sub { 557our $DIED = sub {
538 warn "EV: error in callback (ignoring): $@"; 558 warn "EV: error in callback (ignoring): $@";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines