Server.pm

filter: Statementstmt 37.3% 28 / 75 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 33.9% 35 / 103 CC 11 SCAR 44.0
CC
11
Cov
30%
server
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 81.1
« Active.pm ↑ Summary Connection.pm »
1 # -*- Mode: Perl -*-
2 # Server.pm --
3 # ITIID : $ITI$ $Header $__Header$
4 # Author : Ulrich Pfeifer
5 # Created On : Sat Sep 28 13:53:36 1996
6 # Last Modified By: Ulrich Pfeifer
7 # Last Modified On: Tue Apr 1 13:23:28 1997
8 # Language : CPerl
9 # Update Count : 154
10 # Status : Unknown, Use with caution!
11 #
12 # (C) Copyright 1996, Universität Dortmund, all rights reserved.
13 #
14  
15 package NNML::Server;
16 1 ▶use vars qw($VERSION @ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use NNML::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use NNML::Config qw($Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use NNML::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 require Exporter;
25 1 @ISA = qw(Exporter);
26 1 @EXPORT = qw(server unspool);
27  
28 1 $VERSION = do{my @r=(q$Revision: 1.13 $=~/(\d+)/g);sprintf "%d."."%02d"x$#r,@r};
29  
30 0 ▶sub server {
Subroutine server: not called CC=11 SCAR=48.8
Pod undocumented
31 0 my %opt = @_;
32 0 ▶ my $port = $opt{port} || $Config->port;
Condition0%0/3
$opt{'port'} || $NNML::Server::Config->port
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{'port'} || $NNML::Server::Config->port
$opt{'port'} $NNML::Server::Config->port
Truth table0%0/3
A || B
A= $opt{'port'}B= $NNML::Server::Config->port
ABresult
1X1
011
000
33  
34 0 ▶ if (exists $opt{base}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt{"base"}) 0 0 0
35 0 $Config->base($opt{base});
36 }
37 0 NNML::Auth::_update; # just for the message
38 0 my $lsn = new NNML::Handle(Reuse => 1,
39 Listen => 5,
40 LocalPort => $port,
41 Proto => 'tcp');
42 0 ▶ die "Could not connect to port $port: $!\n" unless defined $lsn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lsn 0 0 0
43  
44 0 my $SEL = new IO::Select( $lsn );
45 0 my %CON;
46 my $fh;
47 0 my @ready;
48  
49 0 print STDERR "listening on port $port\n";
50
51 0 while(1) {
52 0 @ready = $SEL->can_read;
53 REQUEST:
54 0 foreach $fh (@ready) {
55 0 ▶ if($fh == $lsn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh == $lsn) { } 0 0 0
56 0 my $new = $lsn->accept; # Create a new socket
57 0 $CON{$new} = new NNML::Connection $new, $VERSION;
58 0 $SEL->add($new);
59 } else {
60 0 my ($cmd, $func, @args);
61 0 my $fno = fileno($fh);
62  
63 0 $cmd = $fh->getline();
64 0 ($func, @args) = split ' ', $cmd;
65 0 ▶ unless (fileno($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (fileno $fh) 0 0 0
66 # client has closed connection without sending 'quitt'
67 0 printf STDERR "Shuttig down $fh(%d)\n", $fno;
68 0 delete $CON{$fh};
69 0 $SEL->remove($fno);
70 0 next REQUEST;
71 }
72 0 $func = lc($func);
73 0 ▶ if ($func eq 'shut') { # shut down the server
Branch: 1 branch
BranchTrueFalseTotal
if ($func eq 'shut') { } 0 0 0
74 0 ▶ if (NNML::Auth::perm($CON{$fh}, $func)) {
Branch: 1 branch
BranchTrueFalseTotal
if (NNML::Auth::perm($CON{$fh}, $func)) { } 0 0 0
75 0 my $fx;
76 0 print STDERR "Going down\n";
77 0 for $fx (keys %CON) {
78 0 $CON{$fx}->msg(400);
79 0 $CON{$fx}->close;
80 0 delete $CON{$fx};
81 }
82 0 $SEL->remove($lsn);
83 0 $lsn->close();
84 0 return;
85 } else {
86 0 $CON{$fh}->msg(480);
87 0 next REQUEST;
88 }
89 } else {
90 0 $func = $CON{$fh}->dispatch($func, @args);
91 0 ▶ if ($func eq 'quit') {
Branch: 1 branch
BranchTrueFalseTotal
if ($func eq "quit") 0 0 0
92 0 print STDERR "closed\n";
93 0 $SEL->remove($fh);
94 0 $CON{$fh}->close;
95 0 delete $CON{$fh};
96 }
97 }
98 }
99 }
100 }
101 }
102  
103 1 1;
104  
105 __END__
« Active.pm ↑ Summary Connection.pm »