Response below.

On Thu, 27 Jan 2005 20:15:22 +0100, Bas Schulte <[EMAIL PROTECTED]> wrote:
> Hi David,
> 
> On donderdag, jan 27, 2005, at 00:45 Europe/Amsterdam, David Davis
> wrote:
> 
> >> 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.
> 
> Yes, this part I understand now :)
> 
> 
> >> 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.
> 
> Argh. I don't understand why I can't pass the reference to the wheel
> though. Why is it bad?

It has to do with garbage collection.  Wheels are linked to the
session, and if you want to have it properly clean up and disconnect,
don't pass it around.

Rocco, please chime in if I'm wrong.

> 
> >  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]); }
> 
> I tried it, seems to work fine.

It seems to...

> 
> 
> > 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 don't want a hack :)

Nor do I want to suggest one.

> I still don't understand what the "right" solution is though. I saw
> something about detaching a session from it's parent as well. Maybe I
> can create a session in the tcp server session, start the wheel in that
> child session and then detach that session from the tcp server's
> session. Sounds ok to me but I'm still not sure what the "right" way is.
> 

You could do that.  I have never tried it though.  Something like this
might work:

POE::Session->create(
  inline_states => {
    _start => {
        $_[HEAP]->{wheel} = POE::Wheel::Run->.......
        $_[KERNEL]->detach_myself();
    },
     [ other events ]
  },
);

> 
> > Just don't pass wheel handles around freely.
> 
> Does that mean I can't pass the result of "POE::Wheel::Run->new(...)"
> around as well? I have this:
> 
> my $child = new POE::Wheel::Run(....);
> 
> Then I keep the $child around so I can kill it later on. Is that bad?

No, keeping it in the heap is fine. When the wheel dies off (program
finishes) the session will clean itself up and go away.

> 
> Thanks,
> 
> Bas.
> 
> 

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

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

Reply via email to