Re: POE::Component::Server::TCP - accessing listener heap entries

[email protected] (Rocco Caputo) Mon, 29 Aug 2011 21:43:49 -0400
Newsgroups perl.poe
Message-ID <[email protected]>
Hi, Krishna.

Sorry that the docs aren't clear.  It's all Perl, so you could say:

my $server_heap;

POE::Component::Server::TCP->new(
  ...,
  Started => sub { $server_heap = $_[HEAP] },
);

... and then access the server's heap from $server_heap via closure.  Be careful to avoid circular references when you work like this, and you should be fine.

-- 
Rocco Caputo <[email protected]>

On Aug 29, 2011, at 21:20, Krishna K wrote:

> Hi,
>     I am trying to debug an issue with POE::Component::Server::TCP where the client sessions do not get closed correctly when using POE::Component::Client::TCP (1.311/1.312) but work as expected when using 1.294.
> 
>     I am maintaining global variables to manage information on number of clients that are connected/disconnected by updating them in ClientConnected() and ClientDisconnected() methods, which I would like to avoid and use the main listener session's heap entry (connections) as presented in the documentation.
> 
> http://search.cpan.org/~rcaputo/POE/lib/POE/Component/Server/TCP.pm#HEAP_Members_for_Master_Listening_Sessions
> 
> Portion of code
> ==========
> 
> my $client_count = 0;
> POE::Component::Server::TCP->new(
>   Alias => "job_server",
>   Port  => 32080,
> 
>   # Send the client a list of available commands when it connects.
>   ClientConnected => sub {
>     $client_count++;  },
> 
>   # Make sure the job is destroyed when the client exits.
>   ClientDisconnected => sub {
>     $client_count--;  },};
> 
>  I understand that I cannot access the master listener's heap by adding of the inline state handlers are added to the client sessions. Can you please show me some examples on how I can access connections entry from listener's heap.
> 
> 
> 
> Thanks,
> Krishna