seaver has asked for the wisdom of the Perl Monks concerning the following question:

Dear all,

Me again...

I'm using a SOAP::Lite XMLRPC daemon to accept requests from an applet. So far it works very well, even when accepting multiple requests

However, it has developed an annoying habit recently of actually EXITING once it's finished all requests...which is weird...any help would be appreciated

thanks

Sam

#!/usr/bin/env perl use XMLRPC::Transport::HTTP; use XML::Xerces; use XML::Xerces::DOMParse; use Carp; use Fcntl ":flock"; my $daemon = XMLRPC::Transport::HTTP::Daemon -> new (LocalPort => 8081, Reuse => 1) -> dispatch_to('Monster') ; print "Contact to XMLRPC server at ", $daemon->url, "\n"; $daemon->handle; package Monster; sub go{ shift if UNIVERSAL::isa($_[0] => __PACKAGE__); my $CP = shift; my $filePath = "/usr/local/jakarta-tomcat-4.1.12/webapps/monster/j +obs/"; $|=1; my $parser = XML::Xerces::DOMParser->new(); $parser->setCreateEntityReferenceNodes(1); my $error_handler = XML::Xerces::PerlErrorHandler->new(); $parser->setErrorHandler($error_handler); my $in; eval {$in = XML::Xerces::MemBufInputSource->new($CP);}; error($@) if $@; eval {$parser->parse($in);}; error($@) if $@; my $doc = $parser->getDocument(); my $cps = $doc->getElementsByTagName("ChainPairs"); my $id = $cps->item(0)->getAttributes()->getNamedItem("index")->ge +tNodeValue(); my $filePath2 = "$filePath$id/"; mkdir $filePath2; my $fileNode = $doc->getElementsByTagName("File"); my $file = $fileNode->item(0)->getChildNodes->item(0)->getNodeValu +e(); $file = substr($file, 37); $pdb = substr($file, 0, -4); open (F, ">$filePath2$pdb.cp" ) or die "couldn't open file $pdb.cp +: $!"; flock(F, LOCK_EX); print F $CP; flock(F, LOCK_UN); close F; use POSIX ":sys_wait_h"; sub REAPER{ my $child; while (($child = waitpid(-1,&WNOHANG)) > 0) { $Kid_Status{$child} = $?; } $SIG{CHLD} = \&REAPER; # still loathe sysV } $SIG{CHLD} = \&REAPER; exec("/usr/local/bin/monster", "-i$id", "$filePath$file") unless fork( +); return 0; }

Replies are listed 'Best First'.
Re: Daemon exits!
by sgifford (Prior) on Jun 19, 2003 at 01:23 UTC
    I've never used XMLRPC::Transport::HTTP::Daemon, but it seems like:
    while(1) { $daemon->handle; }
    would solve your problem.
      It TOTALLY solved my problem, i cant believe how simple that was! But honestly, why would someone have

       $daemon->handle;

      without it being a daemon? is it a bug that I had to put the

      while(1)

      in?

      thanks so much anyway!

      Sam

Re: Daemon exits!
by tall_man (Parson) on Jun 19, 2003 at 15:27 UTC
    Perl 5.8.0 has a problem with reapers interrupting accept loops, as mentioned here: Re: perl 5.8 killed my socket!. Putting a loop around the handling part to force it not to exit is the best work-around I know of.