![]() |
![]()
| ![]() |
![]()
NAMEPOE::Component::Client::Keepalive - manage connections, with keep-alive VERSIONversion 0.272 SYNOPSISuse warnings; use strict; use POE; use POE::Component::Client::Keepalive; POE::Session->create( inline_states => { _start => \&start, got_conn => \&got_conn, got_error => \&handle_error, got_input => \&handle_input, } ); POE::Kernel->run(); exit; sub start { $_[HEAP]{ka} = POE::Component::Client::Keepalive->new(); $_[HEAP]{ka}->allocate( scheme => "http", addr => "127.0.0.1", port => 9999, event => "got_conn", context => "arbitrary data (even a reference) here", timeout => 60, ); print "Connection is in progress.\n"; } sub got_conn { my ($kernel, $heap, $response) = @_[KERNEL, HEAP, ARG0]; my $conn = $response->{connection}; my $context = $response->{context}; if (defined $conn) { if ($response->{from_cache}) { print "Connection was established immediately.\n"; } else { print "Connection was established asynchronously.\n"; } $conn->start( InputEvent => "got_input", ErrorEvent => "got_error", ); return; } print( "Connection could not be established: ", "$response->{function} error $response->{error_num}: ", "$response->{error_str}\n" ); } sub handle_input { my $input = $_[ARG0]; print "$input\n"; } sub handle_error { my $heap = $_[HEAP]; delete $heap->{connection}; $heap->{ka}->shutdown(); } DESCRIPTIONPOE::Component::Client::Keepalive creates and manages connections for other components. It maintains a cache of kept-alive connections for quick reuse. It is written specifically for clients that can benefit from kept-alive connections, such as HTTP clients. Using it for one-shot connections would probably be silly.
SEE ALSOPOE POE::Component::Connection::Keepalive LICENSEThis distribution is copyright 2004-2009 by Rocco Caputo. All rights are reserved. This distribution is free software; you may redistribute it and/or modify it under the same terms as Perl itself. AUTHORRocco Caputo <rcaputo@cpan.org> CONTRIBUTORSRob Bloodgood helped out a lot. Thank you. Joel Bernstein solved some nasty race conditions. Portugal Telecom <http://www.sapo.pt/> was kind enough to support his contributions. BUG TRACKERhttps://rt.cpan.org/Dist/Display.html?Queue=POE-Component-Client-Keepalive REPOSITORYhttp://gitorious.org/poe-component-client-keepalive http://github.com/rcaputo/poe-component-client-keepalive OTHER RESOURCEShttp://search.cpan.org/dist/POE-Component-Client-Keepalive/
|