File indexing completed on 2026-04-17 08:35:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef _THRIFT_TRANSPORT_TSHORTREADTRANSPORT_H_
0021 #define _THRIFT_TRANSPORT_TSHORTREADTRANSPORT_H_ 1
0022
0023 #include <cstdlib>
0024
0025 #include <thrift/transport/TTransport.h>
0026 #include <thrift/transport/TVirtualTransport.h>
0027
0028 namespace apache {
0029 namespace thrift {
0030 namespace transport {
0031 namespace test {
0032
0033
0034
0035
0036
0037
0038
0039 class TShortReadTransport : public TVirtualTransport<TShortReadTransport> {
0040 public:
0041 TShortReadTransport(std::shared_ptr<TTransport> transport, double full_prob,
0042 std::shared_ptr<TConfiguration> config = nullptr)
0043 : TVirtualTransport(config), transport_(transport), fullProb_(full_prob) {
0044 }
0045
0046 bool isOpen() const override { return transport_->isOpen(); }
0047
0048 bool peek() override { return transport_->peek(); }
0049
0050 void open() override { transport_->open(); }
0051
0052 void close() override { transport_->close(); }
0053
0054 uint32_t read(uint8_t* buf, uint32_t len) {
0055 checkReadBytesAvailable(len);
0056 if (len == 0) {
0057 return 0;
0058 }
0059
0060 if (rand() / (double)RAND_MAX >= fullProb_) {
0061 len = 1 + rand() % len;
0062 }
0063 return transport_->read(buf, len);
0064 }
0065
0066 void write(const uint8_t* buf, uint32_t len) { transport_->write(buf, len); }
0067
0068 void flush() override {
0069 resetConsumedMessageSize();
0070 transport_->flush();
0071 }
0072
0073 const uint8_t* borrow(uint8_t* buf, uint32_t* len) { return transport_->borrow(buf, len); }
0074
0075 void consume(uint32_t len) {
0076 countConsumedMessageBytes(len);
0077 return transport_->consume(len);
0078 }
0079
0080 std::shared_ptr<TTransport> getUnderlyingTransport() { return transport_; }
0081
0082 protected:
0083 std::shared_ptr<TTransport> transport_;
0084 double fullProb_;
0085 };
0086 }
0087 }
0088 }
0089 }
0090
0091 #endif