| 1 | package Frontier::Daemon::Forking; | ||
| 2 | # $Id: Forking.pm,v 1.6 2004/01/23 19:48:33 tcaine Exp $ | ||
| 3 | |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use vars qw{@ISA $VERSION}; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | $VERSION = '0.02'; | ||
| 8 | |||
| 9 | 0 | ▶ | use Frontier::RPC2; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use HTTP::Daemon; | ||
| 11 | use HTTP::Status; | ||
| 12 | |||
| 13 | @ISA = qw{HTTP::Daemon}; | ||
| 14 | |||
| 15 | # most of this routine comes directly from Frontier::Daemon | ||
| 16 | sub new { | ||
| 17 | my $class = shift; | ||
| 18 | my %args = @_; | ||
| 19 | my $encoding = delete $args{encoding}; | ||
| 20 | my $self = $class->SUPER::new( %args ); | ||
| 21 | return undef unless $self; | ||
| 22 | |||
| 23 | my @options; | ||
| 24 | push @options, encoding => $encoding | ||
| 25 | if $encoding; | ||
| 26 | |||
| 27 | ${*$self}{methods} = $args{methods}; | ||
| 28 | ${*$self}{decode} = new Frontier::RPC2(@options); | ||
| 29 | ${*$self}{response} = new HTTP::Response 200; | ||
| 30 | ${*$self}{response}->header( 'Content-Type' => 'text/xml' ); | ||
| 31 | |||
| 32 | local $SIG{CHLD} = 'IGNORE'; | ||
| 33 | |||
| 34 | ACCEPT: | ||
| 35 | while ( my $conn = $self->accept ) { | ||
| 36 | my $pid = fork; | ||
| 37 | next ACCEPT if $pid; | ||
| 38 | |||
| 39 | if ( not defined $pid ) { | ||
| 40 | warn "fork() failed: $!"; | ||
| 41 | $conn = undef; | ||
| 42 | } | ||
| 43 | else { | ||
| 44 | my $request = $conn->get_request; | ||
| 45 | if ($request) { | ||
| 46 | if ($request->method eq 'POST' && $request->url->path eq '/RPC2') { | ||
| 47 | ${*$self}{'response'}->content( | ||
| 48 | ${*$self}{'decode'}->serve( | ||
| 49 | $request->content, | ||
| 50 | ${*$self}{'methods'}, | ||
| 51 | ) | ||
| 52 | ); | ||
| 53 | $conn->send_response(${*$self}{'response'}); | ||
| 54 | } else { | ||
| 55 | $conn->send_error(RC_FORBIDDEN); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | exit; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | 1; | ||
| 64 | __END__ | ||