… | |
… | |
520 | C<send> or C<croak> are called. Calling C<recv> inside the callback |
520 | C<send> or C<croak> are called. Calling C<recv> inside the callback |
521 | or at any later time is guaranteed not to block. |
521 | or at any later time is guaranteed not to block. |
522 | |
522 | |
523 | =back |
523 | =back |
524 | |
524 | |
525 | =head3 MAINLOOP EMULATION |
|
|
526 | |
|
|
527 | Sometimes (often for short test scripts, or even standalone programs |
|
|
528 | who only want to use AnyEvent), you I<do> want your program to block |
|
|
529 | indefinitely in some event loop. |
|
|
530 | |
|
|
531 | In that case, you cna use a condition variable like this: |
|
|
532 | |
|
|
533 | AnyEvent->condvar->recv; |
|
|
534 | |
|
|
535 | This has the effect of entering the event loop and looping forever. |
|
|
536 | |
|
|
537 | Note that usually your program has some exit condition, in which case |
|
|
538 | it is better to use the "traditional" approach of storing a condition |
|
|
539 | variable, waiting for it, and sending it when the program should exit |
|
|
540 | cleanly. |
|
|
541 | |
|
|
542 | |
|
|
543 | =head1 GLOBAL VARIABLES AND FUNCTIONS |
525 | =head1 GLOBAL VARIABLES AND FUNCTIONS |
544 | |
526 | |
545 | =over 4 |
527 | =over 4 |
546 | |
528 | |
547 | =item $AnyEvent::MODEL |
529 | =item $AnyEvent::MODEL |
… | |
… | |
630 | |
612 | |
631 | If it doesn't care, it can just "use AnyEvent" and use it itself, or not |
613 | If it doesn't care, it can just "use AnyEvent" and use it itself, or not |
632 | do anything special (it does not need to be event-based) and let AnyEvent |
614 | do anything special (it does not need to be event-based) and let AnyEvent |
633 | decide which implementation to chose if some module relies on it. |
615 | decide which implementation to chose if some module relies on it. |
634 | |
616 | |
635 | If the main program relies on a specific event model. For example, in |
617 | If the main program relies on a specific event model - for example, in |
636 | Gtk2 programs you have to rely on the Glib module. You should load the |
618 | Gtk2 programs you have to rely on the Glib module - you should load the |
637 | event module before loading AnyEvent or any module that uses it: generally |
619 | event module before loading AnyEvent or any module that uses it: generally |
638 | speaking, you should load it as early as possible. The reason is that |
620 | speaking, you should load it as early as possible. The reason is that |
639 | modules might create watchers when they are loaded, and AnyEvent will |
621 | modules might create watchers when they are loaded, and AnyEvent will |
640 | decide on the event model to use as soon as it creates watchers, and it |
622 | decide on the event model to use as soon as it creates watchers, and it |
641 | might chose the wrong one unless you load the correct one yourself. |
623 | might chose the wrong one unless you load the correct one yourself. |
642 | |
624 | |
643 | You can chose to use a rather inefficient pure-perl implementation by |
625 | You can chose to use a pure-perl implementation by loading the |
644 | loading the C<AnyEvent::Impl::Perl> module, which gives you similar |
626 | C<AnyEvent::Impl::Perl> module, which gives you similar behaviour |
645 | behaviour everywhere, but letting AnyEvent chose is generally better. |
627 | everywhere, but letting AnyEvent chose the model is generally better. |
|
|
628 | |
|
|
629 | =head2 MAINLOOP EMULATION |
|
|
630 | |
|
|
631 | Sometimes (often for short test scripts, or even standalone programs who |
|
|
632 | only want to use AnyEvent), you do not want to run a specific event loop. |
|
|
633 | |
|
|
634 | In that case, you can use a condition variable like this: |
|
|
635 | |
|
|
636 | AnyEvent->condvar->recv; |
|
|
637 | |
|
|
638 | This has the effect of entering the event loop and looping forever. |
|
|
639 | |
|
|
640 | Note that usually your program has some exit condition, in which case |
|
|
641 | it is better to use the "traditional" approach of storing a condition |
|
|
642 | variable somewhere, waiting for it, and sending it when the program should |
|
|
643 | exit cleanly. |
|
|
644 | |
646 | |
645 | |
647 | =head1 OTHER MODULES |
646 | =head1 OTHER MODULES |
648 | |
647 | |
649 | The following is a non-exhaustive list of additional modules that use |
648 | The following is a non-exhaustive list of additional modules that use |
650 | AnyEvent and can therefore be mixed easily with other AnyEvent modules |
649 | AnyEvent and can therefore be mixed easily with other AnyEvent modules |
… | |
… | |
666 | |
665 | |
667 | Provides various utility functions for (internet protocol) sockets, |
666 | Provides various utility functions for (internet protocol) sockets, |
668 | addresses and name resolution. Also functions to create non-blocking tcp |
667 | addresses and name resolution. Also functions to create non-blocking tcp |
669 | connections or tcp servers, with IPv6 and SRV record support and more. |
668 | connections or tcp servers, with IPv6 and SRV record support and more. |
670 | |
669 | |
|
|
670 | =item L<AnyEvent::DNS> |
|
|
671 | |
|
|
672 | Provides rich asynchronous DNS resolver capabilities. |
|
|
673 | |
671 | =item L<AnyEvent::HTTPD> |
674 | =item L<AnyEvent::HTTPD> |
672 | |
675 | |
673 | Provides a simple web application server framework. |
676 | Provides a simple web application server framework. |
674 | |
|
|
675 | =item L<AnyEvent::DNS> |
|
|
676 | |
|
|
677 | Provides rich asynchronous DNS resolver capabilities. |
|
|
678 | |
677 | |
679 | =item L<AnyEvent::FastPing> |
678 | =item L<AnyEvent::FastPing> |
680 | |
679 | |
681 | The fastest ping in the west. |
680 | The fastest ping in the west. |
682 | |
681 | |