]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/perl/lib/Thrift/FramedTransport.pm
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
25 use Thrift
::Transport
;
28 # Framed transport. Writes and reads data in chunks that are stamped with
31 # @package thrift.transport
33 package Thrift
::FramedTransport
;
34 use base
('Thrift::Transport');
35 use version
0.77; our $VERSION = version-
>declare("$Thrift::VERSION");
39 my $classname = shift;
40 my $transport = shift;
41 my $read = shift || 1;
42 my $write = shift || 1;
45 transport
=> $transport,
52 return bless($self,$classname);
58 return $self->{transport
}->isOpen();
65 $self->{transport
}->open();
72 if (defined $self->{transport
}) {
73 $self->{transport
}->close();
78 # Reads from the buffer. When more data is required reads another entire
79 # chunk and serves future reads out of that.
81 # @param int $len How much data
90 return $self->{transport
}->read($len);
93 if (length($self->{rBuf
}) == 0) {
98 # Just return full buff
99 if ($len > length($self->{rBuf
})) {
100 my $out = $self->{rBuf
};
106 my $out = substr($self->{rBuf
}, 0, $len);
107 $self->{rBuf
} = substr($self->{rBuf
}, $len);
112 # Reads a chunk of data into the internal read buffer.
117 my $buf = $self->{transport
}->readAll(4);
118 my @val = unpack('N', $buf);
121 $self->{rBuf
} = $self->{transport
}->readAll($sz);
125 # Writes some data to the pending output buffer.
127 # @param string $buf The data
128 # @param int $len Limit of bytes to write
136 unless($self->{write}) {
137 return $self->{transport
}->write($buf, $len);
140 if ( defined $len && $len < length($buf)) {
141 $buf = substr($buf, 0, $len);
144 $self->{wBuf
} .= $buf;
148 # Writes the output buffer to the stream in the format of a 4-byte length
149 # followed by the actual data.
155 unless ($self->{write}) {
156 return $self->{transport
}->flush();
159 my $out = pack('N', length($self->{wBuf
}));
160 $out .= $self->{wBuf
};
161 $self->{transport
}->write($out);
162 $self->{transport
}->flush();
168 # FramedTransport factory creates framed transport objects from transports
170 package Thrift
::FramedTransportFactory
;
171 use version
0.77; our $VERSION = version-
>declare("$Thrift::VERSION");
174 my $classname = shift;
177 return bless($self, $classname);
181 # Build a framed transport from the base transport
183 # @return Thrift::FramedTransport transport
190 my $buffered = Thrift
::FramedTransport-
>new($trans);