Writing network daemon's is hard.
That's why I prefer not to do it. So for PPerl, I decided to have a go with Net::Server (after having originally written the daemon code using the stuff in the perl cookbook, and failed miserably). It worked really well, and despite being a little slower than my own custom daemon, it seemed really reliable and stable.
That was until I tried it on a real live system. I ended up with defunct processes left right and center, and finally the whole system just locked right up. Bah.
So what could I do? Well, I decided to bite the bullet and re-write it. So I grabbed code from Lincoln Stein's Network Programming with Perl book - the pre-fork web server in there, and adapted it to my needs. After much grappling it seems to be mostly working, though there are some extremely wierd things going on:
- My changing of STDERR to go to a file isn't working right for warn()'s unless I add in a $SIG{__WARN__} handler to print directly to STDERR.
- Occasionally it'll die with a "Connection reset by peer".
- Sometimes the <ARGV> magic fails for unusual reasons.
I guess I need to copy a bit more of the code from Net::Server to see where I'm going wrong (because now I don't have defunct processes any more).
Anyone got good experience with this kind of thing, or an alternate framework to Net::Server?
Stem (Score:2)
Note to self (Score:2)
Re:Stem (Score:2)
Plus much as Stem looks neat, it's not CPAN installable.
Re:Stem (Score:2)
Asynchronous isn't an issue. You can have a synchronous server with asynchronous code internally. Stem comes with a module, Stem::SockMsg that implements a socket-based listener. You use that and it feeds a message into your real server, which then replies. All the synchronous bits are managed by the Stem::SockMsg module.
Having written such a thing (to interface to a client that is _not_ Stem-based) I can tell you its pretty darn easy to do.
Re:Stem (Score:2)
Re:Stem (Score:2)
But you still need a single process listening on the socket that hands off the connection to the preforked processes, right?
Re:Stem (Score:2)
Re:Stem (Score:1)
Re:Stem (Score:2)
Net::Server woes (Score:2)
Re:Net::Server woes (Score:1)
I use Net::Server as an option in my RPC::XML package, an alternative to using the accept-loop in HTTP::Daemon. I also have a set of tests in the t/ directory for it, in which I manipulate the settings at run-time to control the log file and such. I haven't had any problems, but to be fair I probably have run anything yet that's on the scale of PPerl.
--rjray
non-forking (Score:2)
-- ask bjoern hansen [askbjoernhansen.com], !try; do();
Re:non-forking (Score:2)
On the other hand, I've just "solved" or hacked around the ARGV magic stuff. Not sure why what I did worked, but that's what you get with wierd stuff like I'm trying to pull off.