Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 / /

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://177636]
[Tanktalus]: choroba: thanks, not sure why it wasn't doing that for me, but will try to figure it out. :)
[LanX]: can I copy a authotification cookie from mozilla and reuse it in LWP::Useragent?
[LanX]: nevermind
Tanktalus is at work, ssh'd home, using his cbstats bridge to talk on perlmonks CB. :)
[Tanktalus]: anyway, next is to figure out how to get postgres to agree that these are the same :)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2018-03-21 15:56 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (269 votes). Check out past polls.