Loading ...
Sorry, an error occurred while loading the content.

700RE: [soaplite] Forking from a dispatched class

Expand Messages
  • Meisner, Sean
    Jul 31, 2001
      Michael,
      This sounds a lot like a problem I had. To do exactly the kind
      of thing you want to do with forks in my SOAP server, I had to
      create my own version of SOAP::Transport::HTTP::Daemon, with a modified
      handle() method. Here's the code for that package:

      package KillSocketSOAPHTTPDaemon;

      use strict;
      use vars qw(@ISA);
      use SOAP::Transport::HTTP;

      @ISA = qw(SOAP::Transport::HTTP::Daemon);

      sub handle {
      my $self = shift->new;
      while (my $c = $self->accept) {
      while (my $r = $c->get_request) {
      $self->request($r);
      $self->SOAP::Transport::HTTP::Server::handle;
      $c->send_response($self->response)
      }
      $c->shutdown(2);
      $c = undef;
      }
      }

      1;

      Save this code in a file somewhere in your path, and in
      the mainline of your SOAP server, say

      use KillSocketSOAPHTTPDaemon;

      my $daemon = KillSocketSOAPHTTPDaemon->new( .........

      INSTEAD of

      use SOAP::Transport::HTTP::Daemon;

      my $daemon = SOAP::Transport::HTTP::Daemon->new( .........


      The problem is that when you fork under Solaris, your forked process
      will contain a copy of the open socket in the HTTP::Daemon ($c in the
      code above). You don't want that. I call shutdown() on that socket here,
      replacing close() in the original, so the socket is closed in all child
      processes and things should work as expected.

      Hope I explained that clearly enough!!

      Cheers,

      Sean

      > -----Original Message-----
      > From: Michael Percy [mailto:mpercy@...]
      > Sent: Tuesday, July 31, 2001 3:41 PM
      > To: 'soaplite@yahoogroups.com'
      > Subject: [soaplite] Forking from a dispatched class
      >
      >
      > Hi,
      > When inside a dispatched handler (using SOAP Daemon), I am
      > unable to fork a
      > new process to do work without it blocking forever. Even if I localize
      > $SIG{CHLD}, run POSIX::setsid(), close STDIN, STDOUT &
      > STDERR, or fork()
      > twice... the parent process will block until all children exit.
      >
      > What I really want to do is send a SOAP request to a handler
      > that spawns off
      > a child to do work, so the SOAP request can return a port
      > number to the
      > client to contact the spawned child. This behavior is located
      > in a spawn()
      > subroutine which refuses to return to the SOAP client (until
      > all children
      > are dead).
      >
      > Is this a common problem, or has no one heard of this kind of thing
      > happening? I am running ActiveState Perl 5.6.0 on Solaris 8
      > with SOAP::Lite
      > 0.51.
      >
      > Thanks!
      > Mike
      >
      > ------------------------ Yahoo! Groups Sponsor
      > ---------------------~-->
      > Small business owners...
      > Tell us what you think!
      > http://us.click.yahoo.com/vO1FAB/txzCAA/ySSFAA/W6uqlB/TM
      > --------------------------------------------------------------
      > -------~->
      >
      > To unsubscribe from this group, send an email to:
      > soaplite-unsubscribe@yahoogroups.com
      >
      >
      >
      > Your use of Yahoo! Groups is subject to
      http://docs.yahoo.com/info/terms/
    • Show all 12 messages in this topic