1 | =head1 NAME |
1 | =head1 => NAME |
2 | |
2 | |
3 | AnyEvent - provide framework for multiple event loops |
3 | AnyEvent - provide framework for multiple event loops |
4 | |
4 | |
5 | EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event loops |
5 | EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event loops |
6 | |
6 | |
… | |
… | |
48 | isn't itself. What's worse, all the potential users of your module are |
48 | isn't itself. What's worse, all the potential users of your module are |
49 | I<also> forced to use the same event loop you use. |
49 | I<also> forced to use the same event loop you use. |
50 | |
50 | |
51 | AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works |
51 | AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works |
52 | fine. AnyEvent + Tk works fine etc. etc. but none of these work together |
52 | fine. AnyEvent + Tk works fine etc. etc. but none of these work together |
53 | with the rest: POE + IO::Async? no go. Tk + Event? no go. Again: if |
53 | with the rest: POE + IO::Async? No go. Tk + Event? No go. Again: if |
54 | your module uses one of those, every user of your module has to use it, |
54 | your module uses one of those, every user of your module has to use it, |
55 | too. But if your module uses AnyEvent, it works transparently with all |
55 | too. But if your module uses AnyEvent, it works transparently with all |
56 | event models it supports (including stuff like POE and IO::Async, as long |
56 | event models it supports (including stuff like POE and IO::Async, as long |
57 | as those use one of the supported event loops. It is trivial to add new |
57 | as those use one of the supported event loops. It is trivial to add new |
58 | event loops to AnyEvent, too, so it is future-proof). |
58 | event loops to AnyEvent, too, so it is future-proof). |
59 | |
59 | |
60 | In addition to being free of having to use I<the one and only true event |
60 | In addition to being free of having to use I<the one and only true event |
61 | model>, AnyEvent also is free of bloat and policy: with POE or similar |
61 | model>, AnyEvent also is free of bloat and policy: with POE or similar |
62 | modules, you get an enourmous amount of code and strict rules you have to |
62 | modules, you get an enormous amount of code and strict rules you have to |
63 | follow. AnyEvent, on the other hand, is lean and up to the point, by only |
63 | follow. AnyEvent, on the other hand, is lean and up to the point, by only |
64 | offering the functionality that is necessary, in as thin as a wrapper as |
64 | offering the functionality that is necessary, in as thin as a wrapper as |
65 | technically possible. |
65 | technically possible. |
66 | |
66 | |
|
|
67 | Of course, AnyEvent comes with a big (and fully optional!) toolbox |
|
|
68 | of useful functionality, such as an asynchronous DNS resolver, 100% |
|
|
69 | non-blocking connects (even with TLS/SSL, IPv6 and on broken platforms |
|
|
70 | such as Windows) and lots of real-world knowledge and workarounds for |
|
|
71 | platform bugs and differences. |
|
|
72 | |
67 | Of course, if you want lots of policy (this can arguably be somewhat |
73 | Now, if you I<do want> lots of policy (this can arguably be somewhat |
68 | useful) and you want to force your users to use the one and only event |
74 | useful) and you want to force your users to use the one and only event |
69 | model, you should I<not> use this module. |
75 | model, you should I<not> use this module. |
70 | |
76 | |
71 | =head1 DESCRIPTION |
77 | =head1 DESCRIPTION |
72 | |
78 | |
… | |
… | |
102 | starts using it, all bets are off. Maybe you should tell their authors to |
108 | starts using it, all bets are off. Maybe you should tell their authors to |
103 | use AnyEvent so their modules work together with others seamlessly... |
109 | use AnyEvent so their modules work together with others seamlessly... |
104 | |
110 | |
105 | The pure-perl implementation of AnyEvent is called |
111 | The pure-perl implementation of AnyEvent is called |
106 | C<AnyEvent::Impl::Perl>. Like other event modules you can load it |
112 | C<AnyEvent::Impl::Perl>. Like other event modules you can load it |
107 | explicitly. |
113 | explicitly and enjoy the high availability of that event loop :) |
108 | |
114 | |
109 | =head1 WATCHERS |
115 | =head1 WATCHERS |
110 | |
116 | |
111 | AnyEvent has the central concept of a I<watcher>, which is an object that |
117 | AnyEvent has the central concept of a I<watcher>, which is an object that |
112 | stores relevant data for each kind of event you are waiting for, such as |
118 | stores relevant data for each kind of event you are waiting for, such as |
113 | the callback to call, the filehandle to watch, etc. |
119 | the callback to call, the file handle to watch, etc. |
114 | |
120 | |
115 | These watchers are normal Perl objects with normal Perl lifetime. After |
121 | These watchers are normal Perl objects with normal Perl lifetime. After |
116 | creating a watcher it will immediately "watch" for events and invoke the |
122 | creating a watcher it will immediately "watch" for events and invoke the |
117 | callback when the event occurs (of course, only when the event model |
123 | callback when the event occurs (of course, only when the event model |
118 | is in control). |
124 | is in control). |
… | |
… | |
227 | timers. |
233 | timers. |
228 | |
234 | |
229 | AnyEvent always prefers relative timers, if available, matching the |
235 | AnyEvent always prefers relative timers, if available, matching the |
230 | AnyEvent API. |
236 | AnyEvent API. |
231 | |
237 | |
|
|
238 | AnyEvent has two additional methods that return the "current time": |
|
|
239 | |
|
|
240 | =over 4 |
|
|
241 | |
|
|
242 | =item AnyEvent->time |
|
|
243 | |
|
|
244 | This returns the "current wallclock time" as a fractional number of |
|
|
245 | seconds since the Epoch (the same thing as C<time> or C<Time::HiRes::time> |
|
|
246 | return, and the result is guaranteed to be compatible with those). |
|
|
247 | |
|
|
248 | It progresses independently of any event loop processing. |
|
|
249 | |
|
|
250 | In almost all cases (in all cases if you don't care), this is the function |
|
|
251 | to call when you want to know the current time. |
|
|
252 | |
|
|
253 | =item AnyEvent->now |
|
|
254 | |
|
|
255 | This also returns the "current wallclock time", but unlike C<time>, above, |
|
|
256 | this value might change only once per event loop iteration, depending on |
|
|
257 | the event loop (most return the same time as C<time>, above). This is the |
|
|
258 | time that AnyEvent timers get scheduled against. |
|
|
259 | |
|
|
260 | For a practical example of when these times differ, consider L<Event::Lib> |
|
|
261 | and L<EV> and the following set-up: |
|
|
262 | |
|
|
263 | The event loop is running and has just invoked one of your callback at |
|
|
264 | time=500 (assume no other callbacks delay processing). In your callback, |
|
|
265 | you wait a second by executing C<sleep 1> (blocking the process for a |
|
|
266 | second) and then (at time=501) you create a relative timer that fires |
|
|
267 | after three seconds. |
|
|
268 | |
|
|
269 | With L<Event::Lib>, C<< AnyEvent->time >> and C<< AnyEvent->now >> will |
|
|
270 | both return C<501>, because that is the current time, and the timer will |
|
|
271 | be scheduled to fire at time=504 (C<501> + C<3>). |
|
|
272 | |
|
|
273 | With L<EV>m C<< AnyEvent->time >> returns C<501> (as that is the current |
|
|
274 | time), but C<< AnyEvent->now >> returns C<500>, as that is the time the |
|
|
275 | last event processing phase started. With L<EV>, your timer gets scheduled |
|
|
276 | to run at time=503 (C<500> + C<3>). |
|
|
277 | |
|
|
278 | In one sense, L<Event::Lib> is more exact, as it uses the current time |
|
|
279 | regardless of any delays introduced by event processing. However, most |
|
|
280 | callbacks do not expect large delays in processing, so this causes a |
|
|
281 | higher drift (and a lot more syscalls to get the current time). |
|
|
282 | |
|
|
283 | In another sense, L<EV> is more exact, as your timer will be scheduled at |
|
|
284 | the same time, regardless of how long event processing actually took. |
|
|
285 | |
|
|
286 | In either case, if you care (and in most cases, you don't), then you |
|
|
287 | can get whatever behaviour you want with any event loop, by taking the |
|
|
288 | difference between C<< AnyEvent->time >> and C<< AnyEvent->now >> into |
|
|
289 | account. |
|
|
290 | |
|
|
291 | =back |
|
|
292 | |
232 | =head2 SIGNAL WATCHERS |
293 | =head2 SIGNAL WATCHERS |
233 | |
294 | |
234 | You can watch for signals using a signal watcher, C<signal> is the signal |
295 | You can watch for signals using a signal watcher, C<signal> is the signal |
235 | I<name> without any C<SIG> prefix, C<cb> is the Perl callback to |
296 | I<name> without any C<SIG> prefix, C<cb> is the Perl callback to |
236 | be invoked whenever a signal occurs. |
297 | be invoked whenever a signal occurs. |
237 | |
298 | |
238 | Although the callback might get passed parameters, their value and |
299 | Although the callback might get passed parameters, their value and |
239 | presence is undefined and you cannot rely on them. Portable AnyEvent |
300 | presence is undefined and you cannot rely on them. Portable AnyEvent |
240 | callbacks cannot use arguments passed to signal watcher callbacks. |
301 | callbacks cannot use arguments passed to signal watcher callbacks. |
241 | |
302 | |
242 | Multiple signal occurances can be clumped together into one callback |
303 | Multiple signal occurrences can be clumped together into one callback |
243 | invocation, and callback invocation will be synchronous. synchronous means |
304 | invocation, and callback invocation will be synchronous. Synchronous means |
244 | that it might take a while until the signal gets handled by the process, |
305 | that it might take a while until the signal gets handled by the process, |
245 | but it is guarenteed not to interrupt any other callbacks. |
306 | but it is guaranteed not to interrupt any other callbacks. |
246 | |
307 | |
247 | The main advantage of using these watchers is that you can share a signal |
308 | The main advantage of using these watchers is that you can share a signal |
248 | between multiple watchers. |
309 | between multiple watchers. |
249 | |
310 | |
250 | This watcher might use C<%SIG>, so programs overwriting those signals |
311 | This watcher might use C<%SIG>, so programs overwriting those signals |
… | |
… | |
310 | Condition variables can be created by calling the C<< AnyEvent->condvar |
371 | Condition variables can be created by calling the C<< AnyEvent->condvar |
311 | >> method, usually without arguments. The only argument pair allowed is |
372 | >> method, usually without arguments. The only argument pair allowed is |
312 | C<cb>, which specifies a callback to be called when the condition variable |
373 | C<cb>, which specifies a callback to be called when the condition variable |
313 | becomes true. |
374 | becomes true. |
314 | |
375 | |
315 | After creation, the conditon variable is "false" until it becomes "true" |
376 | After creation, the condition variable is "false" until it becomes "true" |
316 | by calling the C<send> method. |
377 | by calling the C<send> method (or calling the condition variable as if it |
|
|
378 | were a callback, read about the caveats in the description for the C<< |
|
|
379 | ->send >> method). |
317 | |
380 | |
318 | Condition variables are similar to callbacks, except that you can |
381 | Condition variables are similar to callbacks, except that you can |
319 | optionally wait for them. They can also be called merge points - points |
382 | optionally wait for them. They can also be called merge points - points |
320 | in time where multiple outstandign events have been processed. And yet |
383 | in time where multiple outstanding events have been processed. And yet |
321 | another way to call them is transations - each condition variable can be |
384 | another way to call them is transactions - each condition variable can be |
322 | used to represent a transaction, which finishes at some point and delivers |
385 | used to represent a transaction, which finishes at some point and delivers |
323 | a result. |
386 | a result. |
324 | |
387 | |
325 | Condition variables are very useful to signal that something has finished, |
388 | Condition variables are very useful to signal that something has finished, |
326 | for example, if you write a module that does asynchronous http requests, |
389 | for example, if you write a module that does asynchronous http requests, |
… | |
… | |
332 | you can block your main program until an event occurs - for example, you |
395 | you can block your main program until an event occurs - for example, you |
333 | could C<< ->recv >> in your main program until the user clicks the Quit |
396 | could C<< ->recv >> in your main program until the user clicks the Quit |
334 | button of your app, which would C<< ->send >> the "quit" event. |
397 | button of your app, which would C<< ->send >> the "quit" event. |
335 | |
398 | |
336 | Note that condition variables recurse into the event loop - if you have |
399 | Note that condition variables recurse into the event loop - if you have |
337 | two pieces of code that call C<< ->recv >> in a round-robbin fashion, you |
400 | two pieces of code that call C<< ->recv >> in a round-robin fashion, you |
338 | lose. Therefore, condition variables are good to export to your caller, but |
401 | lose. Therefore, condition variables are good to export to your caller, but |
339 | you should avoid making a blocking wait yourself, at least in callbacks, |
402 | you should avoid making a blocking wait yourself, at least in callbacks, |
340 | as this asks for trouble. |
403 | as this asks for trouble. |
341 | |
404 | |
342 | Condition variables are represented by hash refs in perl, and the keys |
405 | Condition variables are represented by hash refs in perl, and the keys |
… | |
… | |
347 | |
410 | |
348 | There are two "sides" to a condition variable - the "producer side" which |
411 | There are two "sides" to a condition variable - the "producer side" which |
349 | eventually calls C<< -> send >>, and the "consumer side", which waits |
412 | eventually calls C<< -> send >>, and the "consumer side", which waits |
350 | for the send to occur. |
413 | for the send to occur. |
351 | |
414 | |
352 | Example: |
415 | Example: wait for a timer. |
353 | |
416 | |
354 | # wait till the result is ready |
417 | # wait till the result is ready |
355 | my $result_ready = AnyEvent->condvar; |
418 | my $result_ready = AnyEvent->condvar; |
356 | |
419 | |
357 | # do something such as adding a timer |
420 | # do something such as adding a timer |
… | |
… | |
365 | |
428 | |
366 | # this "blocks" (while handling events) till the callback |
429 | # this "blocks" (while handling events) till the callback |
367 | # calls send |
430 | # calls send |
368 | $result_ready->recv; |
431 | $result_ready->recv; |
369 | |
432 | |
|
|
433 | Example: wait for a timer, but take advantage of the fact that |
|
|
434 | condition variables are also code references. |
|
|
435 | |
|
|
436 | my $done = AnyEvent->condvar; |
|
|
437 | my $delay = AnyEvent->timer (after => 5, cb => $done); |
|
|
438 | $done->recv; |
|
|
439 | |
370 | =head3 METHODS FOR PRODUCERS |
440 | =head3 METHODS FOR PRODUCERS |
371 | |
441 | |
372 | These methods should only be used by the producing side, i.e. the |
442 | These methods should only be used by the producing side, i.e. the |
373 | code/module that eventually sends the signal. Note that it is also |
443 | code/module that eventually sends the signal. Note that it is also |
374 | the producer side which creates the condvar in most cases, but it isn't |
444 | the producer side which creates the condvar in most cases, but it isn't |
… | |
… | |
385 | If a callback has been set on the condition variable, it is called |
455 | If a callback has been set on the condition variable, it is called |
386 | immediately from within send. |
456 | immediately from within send. |
387 | |
457 | |
388 | Any arguments passed to the C<send> call will be returned by all |
458 | Any arguments passed to the C<send> call will be returned by all |
389 | future C<< ->recv >> calls. |
459 | future C<< ->recv >> calls. |
|
|
460 | |
|
|
461 | Condition variables are overloaded so one can call them directly |
|
|
462 | (as a code reference). Calling them directly is the same as calling |
|
|
463 | C<send>. Note, however, that many C-based event loops do not handle |
|
|
464 | overloading, so as tempting as it may be, passing a condition variable |
|
|
465 | instead of a callback does not work. Both the pure perl and EV loops |
|
|
466 | support overloading, however, as well as all functions that use perl to |
|
|
467 | invoke a callback (as in L<AnyEvent::Socket> and L<AnyEvent::DNS> for |
|
|
468 | example). |
390 | |
469 | |
391 | =item $cv->croak ($error) |
470 | =item $cv->croak ($error) |
392 | |
471 | |
393 | Similar to send, but causes all call's to C<< ->recv >> to invoke |
472 | Similar to send, but causes all call's to C<< ->recv >> to invoke |
394 | C<Carp::croak> with the given error message/object/scalar. |
473 | C<Carp::croak> with the given error message/object/scalar. |
… | |
… | |
443 | doesn't execute once). |
522 | doesn't execute once). |
444 | |
523 | |
445 | This is the general pattern when you "fan out" into multiple subrequests: |
524 | This is the general pattern when you "fan out" into multiple subrequests: |
446 | use an outer C<begin>/C<end> pair to set the callback and ensure C<end> |
525 | use an outer C<begin>/C<end> pair to set the callback and ensure C<end> |
447 | is called at least once, and then, for each subrequest you start, call |
526 | is called at least once, and then, for each subrequest you start, call |
448 | C<begin> and for eahc subrequest you finish, call C<end>. |
527 | C<begin> and for each subrequest you finish, call C<end>. |
449 | |
528 | |
450 | =back |
529 | =back |
451 | |
530 | |
452 | =head3 METHODS FOR CONSUMERS |
531 | =head3 METHODS FOR CONSUMERS |
453 | |
532 | |
… | |
… | |
475 | (programs might want to do that to stay interactive), so I<if you are |
554 | (programs might want to do that to stay interactive), so I<if you are |
476 | using this from a module, never require a blocking wait>, but let the |
555 | using this from a module, never require a blocking wait>, but let the |
477 | caller decide whether the call will block or not (for example, by coupling |
556 | caller decide whether the call will block or not (for example, by coupling |
478 | condition variables with some kind of request results and supporting |
557 | condition variables with some kind of request results and supporting |
479 | callbacks so the caller knows that getting the result will not block, |
558 | callbacks so the caller knows that getting the result will not block, |
480 | while still suppporting blocking waits if the caller so desires). |
559 | while still supporting blocking waits if the caller so desires). |
481 | |
560 | |
482 | Another reason I<never> to C<< ->recv >> in a module is that you cannot |
561 | Another reason I<never> to C<< ->recv >> in a module is that you cannot |
483 | sensibly have two C<< ->recv >>'s in parallel, as that would require |
562 | sensibly have two C<< ->recv >>'s in parallel, as that would require |
484 | multiple interpreters or coroutines/threads, none of which C<AnyEvent> |
563 | multiple interpreters or coroutines/threads, none of which C<AnyEvent> |
485 | can supply. |
564 | can supply. |
… | |
… | |
601 | |
680 | |
602 | If it doesn't care, it can just "use AnyEvent" and use it itself, or not |
681 | If it doesn't care, it can just "use AnyEvent" and use it itself, or not |
603 | do anything special (it does not need to be event-based) and let AnyEvent |
682 | do anything special (it does not need to be event-based) and let AnyEvent |
604 | decide which implementation to chose if some module relies on it. |
683 | decide which implementation to chose if some module relies on it. |
605 | |
684 | |
606 | If the main program relies on a specific event model. For example, in |
685 | If the main program relies on a specific event model - for example, in |
607 | Gtk2 programs you have to rely on the Glib module. You should load the |
686 | Gtk2 programs you have to rely on the Glib module - you should load the |
608 | event module before loading AnyEvent or any module that uses it: generally |
687 | event module before loading AnyEvent or any module that uses it: generally |
609 | speaking, you should load it as early as possible. The reason is that |
688 | speaking, you should load it as early as possible. The reason is that |
610 | modules might create watchers when they are loaded, and AnyEvent will |
689 | modules might create watchers when they are loaded, and AnyEvent will |
611 | decide on the event model to use as soon as it creates watchers, and it |
690 | decide on the event model to use as soon as it creates watchers, and it |
612 | might chose the wrong one unless you load the correct one yourself. |
691 | might chose the wrong one unless you load the correct one yourself. |
613 | |
692 | |
614 | You can chose to use a rather inefficient pure-perl implementation by |
693 | You can chose to use a pure-perl implementation by loading the |
615 | loading the C<AnyEvent::Impl::Perl> module, which gives you similar |
694 | C<AnyEvent::Impl::Perl> module, which gives you similar behaviour |
616 | behaviour everywhere, but letting AnyEvent chose is generally better. |
695 | everywhere, but letting AnyEvent chose the model is generally better. |
|
|
696 | |
|
|
697 | =head2 MAINLOOP EMULATION |
|
|
698 | |
|
|
699 | Sometimes (often for short test scripts, or even standalone programs who |
|
|
700 | only want to use AnyEvent), you do not want to run a specific event loop. |
|
|
701 | |
|
|
702 | In that case, you can use a condition variable like this: |
|
|
703 | |
|
|
704 | AnyEvent->condvar->recv; |
|
|
705 | |
|
|
706 | This has the effect of entering the event loop and looping forever. |
|
|
707 | |
|
|
708 | Note that usually your program has some exit condition, in which case |
|
|
709 | it is better to use the "traditional" approach of storing a condition |
|
|
710 | variable somewhere, waiting for it, and sending it when the program should |
|
|
711 | exit cleanly. |
|
|
712 | |
617 | |
713 | |
618 | =head1 OTHER MODULES |
714 | =head1 OTHER MODULES |
619 | |
715 | |
620 | The following is a non-exhaustive list of additional modules that use |
716 | The following is a non-exhaustive list of additional modules that use |
621 | AnyEvent and can therefore be mixed easily with other AnyEvent modules |
717 | AnyEvent and can therefore be mixed easily with other AnyEvent modules |
… | |
… | |
631 | |
727 | |
632 | =item L<AnyEvent::Handle> |
728 | =item L<AnyEvent::Handle> |
633 | |
729 | |
634 | Provide read and write buffers and manages watchers for reads and writes. |
730 | Provide read and write buffers and manages watchers for reads and writes. |
635 | |
731 | |
|
|
732 | =item L<AnyEvent::Socket> |
|
|
733 | |
|
|
734 | Provides various utility functions for (internet protocol) sockets, |
|
|
735 | addresses and name resolution. Also functions to create non-blocking tcp |
|
|
736 | connections or tcp servers, with IPv6 and SRV record support and more. |
|
|
737 | |
|
|
738 | =item L<AnyEvent::DNS> |
|
|
739 | |
|
|
740 | Provides rich asynchronous DNS resolver capabilities. |
|
|
741 | |
636 | =item L<AnyEvent::HTTPD> |
742 | =item L<AnyEvent::HTTPD> |
637 | |
743 | |
638 | Provides a simple web application server framework. |
744 | Provides a simple web application server framework. |
639 | |
|
|
640 | =item L<AnyEvent::DNS> |
|
|
641 | |
|
|
642 | Provides asynchronous DNS resolver capabilities, beyond what |
|
|
643 | L<AnyEvent::Util> offers. |
|
|
644 | |
745 | |
645 | =item L<AnyEvent::FastPing> |
746 | =item L<AnyEvent::FastPing> |
646 | |
747 | |
647 | The fastest ping in the west. |
748 | The fastest ping in the west. |
648 | |
749 | |
… | |
… | |
691 | no warnings; |
792 | no warnings; |
692 | use strict; |
793 | use strict; |
693 | |
794 | |
694 | use Carp; |
795 | use Carp; |
695 | |
796 | |
696 | our $VERSION = '3.4'; |
797 | our $VERSION = '4.05'; |
697 | our $MODEL; |
798 | our $MODEL; |
698 | |
799 | |
699 | our $AUTOLOAD; |
800 | our $AUTOLOAD; |
700 | our @ISA; |
801 | our @ISA; |
701 | |
802 | |
|
|
803 | our @REGISTRY; |
|
|
804 | |
|
|
805 | our $WIN32; |
|
|
806 | |
|
|
807 | BEGIN { |
|
|
808 | my $win32 = ! ! ($^O =~ /mswin32/i); |
|
|
809 | eval "sub WIN32(){ $win32 }"; |
|
|
810 | } |
|
|
811 | |
702 | our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; |
812 | our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; |
703 | |
813 | |
704 | our @REGISTRY; |
814 | our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred |
|
|
815 | |
|
|
816 | { |
|
|
817 | my $idx; |
|
|
818 | $PROTOCOL{$_} = ++$idx |
|
|
819 | for reverse split /\s*,\s*/, |
|
|
820 | $ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6"; |
|
|
821 | } |
705 | |
822 | |
706 | my @models = ( |
823 | my @models = ( |
707 | [EV:: => AnyEvent::Impl::EV::], |
824 | [EV:: => AnyEvent::Impl::EV::], |
708 | [Event:: => AnyEvent::Impl::Event::], |
825 | [Event:: => AnyEvent::Impl::Event::], |
709 | [Tk:: => AnyEvent::Impl::Tk::], |
|
|
710 | [Wx:: => AnyEvent::Impl::POE::], |
|
|
711 | [Prima:: => AnyEvent::Impl::POE::], |
|
|
712 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
826 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
713 | # everything below here will not be autoprobed as the pureperl backend should work everywhere |
827 | # everything below here will not be autoprobed |
714 | [Glib:: => AnyEvent::Impl::Glib::], |
828 | # as the pureperl backend should work everywhere |
|
|
829 | # and is usually faster |
|
|
830 | [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles |
|
|
831 | [Glib:: => AnyEvent::Impl::Glib::], # becomes extremely slow with many watchers |
715 | [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy |
832 | [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy |
716 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
833 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
717 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
834 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
|
|
835 | [Wx:: => AnyEvent::Impl::POE::], |
|
|
836 | [Prima:: => AnyEvent::Impl::POE::], |
718 | ); |
837 | ); |
719 | |
838 | |
720 | our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY); |
839 | our %method = map +($_ => 1), qw(io timer time now signal child condvar one_event DESTROY); |
721 | |
840 | |
722 | our @post_detect; |
841 | our @post_detect; |
723 | |
842 | |
724 | sub post_detect(&) { |
843 | sub post_detect(&) { |
725 | my ($cb) = @_; |
844 | my ($cb) = @_; |
… | |
… | |
730 | 1 |
849 | 1 |
731 | } else { |
850 | } else { |
732 | push @post_detect, $cb; |
851 | push @post_detect, $cb; |
733 | |
852 | |
734 | defined wantarray |
853 | defined wantarray |
735 | ? bless \$cb, "AnyEvent::Util::Guard" |
854 | ? bless \$cb, "AnyEvent::Util::PostDetect" |
736 | : () |
855 | : () |
737 | } |
856 | } |
738 | } |
857 | } |
739 | |
858 | |
740 | sub AnyEvent::Util::Guard::DESTROY { |
859 | sub AnyEvent::Util::PostDetect::DESTROY { |
741 | @post_detect = grep $_ != ${$_[0]}, @post_detect; |
860 | @post_detect = grep $_ != ${$_[0]}, @post_detect; |
742 | } |
861 | } |
743 | |
862 | |
744 | sub detect() { |
863 | sub detect() { |
745 | unless ($MODEL) { |
864 | unless ($MODEL) { |
746 | no strict 'refs'; |
865 | no strict 'refs'; |
|
|
866 | local $SIG{__DIE__}; |
747 | |
867 | |
748 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) { |
868 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) { |
749 | my $model = "AnyEvent::Impl::$1"; |
869 | my $model = "AnyEvent::Impl::$1"; |
750 | if (eval "require $model") { |
870 | if (eval "require $model") { |
751 | $MODEL = $model; |
871 | $MODEL = $model; |
… | |
… | |
808 | $class->$func (@_); |
928 | $class->$func (@_); |
809 | } |
929 | } |
810 | |
930 | |
811 | package AnyEvent::Base; |
931 | package AnyEvent::Base; |
812 | |
932 | |
|
|
933 | # default implementation for now and time |
|
|
934 | |
|
|
935 | use Time::HiRes (); |
|
|
936 | |
|
|
937 | sub time { Time::HiRes::time } |
|
|
938 | sub now { Time::HiRes::time } |
|
|
939 | |
813 | # default implementation for ->condvar |
940 | # default implementation for ->condvar |
814 | |
941 | |
815 | sub condvar { |
942 | sub condvar { |
816 | bless {}, "AnyEvent::Base::CondVar" |
943 | bless { @_ == 3 ? (_ae_cb => $_[2]) : () }, AnyEvent::CondVar:: |
817 | } |
944 | } |
818 | |
945 | |
819 | # default implementation for ->signal |
946 | # default implementation for ->signal |
820 | |
947 | |
821 | our %SIG_CB; |
948 | our %SIG_CB; |
… | |
… | |
874 | or Carp::croak "required option 'pid' is missing"; |
1001 | or Carp::croak "required option 'pid' is missing"; |
875 | |
1002 | |
876 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
1003 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
877 | |
1004 | |
878 | unless ($WNOHANG) { |
1005 | unless ($WNOHANG) { |
879 | $WNOHANG = eval { require POSIX; &POSIX::WNOHANG } || 1; |
1006 | $WNOHANG = eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1; |
880 | } |
1007 | } |
881 | |
1008 | |
882 | unless ($CHLD_W) { |
1009 | unless ($CHLD_W) { |
883 | $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld); |
1010 | $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld); |
884 | # child could be a zombie already, so make at least one round |
1011 | # child could be a zombie already, so make at least one round |
… | |
… | |
895 | delete $PID_CB{$pid} unless keys %{ $PID_CB{$pid} }; |
1022 | delete $PID_CB{$pid} unless keys %{ $PID_CB{$pid} }; |
896 | |
1023 | |
897 | undef $CHLD_W unless keys %PID_CB; |
1024 | undef $CHLD_W unless keys %PID_CB; |
898 | } |
1025 | } |
899 | |
1026 | |
900 | package AnyEvent::Base::CondVar; |
1027 | package AnyEvent::CondVar; |
901 | |
1028 | |
902 | # wake up the waiter |
1029 | our @ISA = AnyEvent::CondVar::Base::; |
|
|
1030 | |
|
|
1031 | package AnyEvent::CondVar::Base; |
|
|
1032 | |
|
|
1033 | use overload |
|
|
1034 | '&{}' => sub { my $self = shift; sub { $self->send (@_) } }, |
|
|
1035 | fallback => 1; |
|
|
1036 | |
903 | sub _send { |
1037 | sub _send { |
904 | &{ delete $_[0]{_ae_cb} } if $_[0]{_ae_cb}; |
1038 | # nop |
905 | } |
1039 | } |
906 | |
1040 | |
907 | sub send { |
1041 | sub send { |
908 | my $cv = shift; |
1042 | my $cv = shift; |
909 | $cv->{_ae_sent} = [@_]; |
1043 | $cv->{_ae_sent} = [@_]; |
|
|
1044 | (delete $cv->{_ae_cb})->($cv) if $cv->{_ae_cb}; |
910 | $cv->_send; |
1045 | $cv->_send; |
911 | } |
1046 | } |
912 | |
1047 | |
913 | sub croak { |
1048 | sub croak { |
914 | $_[0]{_ae_croak} = $_[1]; |
1049 | $_[0]{_ae_croak} = $_[1]; |
… | |
… | |
917 | |
1052 | |
918 | sub ready { |
1053 | sub ready { |
919 | $_[0]{_ae_sent} |
1054 | $_[0]{_ae_sent} |
920 | } |
1055 | } |
921 | |
1056 | |
|
|
1057 | sub _wait { |
|
|
1058 | AnyEvent->one_event while !$_[0]{_ae_sent}; |
|
|
1059 | } |
|
|
1060 | |
922 | sub recv { |
1061 | sub recv { |
923 | AnyEvent->one_event while !$_[0]{_ae_sent}; |
1062 | $_[0]->_wait; |
924 | |
1063 | |
925 | Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak}; |
1064 | Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak}; |
926 | wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0] |
1065 | wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0] |
927 | } |
1066 | } |
928 | |
1067 | |
… | |
… | |
936 | $_[0]{_ae_end_cb} = $_[1] if @_ > 1; |
1075 | $_[0]{_ae_end_cb} = $_[1] if @_ > 1; |
937 | } |
1076 | } |
938 | |
1077 | |
939 | sub end { |
1078 | sub end { |
940 | return if --$_[0]{_ae_counter}; |
1079 | return if --$_[0]{_ae_counter}; |
941 | &{ $_[0]{_ae_end_cb} } if $_[0]{_ae_end_cb}; |
1080 | &{ $_[0]{_ae_end_cb} || sub { $_[0]->send } }; |
942 | } |
1081 | } |
943 | |
1082 | |
944 | # undocumented/compatibility with pre-3.4 |
1083 | # undocumented/compatibility with pre-3.4 |
945 | *broadcast = \&send; |
1084 | *broadcast = \&send; |
946 | *wait = \&recv; |
1085 | *wait = \&_wait; |
947 | |
1086 | |
948 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
1087 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
949 | |
1088 | |
950 | This is an advanced topic that you do not normally need to use AnyEvent in |
1089 | This is an advanced topic that you do not normally need to use AnyEvent in |
951 | a module. This section is only of use to event loop authors who want to |
1090 | a module. This section is only of use to event loop authors who want to |
… | |
… | |
1008 | model it chooses. |
1147 | model it chooses. |
1009 | |
1148 | |
1010 | =item C<PERL_ANYEVENT_MODEL> |
1149 | =item C<PERL_ANYEVENT_MODEL> |
1011 | |
1150 | |
1012 | This can be used to specify the event model to be used by AnyEvent, before |
1151 | This can be used to specify the event model to be used by AnyEvent, before |
1013 | autodetection and -probing kicks in. It must be a string consisting |
1152 | auto detection and -probing kicks in. It must be a string consisting |
1014 | entirely of ASCII letters. The string C<AnyEvent::Impl::> gets prepended |
1153 | entirely of ASCII letters. The string C<AnyEvent::Impl::> gets prepended |
1015 | and the resulting module name is loaded and if the load was successful, |
1154 | and the resulting module name is loaded and if the load was successful, |
1016 | used as event model. If it fails to load AnyEvent will proceed with |
1155 | used as event model. If it fails to load AnyEvent will proceed with |
1017 | autodetection and -probing. |
1156 | auto detection and -probing. |
1018 | |
1157 | |
1019 | This functionality might change in future versions. |
1158 | This functionality might change in future versions. |
1020 | |
1159 | |
1021 | For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you |
1160 | For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you |
1022 | could start your program like this: |
1161 | could start your program like this: |
1023 | |
1162 | |
1024 | PERL_ANYEVENT_MODEL=Perl perl ... |
1163 | PERL_ANYEVENT_MODEL=Perl perl ... |
|
|
1164 | |
|
|
1165 | =item C<PERL_ANYEVENT_PROTOCOLS> |
|
|
1166 | |
|
|
1167 | Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences |
|
|
1168 | for IPv4 or IPv6. The default is unspecified (and might change, or be the result |
|
|
1169 | of auto probing). |
|
|
1170 | |
|
|
1171 | Must be set to a comma-separated list of protocols or address families, |
|
|
1172 | current supported: C<ipv4> and C<ipv6>. Only protocols mentioned will be |
|
|
1173 | used, and preference will be given to protocols mentioned earlier in the |
|
|
1174 | list. |
|
|
1175 | |
|
|
1176 | This variable can effectively be used for denial-of-service attacks |
|
|
1177 | against local programs (e.g. when setuid), although the impact is likely |
|
|
1178 | small, as the program has to handle connection errors already- |
|
|
1179 | |
|
|
1180 | Examples: C<PERL_ANYEVENT_PROTOCOLS=ipv4,ipv6> - prefer IPv4 over IPv6, |
|
|
1181 | but support both and try to use both. C<PERL_ANYEVENT_PROTOCOLS=ipv4> |
|
|
1182 | - only support IPv4, never try to resolve or contact IPv6 |
|
|
1183 | addresses. C<PERL_ANYEVENT_PROTOCOLS=ipv6,ipv4> support either IPv4 or |
|
|
1184 | IPv6, but prefer IPv6 over IPv4. |
|
|
1185 | |
|
|
1186 | =item C<PERL_ANYEVENT_EDNS0> |
|
|
1187 | |
|
|
1188 | Used by L<AnyEvent::DNS> to decide whether to use the EDNS0 extension |
|
|
1189 | for DNS. This extension is generally useful to reduce DNS traffic, but |
|
|
1190 | some (broken) firewalls drop such DNS packets, which is why it is off by |
|
|
1191 | default. |
|
|
1192 | |
|
|
1193 | Setting this variable to C<1> will cause L<AnyEvent::DNS> to announce |
|
|
1194 | EDNS0 in its DNS requests. |
|
|
1195 | |
|
|
1196 | =item C<PERL_ANYEVENT_MAX_FORKS> |
|
|
1197 | |
|
|
1198 | The maximum number of child processes that C<AnyEvent::Util::fork_call> |
|
|
1199 | will create in parallel. |
1025 | |
1200 | |
1026 | =back |
1201 | =back |
1027 | |
1202 | |
1028 | =head1 EXAMPLE PROGRAM |
1203 | =head1 EXAMPLE PROGRAM |
1029 | |
1204 | |
… | |
… | |
1040 | poll => 'r', |
1215 | poll => 'r', |
1041 | cb => sub { |
1216 | cb => sub { |
1042 | warn "io event <$_[0]>\n"; # will always output <r> |
1217 | warn "io event <$_[0]>\n"; # will always output <r> |
1043 | chomp (my $input = <STDIN>); # read a line |
1218 | chomp (my $input = <STDIN>); # read a line |
1044 | warn "read: $input\n"; # output what has been read |
1219 | warn "read: $input\n"; # output what has been read |
1045 | $cv->broadcast if $input =~ /^q/i; # quit program if /^q/i |
1220 | $cv->send if $input =~ /^q/i; # quit program if /^q/i |
1046 | }, |
1221 | }, |
1047 | ); |
1222 | ); |
1048 | |
1223 | |
1049 | my $time_watcher; # can only be used once |
1224 | my $time_watcher; # can only be used once |
1050 | |
1225 | |
… | |
… | |
1055 | }); |
1230 | }); |
1056 | } |
1231 | } |
1057 | |
1232 | |
1058 | new_timer; # create first timer |
1233 | new_timer; # create first timer |
1059 | |
1234 | |
1060 | $cv->wait; # wait until user enters /^q/i |
1235 | $cv->recv; # wait until user enters /^q/i |
1061 | |
1236 | |
1062 | =head1 REAL-WORLD EXAMPLE |
1237 | =head1 REAL-WORLD EXAMPLE |
1063 | |
1238 | |
1064 | Consider the L<Net::FCP> module. It features (among others) the following |
1239 | Consider the L<Net::FCP> module. It features (among others) the following |
1065 | API calls, which are to freenet what HTTP GET requests are to http: |
1240 | API calls, which are to freenet what HTTP GET requests are to http: |
… | |
… | |
1115 | syswrite $txn->{fh}, $txn->{request} |
1290 | syswrite $txn->{fh}, $txn->{request} |
1116 | or die "connection or write error"; |
1291 | or die "connection or write error"; |
1117 | $txn->{w} = AnyEvent->io (fh => $txn->{fh}, poll => 'r', cb => sub { $txn->fh_ready_r }); |
1292 | $txn->{w} = AnyEvent->io (fh => $txn->{fh}, poll => 'r', cb => sub { $txn->fh_ready_r }); |
1118 | |
1293 | |
1119 | Again, C<fh_ready_r> waits till all data has arrived, and then stores the |
1294 | Again, C<fh_ready_r> waits till all data has arrived, and then stores the |
1120 | result and signals any possible waiters that the request ahs finished: |
1295 | result and signals any possible waiters that the request has finished: |
1121 | |
1296 | |
1122 | sysread $txn->{fh}, $txn->{buf}, length $txn->{$buf}; |
1297 | sysread $txn->{fh}, $txn->{buf}, length $txn->{$buf}; |
1123 | |
1298 | |
1124 | if (end-of-file or data complete) { |
1299 | if (end-of-file or data complete) { |
1125 | $txn->{result} = $txn->{buf}; |
1300 | $txn->{result} = $txn->{buf}; |
1126 | $txn->{finished}->broadcast; |
1301 | $txn->{finished}->send; |
1127 | $txb->{cb}->($txn) of $txn->{cb}; # also call callback |
1302 | $txb->{cb}->($txn) of $txn->{cb}; # also call callback |
1128 | } |
1303 | } |
1129 | |
1304 | |
1130 | The C<result> method, finally, just waits for the finished signal (if the |
1305 | The C<result> method, finally, just waits for the finished signal (if the |
1131 | request was already finished, it doesn't wait, of course, and returns the |
1306 | request was already finished, it doesn't wait, of course, and returns the |
1132 | data: |
1307 | data: |
1133 | |
1308 | |
1134 | $txn->{finished}->wait; |
1309 | $txn->{finished}->recv; |
1135 | return $txn->{result}; |
1310 | return $txn->{result}; |
1136 | |
1311 | |
1137 | The actual code goes further and collects all errors (C<die>s, exceptions) |
1312 | The actual code goes further and collects all errors (C<die>s, exceptions) |
1138 | that occured during request processing. The C<result> method detects |
1313 | that occurred during request processing. The C<result> method detects |
1139 | whether an exception as thrown (it is stored inside the $txn object) |
1314 | whether an exception as thrown (it is stored inside the $txn object) |
1140 | and just throws the exception, which means connection errors and other |
1315 | and just throws the exception, which means connection errors and other |
1141 | problems get reported tot he code that tries to use the result, not in a |
1316 | problems get reported tot he code that tries to use the result, not in a |
1142 | random callback. |
1317 | random callback. |
1143 | |
1318 | |
… | |
… | |
1174 | |
1349 | |
1175 | my $quit = AnyEvent->condvar; |
1350 | my $quit = AnyEvent->condvar; |
1176 | |
1351 | |
1177 | $fcp->txn_client_get ($url)->cb (sub { |
1352 | $fcp->txn_client_get ($url)->cb (sub { |
1178 | ... |
1353 | ... |
1179 | $quit->broadcast; |
1354 | $quit->send; |
1180 | }); |
1355 | }); |
1181 | |
1356 | |
1182 | $quit->wait; |
1357 | $quit->recv; |
1183 | |
1358 | |
1184 | |
1359 | |
1185 | =head1 BENCHMARKS |
1360 | =head1 BENCHMARKS |
1186 | |
1361 | |
1187 | To give you an idea of the performance and overheads that AnyEvent adds |
1362 | To give you an idea of the performance and overheads that AnyEvent adds |
… | |
… | |
1189 | of various event loops I prepared some benchmarks. |
1364 | of various event loops I prepared some benchmarks. |
1190 | |
1365 | |
1191 | =head2 BENCHMARKING ANYEVENT OVERHEAD |
1366 | =head2 BENCHMARKING ANYEVENT OVERHEAD |
1192 | |
1367 | |
1193 | Here is a benchmark of various supported event models used natively and |
1368 | Here is a benchmark of various supported event models used natively and |
1194 | through anyevent. The benchmark creates a lot of timers (with a zero |
1369 | through AnyEvent. The benchmark creates a lot of timers (with a zero |
1195 | timeout) and I/O watchers (watching STDOUT, a pty, to become writable, |
1370 | timeout) and I/O watchers (watching STDOUT, a pty, to become writable, |
1196 | which it is), lets them fire exactly once and destroys them again. |
1371 | which it is), lets them fire exactly once and destroys them again. |
1197 | |
1372 | |
1198 | Source code for this benchmark is found as F<eg/bench> in the AnyEvent |
1373 | Source code for this benchmark is found as F<eg/bench> in the AnyEvent |
1199 | distribution. |
1374 | distribution. |
… | |
… | |
1216 | all watchers, to avoid adding memory overhead. That means closure creation |
1391 | all watchers, to avoid adding memory overhead. That means closure creation |
1217 | and memory usage is not included in the figures. |
1392 | and memory usage is not included in the figures. |
1218 | |
1393 | |
1219 | I<invoke> is the time, in microseconds, used to invoke a simple |
1394 | I<invoke> is the time, in microseconds, used to invoke a simple |
1220 | callback. The callback simply counts down a Perl variable and after it was |
1395 | callback. The callback simply counts down a Perl variable and after it was |
1221 | invoked "watcher" times, it would C<< ->broadcast >> a condvar once to |
1396 | invoked "watcher" times, it would C<< ->send >> a condvar once to |
1222 | signal the end of this phase. |
1397 | signal the end of this phase. |
1223 | |
1398 | |
1224 | I<destroy> is the time, in microseconds, that it takes to destroy a single |
1399 | I<destroy> is the time, in microseconds, that it takes to destroy a single |
1225 | watcher. |
1400 | watcher. |
1226 | |
1401 | |
… | |
… | |
1322 | |
1497 | |
1323 | =back |
1498 | =back |
1324 | |
1499 | |
1325 | =head2 BENCHMARKING THE LARGE SERVER CASE |
1500 | =head2 BENCHMARKING THE LARGE SERVER CASE |
1326 | |
1501 | |
1327 | This benchmark atcually benchmarks the event loop itself. It works by |
1502 | This benchmark actually benchmarks the event loop itself. It works by |
1328 | creating a number of "servers": each server consists of a socketpair, a |
1503 | creating a number of "servers": each server consists of a socket pair, a |
1329 | timeout watcher that gets reset on activity (but never fires), and an I/O |
1504 | timeout watcher that gets reset on activity (but never fires), and an I/O |
1330 | watcher waiting for input on one side of the socket. Each time the socket |
1505 | watcher waiting for input on one side of the socket. Each time the socket |
1331 | watcher reads a byte it will write that byte to a random other "server". |
1506 | watcher reads a byte it will write that byte to a random other "server". |
1332 | |
1507 | |
1333 | The effect is that there will be a lot of I/O watchers, only part of which |
1508 | The effect is that there will be a lot of I/O watchers, only part of which |
1334 | are active at any one point (so there is a constant number of active |
1509 | are active at any one point (so there is a constant number of active |
1335 | fds for each loop iterstaion, but which fds these are is random). The |
1510 | fds for each loop iteration, but which fds these are is random). The |
1336 | timeout is reset each time something is read because that reflects how |
1511 | timeout is reset each time something is read because that reflects how |
1337 | most timeouts work (and puts extra pressure on the event loops). |
1512 | most timeouts work (and puts extra pressure on the event loops). |
1338 | |
1513 | |
1339 | In this benchmark, we use 10000 socketpairs (20000 sockets), of which 100 |
1514 | In this benchmark, we use 10000 socket pairs (20000 sockets), of which 100 |
1340 | (1%) are active. This mirrors the activity of large servers with many |
1515 | (1%) are active. This mirrors the activity of large servers with many |
1341 | connections, most of which are idle at any one point in time. |
1516 | connections, most of which are idle at any one point in time. |
1342 | |
1517 | |
1343 | Source code for this benchmark is found as F<eg/bench2> in the AnyEvent |
1518 | Source code for this benchmark is found as F<eg/bench2> in the AnyEvent |
1344 | distribution. |
1519 | distribution. |
… | |
… | |
1346 | =head3 Explanation of the columns |
1521 | =head3 Explanation of the columns |
1347 | |
1522 | |
1348 | I<sockets> is the number of sockets, and twice the number of "servers" (as |
1523 | I<sockets> is the number of sockets, and twice the number of "servers" (as |
1349 | each server has a read and write socket end). |
1524 | each server has a read and write socket end). |
1350 | |
1525 | |
1351 | I<create> is the time it takes to create a socketpair (which is |
1526 | I<create> is the time it takes to create a socket pair (which is |
1352 | nontrivial) and two watchers: an I/O watcher and a timeout watcher. |
1527 | nontrivial) and two watchers: an I/O watcher and a timeout watcher. |
1353 | |
1528 | |
1354 | I<request>, the most important value, is the time it takes to handle a |
1529 | I<request>, the most important value, is the time it takes to handle a |
1355 | single "request", that is, reading the token from the pipe and forwarding |
1530 | single "request", that is, reading the token from the pipe and forwarding |
1356 | it to another server. This includes deleting the old timeout and creating |
1531 | it to another server. This includes deleting the old timeout and creating |
… | |
… | |
1429 | speed most when you have lots of watchers, not when you only have a few of |
1604 | speed most when you have lots of watchers, not when you only have a few of |
1430 | them). |
1605 | them). |
1431 | |
1606 | |
1432 | EV is again fastest. |
1607 | EV is again fastest. |
1433 | |
1608 | |
1434 | Perl again comes second. It is noticably faster than the C-based event |
1609 | Perl again comes second. It is noticeably faster than the C-based event |
1435 | loops Event and Glib, although the difference is too small to really |
1610 | loops Event and Glib, although the difference is too small to really |
1436 | matter. |
1611 | matter. |
1437 | |
1612 | |
1438 | POE also performs much better in this case, but is is still far behind the |
1613 | POE also performs much better in this case, but is is still far behind the |
1439 | others. |
1614 | others. |
… | |
… | |
1479 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL). |
1654 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL). |
1480 | |
1655 | |
1481 | |
1656 | |
1482 | =head1 SEE ALSO |
1657 | =head1 SEE ALSO |
1483 | |
1658 | |
|
|
1659 | Utility functions: L<AnyEvent::Util>. |
|
|
1660 | |
1484 | Event modules: L<EV>, L<EV::Glib>, L<Glib::EV>, L<Event>, L<Glib::Event>, |
1661 | Event modules: L<EV>, L<EV::Glib>, L<Glib::EV>, L<Event>, L<Glib::Event>, |
1485 | L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. |
1662 | L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. |
1486 | |
1663 | |
1487 | Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>, |
1664 | Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>, |
1488 | L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, |
1665 | L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, |
1489 | L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>, |
1666 | L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>, |
1490 | L<AnyEvent::Impl::POE>. |
1667 | L<AnyEvent::Impl::POE>. |
1491 | |
1668 | |
|
|
1669 | Non-blocking file handles, sockets, TCP clients and |
|
|
1670 | servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>. |
|
|
1671 | |
|
|
1672 | Asynchronous DNS: L<AnyEvent::DNS>. |
|
|
1673 | |
1492 | Coroutine support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>, |
1674 | Coroutine support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>, |
1493 | |
1675 | |
1494 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>. |
1676 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>. |
1495 | |
1677 | |
1496 | |
1678 | |
1497 | =head1 AUTHOR |
1679 | =head1 AUTHOR |
1498 | |
1680 | |
1499 | Marc Lehmann <schmorp@schmorp.de> |
1681 | Marc Lehmann <schmorp@schmorp.de> |