Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-14 Thread Rocco Caputo
On Fri, Jun 13, 2003 at 07:22:38PM +0200, Bruno Boettcher wrote:
> On Fri, Jun 13, 2003 at 06:40:07PM +0200, Bruno Boettcher wrote:
> > »···   #program => &runshell,
>   ok.. silly me found out myself that i was lacking a \ 
> 
>   hmmm so far so good...
>   but now the progeam issues a prompt, and blocks irremediably after the
>   first char typed in.

[...]

>   anyway, how do i debug this now that it comes to a grinding halt? no
>   error messages nothing... i have no idea where it blocks now... :(

Depending on what causes the blockage, running the program with ktrace
or strace might give a clue.

-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Bruno Boettcher
On Fri, Jun 13, 2003 at 07:22:38PM +0200, Bruno Boettcher wrote:
>   besides the POE::Wheel::ReadLine syntax is quite strange...
uhm yeah.. its getting late and its very hot over here... uhm maybe that
explains

corrected myself the thing with the eent name and added the state to my
actual session...

doesn't change anything though the thing blocks as soon as the first
char is typed...

-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Bruno Boettcher
On Fri, Jun 13, 2003 at 01:03:59PM -0400, Rocco Caputo wrote:
> It makes the attempted delivery of a message to a non-existent session
> an error.
ok! hmm but since the messages are caught, there's no error...

> You may also want to set $session->option(default => 1) in your
> sessions, to make the attempt to deliver a message to a non-existent
> handler an error.
ok!

> Either through Alias parameters for component constructors or by calling
> $kernel->alias_set("alias") in _start.
argh.. sorry... read that indeed somewhere...

> It is possible, but it is not very "safe".  If you do not clean up
> session references properly, your program will leak memory (and probably
> other things).
awww uncool...

> It's better to pass around $session->ID instead.  These are like weak
> session references.  You can use them as destinations for post() and
> other things.
ok! also for the TCP intrinseque put method? those methods doesn't seem
to be attached as session methods... anyway will give it a try...

ok, since i passed on to use a POE readline i dropped the run stuff
still 

the whole thing stops as soon as i type in the first char
in case someone want's to give this mess a look:
http://bboett.dyndns.org/~bboett/leve.tgz

-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Bruno Boettcher
On Fri, Jun 13, 2003 at 06:40:07PM +0200, Bruno Boettcher wrote:
> »···   #program => &runshell,
  ok.. silly me found out myself that i was lacking a \ 

  hmmm so far so good...
  but now the progeam issues a prompt, and blocks irremediably after the
  first char typed in.

  besides the POE::Wheel::ReadLine syntax is quite strange...

  there's a $heap->{wheel} = POE::Wheel::ReadLine->new( InputEvent =>
  got_input );

  no package name, no object name. i am unsure if this will call the
  correct method...

  later on in the manpage is defined:
  sub got_input_handler

  different name but as it seems that's what it expected?
  i did the same thing... in one method i instantiated the shell object,
  and my object possesses the got_input_handler method

  at least there's no error message at compile time...

  but due to the readline the output to the console is strange, seems as
  if the carriage return codes are swallowed some where elaving a
  staircase effect to the prints

  anyway, how do i debug this now that it comes to a grinding halt? no
  error messages nothing... i have no idea where it blocks now... :(

-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Rocco Caputo
On Fri, Jun 13, 2003 at 06:40:07PM +0200, Bruno Boettcher wrote:
> On Fri, Jun 13, 2003 at 11:22:44AM -0400, Rocco Caputo wrote:
> > If messages are being sent but not received, you can easily find them
> > by setting POE::Kernel::ASSERT_EVENTS, like so:
> > 
> >   sub POE::Kernel::ASSERT_EVENTS () { 1 }
> >   use POE;
> > 
> > It's important to set ASSERT_EVENTS before using POE.pm (or POE::Kernel)
> > so that the module will see the value when it loads.
> uhm what's that supposed to do? doens't change anything in my script?

It makes the attempted delivery of a message to a non-existent session
an error.

You may also want to set $session->option(default => 1) in your
sessions, to make the attempt to deliver a message to a non-existent
handler an error.

> > Server::Web and Client::IRC read configuration options and create their
> > objects and sessions.  The configuration includes aliases for each
> > module, and the modules are designed to talk to each-other using those
> > aliases.
> and how do you set up those aliases?

Either through Alias parameters for component constructors or by calling
$kernel->alias_set("alias") in _start.

[...]

> > It's assumed that you assigned the aliases to ecah session, so you know
> > what they are.
> ??? when i try to add an Alias => "somename" to the create method of
> session, i get a compile error?

See above.

> > You should use POE::Wheel::ReadLine or Term::Visual.  Both work without
> > blocking your program.  Term::Visual is especially nice.
> ok! switched to POE::Wheel::ReadLine (installed by default...)
> 
> in the meantime another problem arouse
> 
> the heap is different for each session, right?
> now, i have on one side a TCP connection and on another a session with
> the shell implementation that needs to send the info through that
> pipe... is it safe to exchange the ref to the server ?

It is possible, but it is not very "safe".  If you do not clean up
session references properly, your program will leak memory (and probably
other things).

It's better to pass around $session->ID instead.  These are like weak
session references.  You can use them as destinations for post() and
other things.

> hmmm now on:
> my $task = POE::Wheel::Run->new
>   (·
> »···   #Program => runShell(@_),
> »···   #Program => &runShell,
> »···   Program => &POE::Component::Leve::leveShell::runShell,

You are saying that the Program is the return value of the function
POE::Component::Leve::leveShell::runShell().  Really you want it to be a
reference to the function:

  Program => \&runShell,
  Program => \&POE::Component::Leve::leveShell::runShell,

> and how do i pass the runshell call its args? i need the usual
> @_[OBJECT, KERNEL etc] input

The child program is not run like the rest of POE.  It is called only
once, with the parameters given in POE::Wheel::Run's ProgramArgs, and
the child process will exit when it returns.

-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Bruno Boettcher
On Fri, Jun 13, 2003 at 11:22:44AM -0400, Rocco Caputo wrote:
> If messages are being sent but not received, you can easily find them
> by setting POE::Kernel::ASSERT_EVENTS, like so:
> 
>   sub POE::Kernel::ASSERT_EVENTS () { 1 }
>   use POE;
> 
> It's important to set ASSERT_EVENTS before using POE.pm (or POE::Kernel)
> so that the module will see the value when it loads.
uhm what's that supposed to do? doens't change anything in my script?

> Also see http://poe.perl.org/?POE_Documentation/Beginners_Guide
heh :D i allready went through that one innumerable times...

> Server::Web and Client::IRC read configuration options and create their
> objects and sessions.  The configuration includes aliases for each
> module, and the modules are designed to talk to each-other using those
> aliases.
and how do you set up those aliases?

> > - events are generated and distributed randlomly to the listeners, once
> > one listener claims the event, it isn't propsed to the other sessions,
> >   right? or is there some sort of telling that the events should be
> >   proposed also to the other sessions?
> 
> The English of this question is very bad.  Because I can't quite
uhm sorry...

> The post() method sends events to a session.  That session may be
> different from the one that calls post().
using the post( session_alias_that_i_dont_get_how_to_define =>
'eventname') paradign, right?

> The yield() method sends events to the session that called it.
ok! got that one

> Events are queued very deterministically.  They are stored in what is
> essentially an array, in due-time order.  Alarms and delays are usually
> due in the future, so they reside later in the queue.  Events
> representing immediate conditions are enqueued for time(), so they
> happen in more-or-less FIFO (first in, first out) order.
the random was aimed at to who processes it, didn't get that the post
method applies exclusively to the actual session.

> The signal() call is for simulating signals without using kill() or
> involving the operating system.
yep, that's why i was surpised to see referencing it as a viable
intersession message paradigm

> Signals may be used to broadcast one event to many sessions at once.
> Posted events are more point-to-point.
and that what i need

> > - sessions like the TCP stuff and the IRC module register an alias iwth
> > which it is possible to get it later on globally from the heap, how do i
> > setup such a mechanism? alias isn't a recognized var of session?
> 
> Aliases are not stored in the heap.  You may retrieve the aliases for a
> session with $kernel->alias_list($session) but there isn't a global
> registry of them.
> 
> It's assumed that you assigned the aliases to ecah session, so you know
> what they are.
??? when i try to add an Alias => "somename" to the create method of
session, i get a compile error?

> You should use POE::Wheel::ReadLine or Term::Visual.  Both work without
> blocking your program.  Term::Visual is especially nice.
ok! switched to POE::Wheel::ReadLine (installed by default...)

in the meantime another problem arouse

the heap is different for each session, right?
now, i have on one side a TCP connection and on another a session with
the shell implementation that needs to send the info through that
pipe... is it safe to exchange the ref to the server ?


hmmm now on:
my $task = POE::Wheel::Run->new
  (·
»···   #Program => runShell(@_),
»···   #Program => &runShell,
»···   Program => &POE::Component::Leve::leveShell::runShell,
··
StdoutFilter => POE::Filter::Reference->new(),
StdoutEvent  => "task_result",
StderrEvent  => "task_debug",
CloseEvent   => "task_done",
  );

$heap->{task}->{ $task->ID } = $task;

i get a 
_start::SH posted runshell
   Debug: can't exec (1) in child pid 
4558: Datei oder Verzeichnis nicht gefunden at /usr/share/perl5/POE/Wheel/Run.pm line 
380.

seems i can't get the syntax correct?

and how do i pass the runshell call its args? i need the usual @_[OBJECT, KERNEL etc] 
input


-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Rocco Caputo
On Fri, Jun 13, 2003 at 04:19:57PM +0200, Bruno Boettcher wrote:
> Hello!
> 
> again i am stuck in a surely trivial and stupid problem, showing again
> that i didn't understand a single thing about POE

[...]

> unfortunately that event is gobbled up somewhere by some other
> session i suppose the POE::Component::Client::TCP thing is
> responsible for that...

If messages are being sent but not received, you can easily find them
by setting POE::Kernel::ASSERT_EVENTS, like so:

  sub POE::Kernel::ASSERT_EVENTS () { 1 }
  use POE;

It's important to set ASSERT_EVENTS before using POE.pm (or POE::Kernel)
so that the module will see the value when it loads.

[...]

> GENERAL QUESTIONS:
> 
> This shuffled up again the fact that i still have problems understanding
> POE

Also see http://poe.perl.org/?POE_Documentation/Beginners_Guide

> - i have several objects, they might start up their own sessions, since
> POE is somehow a global thing, i need to call the kernel run method only
> once somewhere, right?

Yes.  I usually call POE::Kernel->run() after setting up the initial
objects for a program.  Several of my bot programs look like this:

  #!/usr/bin/perl -w
  # $Id: pastebot.perl,v 1.4 2003/02/03 04:50:17 rcaputo Exp $

  use strict;

  use POE;
  use Server::Web;
  use Client::IRC;

  $poe_kernel->run();
  exit 0;

Server::Web and Client::IRC read configuration options and create their
objects and sessions.  The configuration includes aliases for each
module, and the modules are designed to talk to each-other using those
aliases.

It's an interesting way to write programs, and I need to document it,
but the programs themselves are very bad examples of coding style.

> - events are generated and distributed randlomly to the listeners, once
> one listener claims the event, it isn't propsed to the other sessions,
>   right? or is there some sort of telling that the events should be
>   proposed also to the other sessions?

The English of this question is very bad.  Because I can't quite
understand it, I will answer every question I think it may be.

Events are generated as real-world things happen.  "This file has input
waiting."  "At the event, the time will be 16:00 UTC."  "The user is
vainly attempting to suspend the program with ^Z."  "This child process
has closed its output filehandles."

Events also are generated when you call POE::Kernel's post(), yield(),
or signal() methods.

The post() method sends events to a session.  That session may be
different from the one that calls post().

The yield() method sends events to the session that called it.

Events are queued very deterministically.  They are stored in what is
essentially an array, in due-time order.  Alarms and delays are usually
due in the future, so they reside later in the queue.  Events
representing immediate conditions are enqueued for time(), so they
happen in more-or-less FIFO (first in, first out) order.

> - to the above question addendum, i didn't get the difference between
> post and signal, when should i use which one? in all the code i see only
> the use of post, never signal, should i use signal this time??

The signal() call is for simulating signals without using kill() or
involving the operating system.

Signals are broadcast to every session that has used sig() to listen for
them.  Currently they are also broadcast to every other session, under
the _signal event, but that is deprecated and will go away soon.

Signals may be used to broadcast one event to many sessions at once.
Posted events are more point-to-point.

> - sessions like the TCP stuff and the IRC module register an alias iwth
> which it is possible to get it later on globally from the heap, how do i
> setup such a mechanism? alias isn't a recognized var of session?

Aliases are not stored in the heap.  You may retrieve the aliases for a
session with $kernel->alias_list($session) but there isn't a global
registry of them.

It's assumed that you assigned the aliases to ecah session, so you know
what they are.

> - i have a job that is returning only when the wholething closes down
> (= a shell) with very slow input (a human user) that qualifies as a long
> running task...  actually i run it inside a POE event handler, but
> should i use the ::Run object instead? do i cause some havoc somewhere
> by blocking the return of that event processing or doesn't it matter??

You should use POE::Wheel::ReadLine or Term::Visual.  Both work without
blocking your program.  Term::Visual is especially nice.

-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/


creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Bruno Boettcher
Hello!

again i am stuck in a surely trivial and stupid problem, showing again
that i didn't understand a single thing about POE

(thus the general POE questions at the end of this mail, you might want
 ot jump directly there searching for 'GENERAL QUESTIONS')

anyways...

i am trying to move a service actually based on a script run amidst
xchat to a client server type setup (that's why i needed the ssl
layer...)

actually it works without the ssl stuff since i decided to continue
setting the thing up without that lib, to see if its possible to get it
actually working...

i took the client server example from the cook book and began to extend
it... worked quite nicely until i decided to integrade a Term::ReadLine
to the client...

the first thing i noticed was that it completely blocked the POE
system... thus i tryed to get it running through the event system of
POE

for this i created a new class, which starts an own session (listening
to 'shell' events) and starting on the "runShell" event a new
instance of Term::ReadLine 

unfortunately that event is gobbled up somewhere by some other
session i suppose the POE::Component::Client::TCP thing is
responsible for that...

i have put the stuff up on http://bboett.dyndns.org/~bboett/leve.tgz

the interesting parts are: POE::Component::Leve::leveShell
and search for runShell (3 occurences: set up of the session, sending
the runshell event, and the actual thing that set ups the shell)

the thing gots called from patternQuery.pl, CTOR of
POE::Component::Client::TCP under the event Connected (shell->init)

to start the whole system, run in one shell patternServer.pl, in another
patternQuery.pl (that's the client...)

so if someone could be kind enough and look through my messed up code
and tell my what's going wrong, why and how to correct it...


GENERAL QUESTIONS:

This shuffled up again the fact that i still have problems understanding
POE


- i have several objects, they might start up their own sessions, since
POE is somehow a global thing, i need to call the kernel run method only
once somewhere, right?

- events are generated and distributed randlomly to the listeners, once
one listener claims the event, it isn't propsed to the other sessions,
  right? or is there some sort of telling that the events should be
  proposed also to the other sessions?

- to the above question addendum, i didn't get the difference between
post and signal, when should i use which one? in all the code i see only
the use of post, never signal, should i use signal this time??

- sessions like the TCP stuff and the IRC module register an alias iwth
which it is possible to get it later on globally from the heap, how do i
setup such a mechanism? alias isn't a recognized var of session?

- i have a job that is returning only when the wholething closes down
(= a shell) with very slow input (a human user) that qualifies as a long
running task...  actually i run it inside a POE event handler, but
should i use the ::Run object instead? do i cause some havoc somewhere
by blocking the return of that event processing or doesn't it matter??

if you got this far, my gratefulness and sympathy, ethernal adoration to
you if you manage to help me on that :D 
sorry for the long post...
and if stuff isn't very clear: please keep in mind that i am not a
native english speaker


  
-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===