Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Re: Re: Re: How do I close a POE SocketFactory Socket?

by rcaputo (Chaplain)
on Jun 27, 2002 at 05:37 UTC ( #177636=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: How do I close a POE SocketFactory Socket?
in thread How do I close a POE SocketFactory Socket?

If I understand correctly, you want the server to start talking first. That's easy, really. POE::Wheel::ReadWrite instances are ready to be used immediately.

sub agent_handler { # ... my $wheel = new POE::Wheel::ReadWrite(...); $heap->{wheel}->{$wheel->ID} = $wheel; $wheel->put("Greetings from MyServer version 1.0"); # ... }

POE can be used to write single-tasking programs that block, but network servers don't usually don't fall into this category. It's possible to block temporarily, though, and short blockages might go unnoticed. (Actually, a POE program is just a series of very short blocking operations. They usually occur quickly enough that people don't notice.)

The heap is reserved almost entirely for your storage. Its main purpose is to store persistent information between events. If I understand your question, this is exactly what you want to do.

If you decide to keep copies of socket handles in the heap, be sure to delete them when you're done with them. Otherwise your server will leak memory and file handles, and it will crash in short order.

sub agent_handler { # ... $heap->{wheel}->{$wheel->ID} = $wheel; $heap->{socket}->{$wheel->ID} = $socket; # ... } sub agent_error { # ... delete $heap->{wheel}->{$wheel_id}; delete $heap->{socket}->{$wheel_id}; }

If at all possible, however, you should use $wheel->put() to send data. Your $socket is in non-blocking mode, and all the standard caveats about print() and <> apply.

More notes.

If you're going to store a lot of things in the heap for each wheel, consider turning things inside out.

$heap->{$wheel->ID} = { wheel => $wheel, socket => $socket, foo => $foo, };

Then you can delete it all at once.

delete $heap->{$wheel_id};

Interview? I get this sort of Q&A all the time. :)

-- Rocco Caputo / poe.perl.org / poe.sf.net

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://177636]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-01-17 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (196 votes). Check out past polls.

    Notices?