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_SERVER_H_
0021 #define _THRIFT_TEVHTTP_SERVER_H_ 1
0022 
0023 #include <memory>
0024 
0025 struct event_base;
0026 struct evhttp;
0027 struct evhttp_request;
0028 
0029 namespace apache {
0030 namespace thrift {
0031 namespace async {
0032 
0033 class TAsyncBufferProcessor;
0034 
0035 class TEvhttpServer {
0036 public:
0037   /**
0038    * Create a TEvhttpServer for use with an external evhttp instance.
0039    * Must be manually installed with evhttp_set_cb, using
0040    * TEvhttpServer::request as the callback and the
0041    * address of the server as the extra arg.
0042    * Do not call "serve" on this server.
0043    */
0044   TEvhttpServer(std::shared_ptr<TAsyncBufferProcessor> processor);
0045 
0046   /**
0047    * Create a TEvhttpServer with an embedded event_base and evhttp,
0048    * listening on port and responding on the endpoint "/".
0049    * Call "serve" on this server to serve forever.
0050    */
0051   TEvhttpServer(std::shared_ptr<TAsyncBufferProcessor> processor, int port);
0052 
0053   virtual ~TEvhttpServer();
0054 
0055   static void request(struct evhttp_request* req, void* self);
0056   int serve();
0057 
0058   struct event_base* getEventBase();
0059 
0060 private:
0061   struct RequestContext;
0062 
0063   void process(struct evhttp_request* req);
0064   void complete(RequestContext* ctx, bool success);
0065 
0066   std::shared_ptr<TAsyncBufferProcessor> processor_;
0067   struct event_base* eb_;
0068   struct evhttp* eh_;
0069 };
0070 }
0071 }
0072 } // apache::thrift::async
0073 
0074 #endif // #ifndef _THRIFT_TEVHTTP_SERVER_H_