… | |
… | |
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 | |
510 | The callbacks are irrelevant, the only purpose of those watchers is |
511 | The callbacks are irrelevant (and are not even being called), the |
511 | to wake up the process as soon as one of those events occurs (socket |
512 | only purpose of those watchers is to wake up the process as soon as |
512 | readable, or timer timed out). The corresponding EV::check watcher will then |
513 | one of those events occurs (socket readable, or timer timed out). The |
513 | clean up: |
514 | corresponding 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 | |
522 | The callbacks of the created watchers will not be called as the watchers |
524 | The callbacks of the created watchers will not be called as the watchers |
523 | are destroyed before this cna happen (remember EV::check gets called |
525 | are destroyed before this cna happen (remember EV::check gets called |
524 | first). |
526 | first). |
… | |
… | |
527 | |
529 | |
528 | =back |
530 | =back |
529 | |
531 | |
530 | =head1 THREADS |
532 | =head1 THREADS |
531 | |
533 | |
532 | Threads are not supported by this in any way. Perl pseudo-threads is evil |
534 | Threads are not supported by this module in any way. Perl pseudo-threads |
533 | stuff and must die. |
535 | is evil stuff and must die. As soon as Perl gains real threads I will work |
|
|
536 | on thread support for it. |
|
|
537 | |
|
|
538 | =head1 FORK |
|
|
539 | |
|
|
540 | Most of the "improved" event delivering mechanisms of modern operating |
|
|
541 | systems have quite a few problems with fork(2) (to put it bluntly: it is |
|
|
542 | not supported and usually destructive). Libev makes it possible to work |
|
|
543 | around this by having a function that recreates the kernel state after |
|
|
544 | fork in the child. |
|
|
545 | |
|
|
546 | On non-win32 platforms, this module requires the pthread_atfork |
|
|
547 | functionality to do this automatically for you. This function is quite |
|
|
548 | buggy on most BSDs, though, so YMMV. The overhead for this is quite |
|
|
549 | negligible, because everything the function currently does is set a flag |
|
|
550 | that is checked only when the event loop gets used the next time, so when |
|
|
551 | you do fork but not use EV, the overhead is minimal. |
|
|
552 | |
|
|
553 | On win32, there is no notion of fork so all this doesn't apply, of course. |
534 | |
554 | |
535 | =cut |
555 | =cut |
536 | |
556 | |
537 | our $DIED = sub { |
557 | our $DIED = sub { |
538 | warn "EV: error in callback (ignoring): $@"; |
558 | warn "EV: error in callback (ignoring): $@"; |