Back to home page

EIC code displayed by LXR

 
 

    


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

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_TEVHTTP_CLIENT_CHANNEL_H_
0021 #define _THRIFT_TEVHTTP_CLIENT_CHANNEL_H_ 1
0022 
0023 #include <queue>
0024 #include <string>
0025 #include <utility>
0026 #include <memory>
0027 #include <thrift/async/TAsyncChannel.h>
0028 
0029 struct event_base;
0030 struct evdns_base;
0031 struct evhttp_connection;
0032 struct evhttp_request;
0033 
0034 namespace apache {
0035 namespace thrift {
0036 namespace transport {
0037 class TMemoryBuffer;
0038 }
0039 }
0040 }
0041 
0042 namespace apache {
0043 namespace thrift {
0044 namespace async {
0045 
0046 class TEvhttpClientChannel : public TAsyncChannel {
0047 public:
0048   using TAsyncChannel::VoidCallback;
0049 
0050   TEvhttpClientChannel(const std::string& host,
0051                        const std::string& path,
0052                        const char* address,
0053                        int port,
0054                        struct event_base* eb,
0055                        struct evdns_base *dnsbase = nullptr);
0056   ~TEvhttpClientChannel() override;
0057 
0058   void sendAndRecvMessage(const VoidCallback& cob,
0059                                   apache::thrift::transport::TMemoryBuffer* sendBuf,
0060                                   apache::thrift::transport::TMemoryBuffer* recvBuf) override;
0061 
0062   void sendMessage(const VoidCallback& cob,
0063                            apache::thrift::transport::TMemoryBuffer* message) override;
0064   void recvMessage(const VoidCallback& cob,
0065                            apache::thrift::transport::TMemoryBuffer* message) override;
0066 
0067   void finish(struct evhttp_request* req);
0068 
0069   // XXX
0070   bool good() const override { return true; }
0071   bool error() const override { return false; }
0072   bool timedOut() const override { return false; }
0073 
0074 private:
0075   static void response(struct evhttp_request* req, void* arg);
0076 
0077   std::string host_;
0078   std::string path_;
0079   typedef std::pair<VoidCallback, apache::thrift::transport::TMemoryBuffer*> Completion;
0080   typedef std::queue<Completion> CompletionQueue;
0081   CompletionQueue completionQueue_;
0082   struct evhttp_connection* conn_;
0083 };
0084 }
0085 }
0086 } // apache::thrift::async
0087 
0088 #endif // #ifndef _THRIFT_TEVHTTP_CLIENT_CHANNEL_H_