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_TFDTRANSPORT_H_
0021 #define _THRIFT_TRANSPORT_TFDTRANSPORT_H_ 1
0022
0023 #include <string>
0024 #ifdef HAVE_SYS_TIME_H
0025 #include <sys/time.h>
0026 #endif
0027
0028 #include <thrift/transport/TTransport.h>
0029 #include <thrift/transport/TVirtualTransport.h>
0030
0031 namespace apache {
0032 namespace thrift {
0033 namespace transport {
0034
0035
0036
0037
0038
0039 class TFDTransport : public TVirtualTransport<TFDTransport> {
0040 public:
0041 enum ClosePolicy { NO_CLOSE_ON_DESTROY = 0, CLOSE_ON_DESTROY = 1 };
0042
0043 TFDTransport(int fd, ClosePolicy close_policy = NO_CLOSE_ON_DESTROY,
0044 std::shared_ptr<TConfiguration> config = nullptr)
0045 : TVirtualTransport(config), fd_(fd), close_policy_(close_policy) {
0046 }
0047
0048 ~TFDTransport() override {
0049 if (close_policy_ == CLOSE_ON_DESTROY) {
0050 try {
0051 close();
0052 } catch (TTransportException& ex) {
0053 GlobalOutput.printf("~TFDTransport TTransportException: '%s'", ex.what());
0054 }
0055 }
0056 }
0057
0058 bool isOpen() const override { return fd_ >= 0; }
0059
0060 void open() override {}
0061
0062 void close() override;
0063
0064 uint32_t read(uint8_t* buf, uint32_t len);
0065
0066 void write(const uint8_t* buf, uint32_t len);
0067
0068 void setFD(int fd) { fd_ = fd; }
0069 int getFD() { return fd_; }
0070
0071 protected:
0072 int fd_;
0073 ClosePolicy close_policy_;
0074 };
0075 }
0076 }
0077 }
0078
0079 #endif