blob: 41b7e150fe839ce446c2db7882e9da7abb5dcbbd [file] [log] [blame]
Mark Slee254ce202007-05-16 02:21:06 +00001#
David Reissea2cba82009-03-30 21:35:00 +00002# 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
Mark Slee254ce202007-05-16 02:21:06 +00009#
David Reissea2cba82009-03-30 21:35:00 +000010# http://www.apache.org/licenses/LICENSE-2.0
Mark Slee254ce202007-05-16 02:21:06 +000011#
David Reissea2cba82009-03-30 21:35:00 +000012# 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.
Mark Slee254ce202007-05-16 02:21:06 +000018#
19
James E. King, III177c37c2017-03-30 17:09:04 -040020use 5.10.0;
Mark Slee254ce202007-05-16 02:21:06 +000021use strict;
22use warnings;
23
24use Thrift;
James E. King, III177c37c2017-03-30 17:09:04 -040025use Thrift::Exception;
Mark Slee254ce202007-05-16 02:21:06 +000026
27#
28# Transport exceptions
29#
James E. King, III177c37c2017-03-30 17:09:04 -040030package Thrift::TTransportException;
Mark Slee254ce202007-05-16 02:21:06 +000031use base('Thrift::TException');
James E. King, III177c37c2017-03-30 17:09:04 -040032use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
Mark Slee254ce202007-05-16 02:21:06 +000033
34use constant UNKNOWN => 0;
35use constant NOT_OPEN => 1;
36use constant ALREADY_OPEN => 2;
37use constant TIMED_OUT => 3;
38use constant END_OF_FILE => 4;
39
James E. King, III177c37c2017-03-30 17:09:04 -040040sub new {
Mark Slee254ce202007-05-16 02:21:06 +000041 my $classname = shift;
42 my $self = $classname->SUPER::new(@_);
43
44 return bless($self,$classname);
45}
46
47package Thrift::Transport;
James E. King, III177c37c2017-03-30 17:09:04 -040048use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
Mark Slee254ce202007-05-16 02:21:06 +000049
50#
51# Whether this transport is open.
52#
53# @return boolean true if open
54#
55sub isOpen
56{
Dean Hamstead8a130f62018-10-17 18:48:42 +110057 die 'abstract';
Mark Slee254ce202007-05-16 02:21:06 +000058}
59
60#
61# Open the transport for reading/writing
62#
63# @throws TTransportException if cannot open
64#
65sub open
66{
Dean Hamstead8a130f62018-10-17 18:48:42 +110067 die 'abstract';
Mark Slee254ce202007-05-16 02:21:06 +000068}
69
70#
71# Close the transport.
72#
73sub close
74{
Dean Hamstead8a130f62018-10-17 18:48:42 +110075 die 'abstract';
Mark Slee254ce202007-05-16 02:21:06 +000076}
77
78#
79# Read some data into the array.
80#
81# @param int $len How much to read
82# @return string The data that has been read
83# @throws TTransportException if cannot read any more data
84#
85sub read
86{
Dean Hamstead8a130f62018-10-17 18:48:42 +110087 die 'abstract';
Mark Slee254ce202007-05-16 02:21:06 +000088}
89
90#
91# Guarantees that the full amount of data is read.
92#
93# @return string The data, of exact length
94# @throws TTransportException if cannot read data
95#
96sub readAll
97{
98 my $self = shift;
99 my $len = shift;
100
101 my $data = '';
102 my $got = 0;
103
104 while (($got = length($data)) < $len) {
105 $data .= $self->read($len - $got);
106 }
107
108 return $data;
109}
110
111#
112# Writes the given data out.
113#
114# @param string $buf The data to write
115# @throws TTransportException if writing fails
116#
117sub write
118{
Dean Hamstead8a130f62018-10-17 18:48:42 +1100119 die 'abstract';
Mark Slee254ce202007-05-16 02:21:06 +0000120}
121
122#
123# Flushes any pending data out of a buffer
124#
125# @throws TTransportException if a writing error occurs
126#
127sub flush {}
128
T Jake Luciani0c5c2342009-11-12 03:01:33 +0000129
130#
131# TransportFactory creates transport objects from transports
132#
133package Thrift::TransportFactory;
James E. King, III177c37c2017-03-30 17:09:04 -0400134use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
T Jake Luciani0c5c2342009-11-12 03:01:33 +0000135
136sub new {
137 my $classname = shift;
138 my $self = {};
139
140 return bless($self,$classname);
141}
142
143#
144# Build a transport from the base transport
145#
146# @return Thrift::Transport transport
147#
148sub getTransport
149{
150 my $self = shift;
151 my $trans = shift;
152
153 return $trans;
154}
155
156
157#
158# ServerTransport base class module
159#
160package Thrift::ServerTransport;
James E. King, III177c37c2017-03-30 17:09:04 -0400161use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
T Jake Luciani0c5c2342009-11-12 03:01:33 +0000162
163sub listen
164{
Dean Hamstead8a130f62018-10-17 18:48:42 +1100165 die 'abstract';
T Jake Luciani0c5c2342009-11-12 03:01:33 +0000166}
167
168sub accept
169{
Dean Hamstead8a130f62018-10-17 18:48:42 +1100170 die 'abstract';
T Jake Luciani0c5c2342009-11-12 03:01:33 +0000171}
172
173sub close
174{
Dean Hamstead8a130f62018-10-17 18:48:42 +1100175 die 'abstract';
T Jake Luciani0c5c2342009-11-12 03:01:33 +0000176}
177
178
Mark Slee254ce202007-05-16 02:21:06 +00001791;
180