Response within,

On Wed, 26 Jan 2005 22:36:25 +0100, Bas Schulte <[EMAIL PROTECTED]> wrote:
> Hi David,
> 
> On woensdag, jan 26, 2005, at 20:01 Europe/Amsterdam, David Davis wrote:
> 
> > Setup another session to handle wheel run, and use $_[SENDER] to reply
> > back if the client is still connected.
> 
> That's a bit too compact for me :)
> 
> Where do I do what, that's basically my problem:
> 
> Can I start a new session in client_input, start a new POE::Wheel::Run
> from there *in* the ClientInput state? Or does that create a
> (parent-child?) dependency with the POE::Component::Server::TCP
> session? That runs sour when the client disconnects?

Yes it does create a wheel in that session handling the input for that client.
Your session_stdout even is getting sent to that session, and you
don't have an event by that name in that session created by
Server::TCP.

> 
> I'm confused as to what session should manage the events fired by the
> POE::Wheel that manages my child. I think I need to "detach" the
> started wheel from the tcp session but don't know how.
> 
> I now do this:
> 
> POE::Session->create(
>     inline_states =>
>     {
>        _start                => \&controller_start,
> 
>        do_the_start => \&do_the_start,
> 
>        ...
>     },
> );
> 
> sub controller_start
> {
>     my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION ];
> 
>     $heap->{server} = new POE::Component::Server::TCP(
>           Alias           => "controld",
>           Port            => 6666,
>           ClientInput     => \&client_input,
>           ClientConnected => \&client_connected,
>           Args            => [ $session ],
>     );
> }
> 
> sub do_the_start
> {
>     my ($kernel, $heap, $session, $input, $client) = @_[KERNEL, HEAP,
> SESSION, ARG0, ARG1];
> 
>     my $child = new POE::Wheel::Run(
> 
>        Program        => $input,  ## Not recommended :)
> 
>        ...
> 
>        StdoutEvent    => 'session_stdout',
> 
>        ...
>     );
> 
>     ## If this went well, send response back to client:
> 
>     client->put("OK");

Missing a $ here

> }
> 
> ...
> 
> $poe_kernel->run();
> 
> sub client_connected
> {
>     my ($session, $heap, $kernel, $controllingSession) = @_[ SESSION,
> HEAP, KERNEL, ARG0];
> 
>     $heap->{controllingSession} = $controllingSession;
> }
> 
> sub client_input
> {
>     my ($session, $heap, $kernel, $input, $wheel) = @_[ SESSION, HEAP,
> KERNEL, ARG0, ARG1 ];
> 
>     ## pass client's input and reference to our wheel
> 
>     $kernel->post($heap->{controllingSession}, 'do_the_start', $input,
> $heap->{client});

Don't pass the client wheel, that's bad when using post.  It would be
better if you used $kernel->post($_[SENDER] => send => 'OK');  and
setup an inline_state called send that did a if ($heap->{client}) {
$heap->{client}->put($_[ARG0]); }

You could also change this to a call() and be ok with using it as a
hack.  Just don't pass wheel handles around freely.

> }
> 
> I basically do not respond from within the ClientInput state, but do a
> post to another session, with both the client's input and a reference
> to the tcp wheel.
> 
> This works but I'm somewhat confused as to why I can't just fork a
> child from within the ClientInput state using POE::Wheel::Run,
> conceptually that is. So I'd love someone explain me the concept ;)

See above. The wheel becomes a child of the client control session.

> 
> Regards,
> 
> Bas.
> 
> 

I hope this helps.

-- 
David Davis
Perl Programmer
http://teknikill.net/

Try CPAN Suggest!
http://cpan.teknikill.net/

Reply via email to