]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/dart/lib/src/transport/t_transport.dart
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / dart / lib / src / transport / t_transport.dart
CommitLineData
f67539c2
TL
1/// Licensed to the Apache Software Foundation (ASF) under one
2/// or more contributor license agreements. See the NOTICE file
3/// distributed with this work for additional information
4/// regarding copyright ownership. The ASF licenses this file
5/// to you under the Apache License, Version 2.0 (the
6/// "License"); you may not use this file except in compliance
7/// with the License. You may obtain a copy of the License at
8///
9/// http://www.apache.org/licenses/LICENSE-2.0
10///
11/// Unless required by applicable law or agreed to in writing,
12/// software distributed under the License is distributed on an
13/// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14/// KIND, either express or implied. See the License for the
15/// specific language governing permissions and limitations
16/// under the License.
17
18part of thrift;
19
20abstract class TTransport {
21 /// Queries whether the transport is open.
22 /// Returns [true] if the transport is open.
23 bool get isOpen;
24
25 /// Opens the transport for reading/writing.
26 /// Throws [TTransportError] if the transport could not be opened.
27 Future open();
28
29 /// Closes the transport.
30 Future close();
31
32 /// Reads up to [length] bytes into [buffer], starting at [offset].
33 /// Returns the number of bytes actually read.
34 /// Throws [TTransportError] if there was an error reading data
35 int read(Uint8List buffer, int offset, int length);
36
37 /// Guarantees that all of [length] bytes are actually read off the transport.
38 /// Returns the number of bytes actually read, which must be equal to
39 /// [length].
40 /// Throws [TTransportError] if there was an error reading data
41 int readAll(Uint8List buffer, int offset, int length) {
42 int got = 0;
43 int ret = 0;
44 while (got < length) {
45 ret = read(buffer, offset + got, length - got);
46 if (ret <= 0) {
47 throw new TTransportError(
48 TTransportErrorType.UNKNOWN,
49 "Cannot read. Remote side has closed. Tried to read $length "
50 "bytes, but only got $got bytes.");
51 }
52 got += ret;
53 }
54 return got;
55 }
56
57 /// Writes up to [len] bytes from the buffer.
58 /// Throws [TTransportError] if there was an error writing data
59 void write(Uint8List buffer, int offset, int length);
60
61 /// Writes the [bytes] to the output.
62 /// Throws [TTransportError] if there was an error writing data
63 void writeAll(Uint8List buffer) {
64 write(buffer, 0, buffer.length);
65 }
66
67 /// Flush any pending data out of a transport buffer.
68 /// Throws [TTransportError] if there was an error writing out data.
69 Future flush();
70}