On Feb 23, 2007, at 09:34, Fei Liu wrote:

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?

It is somewhat like yield(), except that it only sends the event when a filehandle has data ready to be read. yield() however sends the event at the next available opportunity.

Event generators are things that generate events in response to external stimuli. select_read() manages an event generator within POE::Kernel. Also consider delay(), which generates an event after a certain time has elapsed.

Your code can also be one or more event generators. Any time you call post() or yield() you're generating a new event.

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?

A single session can handle multiple clients. The handler for "event_accept" accepts each new connection and calls select_read() to be made aware when the client sends data. While there are active connections, the one session is watching multiple filehandles at once.

The client_read() function described later in the article handles data sent by each client. The $client parameter is a copy of the client's socket. It separates each client's data by using hashes keyed on the client sockets. For example, $inbuffer{$client} and $outbuffer{$client} are the client connection's input and output buffers.

There will be no hash collisions since no two clients will have the same socket at the same time.

Conscientious deletion of old data from the hashes is important here. A new connection may have the same socket as a previously closed one, and you don't want data to bleed between connections. Likewise, you may see memory or other leaks if you don't clean up the hashes as clients disconnect.

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

I'm all for that. :)

--
Rocco Caputo - [EMAIL PROTECTED]


Reply via email to