PageRenderTime 72ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/service/lib/php/transport/TTransport.php

#
PHP | 108 lines | 28 code | 14 blank | 66 comment | 1 complexity | bdb226b4fdbc45445bb6937c33e42f7c MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. <?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. * Transport exceptions
  24. */
  25. class TTransportException extends TException {
  26. const UNKNOWN = 0;
  27. const NOT_OPEN = 1;
  28. const ALREADY_OPEN = 2;
  29. const TIMED_OUT = 3;
  30. const END_OF_FILE = 4;
  31. function __construct($message=null, $code=0) {
  32. parent::__construct($message, $code);
  33. }
  34. }
  35. /**
  36. * Base interface for a transport agent.
  37. *
  38. * @package thrift.transport
  39. */
  40. abstract class TTransport {
  41. /**
  42. * Whether this transport is open.
  43. *
  44. * @return boolean true if open
  45. */
  46. public abstract function isOpen();
  47. /**
  48. * Open the transport for reading/writing
  49. *
  50. * @throws TTransportException if cannot open
  51. */
  52. public abstract function open();
  53. /**
  54. * Close the transport.
  55. */
  56. public abstract function close();
  57. /**
  58. * Read some data into the array.
  59. *
  60. * @param int $len How much to read
  61. * @return string The data that has been read
  62. * @throws TTransportException if cannot read any more data
  63. */
  64. public abstract function read($len);
  65. /**
  66. * Guarantees that the full amount of data is read.
  67. *
  68. * @return string The data, of exact length
  69. * @throws TTransportException if cannot read data
  70. */
  71. public function readAll($len) {
  72. // return $this->read($len);
  73. $data = '';
  74. $got = 0;
  75. while (($got = strlen($data)) < $len) {
  76. $data .= $this->read($len - $got);
  77. }
  78. return $data;
  79. }
  80. /**
  81. * Writes the given data out.
  82. *
  83. * @param string $buf The data to write
  84. * @throws TTransportException if writing fails
  85. */
  86. public abstract function write($buf);
  87. /**
  88. * Flushes any pending data out of a buffer
  89. *
  90. * @throws TTransportException if a writing error occurs
  91. */
  92. public function flush() {}
  93. }
  94. ?>