Daemon/AnyDaemon.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 25 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 124 SCAR 30.0
CC
4
Cov
0%
_run
12.0
handle_connection
6.0
new
2.0
CRAP 20.0
1 # Copyrights 2007-2018 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution XML-Compile-SOAP-Daemon. Meta-POD
6 # processed with OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package XML::Compile::SOAP::Daemon::AnyDaemon;
10 use vars '$VERSION';
11 $VERSION = '3.14';
12  
13  
14 use warnings;
15 use strict;
16  
17 # Any::Daemon at least version 0.13
18 use parent 'XML::Compile::SOAP::Daemon', 'Any::Daemon';
19  
20 use Log::Report 'xml-compile-soap-daemon';
21  
22 use Time::HiRes qw/time alarm/;
23 use Socket qw/SOMAXCONN/;
24 use IO::Socket::INET ();
25  
26 use XML::Compile::SOAP::Util qw/:daemon/;
27 use XML::Compile::SOAP::Daemon::LWPutil;
28  
29  
30 sub new($%)
31 { my ($class, %args) = @_;
32 my $self = Any::Daemon->new(%args);
33 (bless $self, $class)->init(\%args); # $ISA[0] branch only
34 }
35  
36 sub setWsdlResponse($;$)
37 { my ($self, $fn, $ft) = @_;
38 trace "setting wsdl response to $fn";
39 lwp_wsdl_response $fn, $ft;
40 }
41  
42 #-----------------------
43  
44 sub _run($)
45 { my ($self, $args) = @_;
46  
47 my $name = $args->{server_name} || 'soap server';
48 lwp_add_header
49 'X-Any-Daemon-Version' => $Any::Daemon::VERSION
50 , Server => $name;
51  
52 my $socket = $args->{socket};
53 unless($socket)
54 { my $host = $args->{host} or error "run() requires host";
55 my $port = $args->{port} or error "run() requires port";
56  
57 $socket = IO::Socket::INET->new
58 ( LocalHost => $host
59 , LocalPort => $port
60 , Listen => ($args->{listen} || SOMAXCONN)
61 , Reuse => 1
62 ) or fault __x"cannot create socket at {interface}"
63 , interface => "$host:$port";
64  
65 info __x"created socket at {interface}", interface => "$host:$port";
66 }
67 $self->{XCSDA_socket} = $socket;
68 lwp_socket_init $socket;
69  
70 $self->{XCSDA_conn_opts} =
71 +{ timeout => ($args->{client_timeout} || 30)
72 , maxmsgs => ($args->{client_maxreq} || 100)
73 , reqbonus => ($args->{client_reqbonus} || 0)
74 , postprocess => $args->{postprocess}
75 };
76  
77 my $child_init = $args->{child_init} || sub {};
78 my $child_task = sub {$child_init->($self); $self->accept_connections};
79  
80 $self->Any::Daemon::run
81 ( child_task => $child_task
82 , max_childs => ($args->{max_childs} || 10)
83 , background => (exists $args->{background} ? $args->{background} : 1)
84 );
85 }
86  
87 sub accept_connections()
88 { my $self = shift;
89 my $socket = $self->{XCSDA_socket};
90  
91 while(my $client = $socket->accept)
92 { info __x"new client {remote}", remote => $client->peerhost;
93 $self->handle_connection(lwp_http11_connection $self, $client);
94 $client->close;
95 }
96 }
97  
98 sub handle_connection($)
99 { my ($self, $connection) = @_;
100 my $conn_opts = $self->{XCSDA_conn_opts};
101 eval {
102 lwp_handle_connection $connection
103 , %$conn_opts
104 , expires => time() + $conn_opts->{timeout}
105 , handler => sub {$self->process(@_)}
106 };
107 info __x"connection ended with force; {error}", error => $@
108 if $@;
109 1;
110 }
111  
112 sub url() { "url replacement not yet implemented" }
113 sub product_tokens() { shift->{prop}{name} }
114  
115 #-----------------------------
116  
117  
118 1;