1 |
15801
|
thanos.pap
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
4 |
|
|
* or more contributor license agreements. See the NOTICE file
|
5 |
|
|
* distributed with this work for additional information
|
6 |
|
|
* regarding copyright ownership. The ASF licenses this file
|
7 |
|
|
* to you under the Apache License, Version 2.0 (the
|
8 |
|
|
* "License"); you may not use this file except in compliance
|
9 |
|
|
* with the License. You may obtain a copy of the License at
|
10 |
|
|
*
|
11 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
12 |
|
|
*
|
13 |
|
|
* Unless required by applicable law or agreed to in writing,
|
14 |
|
|
* software distributed under the License is distributed on an
|
15 |
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16 |
|
|
* KIND, either express or implied. See the License for the
|
17 |
|
|
* specific language governing permissions and limitations
|
18 |
|
|
* under the License.
|
19 |
|
|
*
|
20 |
|
|
* @package thrift.transport
|
21 |
|
|
*/
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Transport exceptions
|
26 |
|
|
*/
|
27 |
|
|
class TTransportException extends TException {
|
28 |
|
|
|
29 |
|
|
const UNKNOWN = 0;
|
30 |
|
|
const NOT_OPEN = 1;
|
31 |
|
|
const ALREADY_OPEN = 2;
|
32 |
|
|
const TIMED_OUT = 3;
|
33 |
|
|
const END_OF_FILE = 4;
|
34 |
|
|
|
35 |
|
|
function __construct($message=null, $code=0) {
|
36 |
|
|
parent::__construct($message, $code);
|
37 |
|
|
}
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* Base interface for a transport agent.
|
42 |
|
|
*
|
43 |
|
|
* @package thrift.transport
|
44 |
|
|
*/
|
45 |
|
|
abstract class TTransport {
|
46 |
|
|
|
47 |
|
|
/**
|
48 |
|
|
* Whether this transport is open.
|
49 |
|
|
*
|
50 |
|
|
* @return boolean true if open
|
51 |
|
|
*/
|
52 |
|
|
public abstract function isOpen();
|
53 |
|
|
|
54 |
|
|
/**
|
55 |
|
|
* Open the transport for reading/writing
|
56 |
|
|
*
|
57 |
|
|
* @throws TTransportException if cannot open
|
58 |
|
|
*/
|
59 |
|
|
public abstract function open();
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Close the transport.
|
63 |
|
|
*/
|
64 |
|
|
public abstract function close();
|
65 |
|
|
|
66 |
|
|
/**
|
67 |
|
|
* Read some data into the array.
|
68 |
|
|
*
|
69 |
|
|
* @param int $len How much to read
|
70 |
|
|
* @return string The data that has been read
|
71 |
|
|
* @throws TTransportException if cannot read any more data
|
72 |
|
|
*/
|
73 |
|
|
public abstract function read($len);
|
74 |
|
|
|
75 |
|
|
/**
|
76 |
|
|
* Guarantees that the full amount of data is read.
|
77 |
|
|
*
|
78 |
|
|
* @return string The data, of exact length
|
79 |
|
|
* @throws TTransportException if cannot read data
|
80 |
|
|
*/
|
81 |
|
|
public function readAll($len) {
|
82 |
|
|
// return $this->read($len);
|
83 |
|
|
|
84 |
|
|
$data = '';
|
85 |
|
|
$got = 0;
|
86 |
|
|
while (($got = strlen($data)) < $len) {
|
87 |
|
|
$data .= $this->read($len - $got);
|
88 |
|
|
}
|
89 |
|
|
return $data;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
/**
|
93 |
|
|
* Writes the given data out.
|
94 |
|
|
*
|
95 |
|
|
* @param string $buf The data to write
|
96 |
|
|
* @throws TTransportException if writing fails
|
97 |
|
|
*/
|
98 |
|
|
public abstract function write($buf);
|
99 |
|
|
|
100 |
|
|
/**
|
101 |
|
|
* Flushes any pending data out of a buffer
|
102 |
|
|
*
|
103 |
|
|
* @throws TTransportException if a writing error occurs
|
104 |
|
|
*/
|
105 |
|
|
public function flush() {}
|
106 |
|
|
}
|