Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 08:35:03

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements. See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership. The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License. You may obtain a copy of the License at
0009  *
0010  *   http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing,
0013  * software distributed under the License is distributed on an
0014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015  * KIND, either express or implied. See the License for the
0016  * specific language governing permissions and limitations
0017  * under the License.
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  * Dead-simple wrapper around a file descriptor.
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 } // apache::thrift::transport
0078 
0079 #endif // #ifndef _THRIFT_TRANSPORT_TFDTRANSPORT_H_