| 1 | package Ekahau::Server; | ||||||||||||||||||||||||||||||||
| 2 | 15 | ▶ | use base 'Ekahau::Base'; our $VERSION = $Ekahau::Base::VERSION; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use base 'Ekahau::ErrHandler'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | # Written by Scott Gifford <gifford@umich.edu> | ||||||||||||||||||||||||||||||||
| 6 | # Copyright (C) 2004 The Regents of the University of Michigan. | ||||||||||||||||||||||||||||||||
| 7 | # See the file LICENSE included with the distribution for license | ||||||||||||||||||||||||||||||||
| 8 | # information. | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use bytes; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | Ekahau::Server - Simple class for creating an Ekahau-style server, for testing | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | This class is used to create a server that behaves like the Ekahau | ||||||||||||||||||||||||||||||||
| 21 | Positioning Engine. It is only used for testing the Ekahau client, | ||||||||||||||||||||||||||||||||
| 22 | via the L<Ekahau::Server::Test|Ekahau::Server::Test> class. | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | Because this class is used only for testing, it is not documented. | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 15 | ▶ | use constant READ_BLOCKSIZE => 8192; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 29 | 15 | ▶ | use constant DEFAULT_TIMEOUT => 10; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 15 | ▶ | use IO::Select; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | sub new | ||||||||||||||||||||||||||||||||
| 34 | 28 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 35 | 28 | my $class = shift; | |||||||||||||||||||||||||||||||
| 36 | 28 | my(%p) = @_; | |||||||||||||||||||||||||||||||
| 37 | 28 | my $private_error; | |||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 28 | my $self = {}; | |||||||||||||||||||||||||||||||
| 40 | 28 | bless $self, $class; | |||||||||||||||||||||||||||||||
| 41 | 28 | $self->{_errhandler} = Ekahau::ErrHandler->errhandler_new($class,%p); | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 28 | $self->{tag} = 0; | |||||||||||||||||||||||||||||||
| 44 | 28 | $self->{_readbuf} = ""; | |||||||||||||||||||||||||||||||
| 45 | 28 | ▶ | $self->{_timeout}=$p{Timeout}||$p{timeout}||DEFAULT_TIMEOUT; | ||||||||||||||||||||||||||||||
|
Condition40%2/5
$p{'Timeout'} || $p{'timeout'} || 10
$p{"Timeout"} or $p{"timeout"}
MC/DC0%0/2
$p{'Timeout'} || $p{'timeout'} || 10
$p{"Timeout"}
$p{"timeout"}
Truth table33%1/3
A or B
A= $p{"Timeout"}B= $p{"timeout"}
| |||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | $self->{_sock} = $p{Socket} | ||||||||||||||||||||||||||||||||
| 48 | 28 | ▶ | or return $self->reterr("No Socket supplied to Ekahau::Server constructor.\n"); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 28 | binmode $self->{_sock}; | |||||||||||||||||||||||||||||||
| 50 | 28 | $self->{_sock}->autoflush(1); | |||||||||||||||||||||||||||||||
| 51 | $self->{_socksel} = IO::Select->new($self->{_sock}) | ||||||||||||||||||||||||||||||||
| 52 | 28 | ▶ | or return $self->reterr("Couldn't create IO::Select object: $!\n"); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 28 | $self->errhandler_constructed(); | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | sub ERROBJ | ||||||||||||||||||||||||||||||||
| 58 | 183 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
ERROBJ: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 59 | 183 | my $self = shift; | |||||||||||||||||||||||||||||||
| 60 | 183 | $self->{_errhandler}; | |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | sub nextresponse | ||||||||||||||||||||||||||||||||
| 64 | 90 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
nextresponse: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 65 | 90 | my $self = shift; | |||||||||||||||||||||||||||||||
| 66 | 90 | my($sock)=@_; | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 90 | ▶ | my $resp = $self->SUPER::nextresponse | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | or return undef; | ||||||||||||||||||||||||||||||||
| 70 | 73 | $resp; | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | sub reply | ||||||||||||||||||||||||||||||||
| 74 | 58 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
reply: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 75 | 58 | my $self = shift; | |||||||||||||||||||||||||||||||
| 76 | 58 | my $resp = shift; | |||||||||||||||||||||||||||||||
| 77 | 58 | $self->command(@_,$resp->{tag}); | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | sub DESTROY | ||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 82 | ; | ||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | package Ekahau::Server::Listener; | ||||||||||||||||||||||||||||||||
| 86 | 15 | ▶ | use base 'Ekahau::ErrHandler'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 15 | ▶ | use constant DEFAULT_PORT => 8548; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 89 | 15 | ▶ | use constant DEFAULT_HOST => 0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | sub new | ||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 93 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 94 | 0 | my(%p) = @_; | |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 0 | my $self = {}; | |||||||||||||||||||||||||||||||
| 97 | 0 | bless $self,$class; | |||||||||||||||||||||||||||||||
| 98 | 0 | $self->{_errhandler} = Ekahau::ErrHandler->errhandler_new($class,%p); | |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $self->{_timeout}=$p{Timeout}||$p{timeout}||Ekahau::Server::DEFAULT_TIMEOUT; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
$p{'Timeout'} || $p{'timeout'} || 10
$p{"Timeout"} or $p{"timeout"}
MC/DC0%0/2
$p{'Timeout'} || $p{'timeout'} || 10
$p{"Timeout"}
$p{"timeout"}
Truth table0%0/3
A or B
A= $p{"Timeout"}B= $p{"timeout"}
| |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $self->_opensock(%p) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 103 | or return undef; | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 0 | $self->errhandler_constructed(); | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | sub ERROBJ | ||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
ERROBJ: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 110 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 111 | 0 | $self->{_errhandler}; | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | # Connect to the TCP socket | ||||||||||||||||||||||||||||||||
| 115 | sub _opensock | ||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_opensock: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||
| 117 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 118 | 0 | my(%p)=@_; | |||||||||||||||||||||||||||||||
| 119 | 0 | my $sock; | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ($p{Socket}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||||||
| 123 | 0 | $sock = $p{Socket}; | |||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | else | ||||||||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||||||
| 127 | # For IO::Socket::INET | ||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ($p{timeout} && !$p{Timeout}) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$p{"timeout"} and not $p{"Timeout"}
MC/DC0%0/2
$p{"timeout"} and not $p{"Timeout"}
$p{"timeout"}
not $p{"Timeout"}
Truth table0%0/3
A and not(B)
A= $p{"timeout"}B= not $p{"Timeout"}
| |||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||
| 130 | 0 | $p{Timeout}=$p{timeout}; | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | elsif ($self->{_timeout}) | ||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||
| 134 | 0 | $p{Timeout} = $self->{_timeout}; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if (!$p{LocalPort}) { $p{LocalPort} = DEFAULT_PORT }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if (!$p{LocalAddr} and !$p{LocalHost}) { $p{LocalAddr} = DEFAULT_HOST }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p{"LocalAddr"} or $p{"LocalHost"}
MC/DC0%0/2
$p{"LocalAddr"} or $p{"LocalHost"}
$p{"LocalAddr"}
$p{"LocalHost"}
Truth table0%0/3
A or B
A= $p{"LocalAddr"}B= $p{"LocalHost"}
| |||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | warn "DEBUG Created listener for $p{LocalAddr}:$p{LocalPort}...\n" | ||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ($ENV{VERBOSE}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | $sock = IO::Socket::INET->new(%p, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | Listen => 5, | ||||||||||||||||||||||||||||||||
| 144 | ReuseAddr => 1, | ||||||||||||||||||||||||||||||||
| 145 | Proto => 'tcp') | ||||||||||||||||||||||||||||||||
| 146 | or return $self->reterr("Couldn't create IO::Socket::INET - $!"); | ||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 0 | $self->{_listen} = $sock; | |||||||||||||||||||||||||||||||
| 150 | 0 | binmode $self->{_listen}; | |||||||||||||||||||||||||||||||
| 151 | 0 | $self->{_listen}->autoflush(1); | |||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | warn "DEBUG connected.\n" | ||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if ($ENV{VERBOSE}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | sub accept | ||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
accept: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 159 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $class = shift || 'Ekahau::Server'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'Ekahau::Server'
MC/DC0%0/1
shift() || 'Ekahau::Server'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 161 | my $newconn = $self->{_listen}->accept | ||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | or return undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 163 | return $class->new(Socket => $newconn, | ||||||||||||||||||||||||||||||||
| 164 | 0 | Timeout => $self->{_timeout}); | |||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | Scott Gifford E<lt>gifford@umich.eduE<gt>, E<lt>sgifford@suspectclass.comE<gt> | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | Copyright (C) 2005 The Regents of the University of Michigan. | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | See the file LICENSE included with the distribution for license | ||||||||||||||||||||||||||||||||
| 174 | information. | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | =cut | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | 15 | 1; | |||||||||||||||||||||||||||||||