blob: afc679ccfc668b30434abf83a98334b10ab5360c [file] [log] [blame]
David Reiss5ddabb82010-10-06 17:09:37 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef _THRIFT_TEVHTTP_SERVER_H_
21#define _THRIFT_TEVHTTP_SERVER_H_ 1
22
James E. King, III82ae9572017-08-05 12:23:54 -040023#include <thrift/stdcxx.h>
David Reiss5ddabb82010-10-06 17:09:37 +000024
25struct event_base;
26struct evhttp;
27struct evhttp_request;
28
Konrad Grochowski16a23a62014-11-13 15:33:38 +010029namespace apache {
30namespace thrift {
31namespace async {
David Reiss5ddabb82010-10-06 17:09:37 +000032
33class TAsyncBufferProcessor;
34
35class TEvhttpServer {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010036public:
David Reiss5ddabb82010-10-06 17:09:37 +000037 /**
38 * Create a TEvhttpServer for use with an external evhttp instance.
39 * Must be manually installed with evhttp_set_cb, using
40 * TEvhttpServer::request as the callback and the
41 * address of the server as the extra arg.
42 * Do not call "serve" on this server.
43 */
James E. King, III82ae9572017-08-05 12:23:54 -040044 TEvhttpServer(stdcxx::shared_ptr<TAsyncBufferProcessor> processor);
David Reiss5ddabb82010-10-06 17:09:37 +000045
46 /**
47 * Create a TEvhttpServer with an embedded event_base and evhttp,
48 * listening on port and responding on the endpoint "/".
49 * Call "serve" on this server to serve forever.
50 */
James E. King, III82ae9572017-08-05 12:23:54 -040051 TEvhttpServer(stdcxx::shared_ptr<TAsyncBufferProcessor> processor, int port);
David Reiss5ddabb82010-10-06 17:09:37 +000052
53 ~TEvhttpServer();
54
55 static void request(struct evhttp_request* req, void* self);
56 int serve();
57
58 struct event_base* getEventBase();
59
Konrad Grochowski16a23a62014-11-13 15:33:38 +010060private:
David Reiss5ddabb82010-10-06 17:09:37 +000061 struct RequestContext;
62
63 void process(struct evhttp_request* req);
64 void complete(RequestContext* ctx, bool success);
65
James E. King, III82ae9572017-08-05 12:23:54 -040066 stdcxx::shared_ptr<TAsyncBufferProcessor> processor_;
David Reiss5ddabb82010-10-06 17:09:37 +000067 struct event_base* eb_;
68 struct evhttp* eh_;
69};
Konrad Grochowski16a23a62014-11-13 15:33:38 +010070}
71}
72} // apache::thrift::async
David Reiss5ddabb82010-10-06 17:09:37 +000073
74#endif // #ifndef _THRIFT_TEVHTTP_SERVER_H_