select_read( $socket, "event to fire") tells the kernel to fire the event
"event to fire" to the current session whenever there is data that can be
read from $socket

yield("event") tells the kernel to queue the signal, event, whatever you
want to call it, to the current session

On 2/23/07, Fei Liu <[EMAIL PROTECTED]> wrote:

P Dobranski wrote:
> POE::Kernel::yield is sort of a shortcut for 'post'.
> You 'yield' an event in the current session.
> It is the same as 'post'ing the event to the current session.
>
> $kernel->yield('some_event_handler');
>
> is roughly the same as
> $kernel->post($my_session, 'some_event_handler');
>
> (assuming both statements happen in the same session).
>
> select_read/select_write allow you to get events when a file
> descriptor becomes ready to read or write without you having to manage
> your own select() loops.
>
> On 2/22/07, Fei Liu <[EMAIL PROTECTED]> wrote:
>>
>> Hi group, just wondering what's the difference between
>> POE::Kernel::select_read/write method and POE::Kernel::yield method?
How
>> should I use select_read/select_write? Do they do anything special
about
>> the events that they select? Thanks,
>>
>> Fei

Thanks for your reply. I was reading Rocco's tutorial
(http://poe.perl.org/?Evolution_of_a_POE_Server) on POE and my question
came up when he first introduced POE framework to replace the original
non-blocking tcp echo server. In the example no Wheel or
Component::Server::TCP were used, it was basic POE::Session.

POE::Session->create
  ( inline_states =>
      { _start => \&server_start,
        event_accept => \&server_accept,
        event_read   => \&client_read,
        event_write  => \&client_write,
        event_error  => \&client_error,
      }
  );

sub server_start {
    my $server = IO::Socket::INET->new
      ( LocalPort => 12345,
        Listen => 10,
        Reuse  => "yes",
      ) or die "can't make server socket: [EMAIL PROTECTED]";

    $_[KERNEL]->select_read( $server, "event_accept" );
}

Here it seems select_read works sort of like yield, doesn't it? It
yields to event_accept handler? Quote 'The _start handler creates the
server socket and allocates its event generator with select_read()",
what's a event generator and what does it do?

Another thing confusing me here is that there seems to be a total of one
session in this echo server implementation, how can it handle mutliple
clients?

Sorry for so many questions, I can use POE just fine but I want to
understand what's going on under the hood.

Fei


Reply via email to