]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/perl/lib/Thrift/BufferedTransport.pm
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / perl / lib / Thrift / BufferedTransport.pm
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 use 5.10.0;
21 use strict;
22 use warnings;
23
24 use Thrift;
25 use Thrift::Exception;
26 use Thrift::Transport;
27
28 package Thrift::BufferedTransport;
29 use base('Thrift::Transport');
30 use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
31
32 sub new
33 {
34 my $classname = shift;
35 my $transport = shift;
36 my $rBufSize = shift || 512;
37 my $wBufSize = shift || 512;
38
39 my $self = {
40 transport => $transport,
41 rBufSize => $rBufSize,
42 wBufSize => $wBufSize,
43 wBuf => '',
44 rBuf => '',
45 };
46
47 return bless($self,$classname);
48 }
49
50 sub isOpen
51 {
52 my $self = shift;
53
54 return $self->{transport}->isOpen();
55 }
56
57 sub open
58 {
59 my $self = shift;
60 $self->{transport}->open();
61 }
62
63 sub close()
64 {
65 my $self = shift;
66 $self->{transport}->close();
67 }
68
69 sub readAll
70 {
71 my $self = shift;
72 my $len = shift;
73
74 return $self->{transport}->readAll($len);
75 }
76
77 sub read
78 {
79 my $self = shift;
80 my $len = shift;
81 my $ret;
82
83 # Methinks Perl is already buffering these for us
84 return $self->{transport}->read($len);
85 }
86
87 sub write
88 {
89 my $self = shift;
90 my $buf = shift;
91
92 $self->{wBuf} .= $buf;
93 if (length($self->{wBuf}) >= $self->{wBufSize}) {
94 $self->{transport}->write($self->{wBuf});
95 $self->{wBuf} = '';
96 }
97 }
98
99 sub flush
100 {
101 my $self = shift;
102
103 if (length($self->{wBuf}) > 0) {
104 $self->{transport}->write($self->{wBuf});
105 $self->{wBuf} = '';
106 }
107 $self->{transport}->flush();
108 }
109
110
111 #
112 # BufferedTransport factory creates buffered transport objects from transports
113 #
114 package Thrift::BufferedTransportFactory;
115 use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
116
117 sub new {
118 my $classname = shift;
119 my $self = {};
120
121 return bless($self,$classname);
122 }
123
124 #
125 # Build a buffered transport from the base transport
126 #
127 # @return Thrift::BufferedTransport transport
128 #
129 sub getTransport
130 {
131 my $self = shift;
132 my $trans = shift;
133
134 my $buffered = Thrift::BufferedTransport->new($trans);
135 return $buffered;
136 }
137
138
139 1;