| 1 | # | ||||||||||||||||||||||||||||
| 2 | # Licensed to the Apache Software Foundation (ASF) under one | ||||||||||||||||||||||||||||
| 3 | # or more contributor license agreements. See the NOTICE file | ||||||||||||||||||||||||||||
| 4 | # distributed with this work for additional information | ||||||||||||||||||||||||||||
| 5 | # regarding copyright ownership. The ASF licenses this file | ||||||||||||||||||||||||||||
| 6 | # to you under the Apache License, Version 2.0 (the | ||||||||||||||||||||||||||||
| 7 | # "License"); you may not use this file except in compliance | ||||||||||||||||||||||||||||
| 8 | # with the License. You may obtain a copy of the License at | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | # Unless required by applicable law or agreed to in writing, | ||||||||||||||||||||||||||||
| 13 | # software distributed under the License is distributed on an | ||||||||||||||||||||||||||||
| 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||||||||||||||||||||||
| 15 | # KIND, either express or implied. See the License for the | ||||||||||||||||||||||||||||
| 16 | # specific language governing permissions and limitations | ||||||||||||||||||||||||||||
| 17 | # under the License. | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use 5.10.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Thrift; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Thrift::Transport; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||
| 28 | # Framed transport. Writes and reads data in chunks that are stamped with | ||||||||||||||||||||||||||||
| 29 | # their length. | ||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||
| 31 | # @package thrift.transport | ||||||||||||||||||||||||||||
| 32 | # | ||||||||||||||||||||||||||||
| 33 | package Thrift::FramedTransport; | ||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use base('Thrift::Transport'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub new | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 0 | my $classname = shift; | |||||||||||||||||||||||||||
| 40 | 0 | my $transport = shift; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $read = shift || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $write = shift || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | my $self = { | |||||||||||||||||||||||||||
| 45 | transport => $transport, | ||||||||||||||||||||||||||||
| 46 | read => $read, | ||||||||||||||||||||||||||||
| 47 | write => $write, | ||||||||||||||||||||||||||||
| 48 | wBuf => '', | ||||||||||||||||||||||||||||
| 49 | rBuf => '', | ||||||||||||||||||||||||||||
| 50 | }; | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | return bless($self,$classname); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub isOpen | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
isOpen: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | 0 | return $self->{transport}->isOpen(); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub open | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
open: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | $self->{transport}->open(); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub close | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (defined $self->{transport}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $self->{transport}->close(); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # | ||||||||||||||||||||||||||||
| 78 | # Reads from the buffer. When more data is required reads another entire | ||||||||||||||||||||||||||||
| 79 | # chunk and serves future reads out of that. | ||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||
| 81 | # @param int $len How much data | ||||||||||||||||||||||||||||
| 82 | # | ||||||||||||||||||||||||||||
| 83 | sub read | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 87 | 0 | my $len = shift; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (!$self->{read}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | return $self->{transport}->read($len); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if (length($self->{rBuf}) == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | $self->_readFrame(); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # Just return full buff | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($len > length($self->{rBuf})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | my $out = $self->{rBuf}; | |||||||||||||||||||||||||||
| 101 | 0 | $self->{rBuf} = ''; | |||||||||||||||||||||||||||
| 102 | 0 | return $out; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # Return substr | ||||||||||||||||||||||||||||
| 106 | 0 | my $out = substr($self->{rBuf}, 0, $len); | |||||||||||||||||||||||||||
| 107 | 0 | $self->{rBuf} = substr($self->{rBuf}, $len); | |||||||||||||||||||||||||||
| 108 | 0 | return $out; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # | ||||||||||||||||||||||||||||
| 112 | # Reads a chunk of data into the internal read buffer. | ||||||||||||||||||||||||||||
| 113 | # (private) | ||||||||||||||||||||||||||||
| 114 | sub _readFrame | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_readFrame: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 116 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 117 | 0 | my $buf = $self->{transport}->readAll(4); | |||||||||||||||||||||||||||
| 118 | 0 | my @val = unpack('N', $buf); | |||||||||||||||||||||||||||
| 119 | 0 | my $sz = $val[0]; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | $self->{rBuf} = $self->{transport}->readAll($sz); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | # | ||||||||||||||||||||||||||||
| 125 | # Writes some data to the pending output buffer. | ||||||||||||||||||||||||||||
| 126 | # | ||||||||||||||||||||||||||||
| 127 | # @param string $buf The data | ||||||||||||||||||||||||||||
| 128 | # @param int $len Limit of bytes to write | ||||||||||||||||||||||||||||
| 129 | # | ||||||||||||||||||||||||||||
| 130 | sub write | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 133 | 0 | my $buf = shift; | |||||||||||||||||||||||||||
| 134 | 0 | my $len = shift; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | unless($self->{write}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | return $self->{transport}->write($buf, $len); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ( defined $len && $len < length($buf)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $len and $len < length $buf
MC/DC0%0/2
defined $len and $len < length $buf
defined $len
$len < length $buf
Truth table0%0/3
A and B
A= defined $lenB= $len < length $buf
| |||||||||||||||||||||||||||||
| 141 | 0 | $buf = substr($buf, 0, $len); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | $self->{wBuf} .= $buf; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # | ||||||||||||||||||||||||||||
| 148 | # Writes the output buffer to the stream in the format of a 4-byte length | ||||||||||||||||||||||||||||
| 149 | # followed by the actual data. | ||||||||||||||||||||||||||||
| 150 | # | ||||||||||||||||||||||||||||
| 151 | sub flush | ||||||||||||||||||||||||||||
| 152 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | unless ($self->{write}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | return $self->{transport}->flush(); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | my $out = pack('N', length($self->{wBuf})); | |||||||||||||||||||||||||||
| 160 | 0 | $out .= $self->{wBuf}; | |||||||||||||||||||||||||||
| 161 | 0 | $self->{transport}->write($out); | |||||||||||||||||||||||||||
| 162 | 0 | $self->{transport}->flush(); | |||||||||||||||||||||||||||
| 163 | 0 | $self->{wBuf} = ''; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | # | ||||||||||||||||||||||||||||
| 168 | # FramedTransport factory creates framed transport objects from transports | ||||||||||||||||||||||||||||
| 169 | # | ||||||||||||||||||||||||||||
| 170 | package Thrift::FramedTransportFactory; | ||||||||||||||||||||||||||||
| 171 | 1 | ▶ | use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 174 | 0 | my $classname = shift; | |||||||||||||||||||||||||||
| 175 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | return bless($self, $classname); | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # | ||||||||||||||||||||||||||||
| 181 | # Build a framed transport from the base transport | ||||||||||||||||||||||||||||
| 182 | # | ||||||||||||||||||||||||||||
| 183 | # @return Thrift::FramedTransport transport | ||||||||||||||||||||||||||||
| 184 | # | ||||||||||||||||||||||||||||
| 185 | sub getTransport | ||||||||||||||||||||||||||||
| 186 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getTransport: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 187 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 188 | 0 | my $trans = shift; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | my $buffered = Thrift::FramedTransport->new($trans); | |||||||||||||||||||||||||||
| 191 | 0 | return $buffered; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 1 | 1; | |||||||||||||||||||||||||||