• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10/CPANInternal-159.1/SOAP-Lite-1.11/examples/SOAP/Transport/HTTP/Daemon/
1package SOAP::Transport::HTTP::Daemon::ForkOnAccept;
2
3use strict;
4use vars qw(@ISA);
5use SOAP::Transport::HTTP;
6
7# Idea and implementation of Michael Douglass
8
9@ISA = qw(SOAP::Transport::HTTP::Daemon);
10
11sub handle {
12  my $self = shift->new;
13
14  CLIENT:
15  while (my $c = $self->accept) {
16    my $pid = fork();
17
18    # We are going to close the new connection on one of two conditions
19    #  1. The fork failed ($pid is undefined)
20    #  2. We are the parent ($pid != 0)
21    unless( defined $pid && $pid == 0 ) {
22      $c->close;
23      next;
24    }
25    # From this point on, we are the child.
26
27    $self->close;  # Close the listening socket (always done in children)
28
29    # Handle requests as they come in
30    while (my $r = $c->get_request) {
31      $self->request($r);
32      $self->SOAP::Transport::HTTP::Server::handle;
33      $c->send_response($self->response);
34    }
35    $c->close;
36    return;
37  }
38}
39
401;
41