1 /*
2  * Copyright (c) 2006- Facebook
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 /*
7  * Licensed to the Apache Software Foundation (ASF) under one
8  * or more contributor license agreements. See the NOTICE file
9  * distributed with this work for additional information
10  * regarding copyright ownership. The ASF licenses this file
11  * to you under the Apache License, Version 2.0 (the
12  * "License"); you may not use this file except in compliance
13  * with the License. You may obtain a copy of the License at
14  *
15  *   http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing,
18  * software distributed under the License is distributed on an
19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20  * KIND, either express or implied. See the License for the
21  * specific language governing permissions and limitations
22  * under the License.
23  */
24 
25 #ifndef _THRIFT_SERVER_TSIMPLESERVER_H_
26 #define _THRIFT_SERVER_TSIMPLESERVER_H_ 1
27 
28 #include <thrift/server/TServerFramework.h>
29 
30 namespace apache
31 {
32 namespace thrift
33 {
34 namespace server
35 {
36 
37 /**
38  * This is the most basic simple server. It is single-threaded and runs a
39  * continuous loop of accepting a single connection, processing requests on
40  * that connection until it closes, and then repeating.
41  */
42 class TSimpleServer : public TServerFramework
43 {
44 public:
45 	TSimpleServer(
46 		const std::shared_ptr<apache::thrift::TProcessorFactory> &processorFactory,
47 		const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
48 		const std::shared_ptr<apache::thrift::transport::TTransportFactory>
49 			&transportFactory,
50 		const std::shared_ptr<apache::thrift::protocol::TProtocolFactory> &protocolFactory);
51 
52 	TSimpleServer(
53 		const std::shared_ptr<apache::thrift::TProcessor> &processor,
54 		const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
55 		const std::shared_ptr<apache::thrift::transport::TTransportFactory>
56 			&transportFactory,
57 		const std::shared_ptr<apache::thrift::protocol::TProtocolFactory> &protocolFactory);
58 
59 	TSimpleServer(
60 		const std::shared_ptr<apache::thrift::TProcessorFactory> &processorFactory,
61 		const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
62 		const std::shared_ptr<apache::thrift::transport::TTransportFactory>
63 			&inputTransportFactory,
64 		const std::shared_ptr<apache::thrift::transport::TTransportFactory>
65 			&outputTransportFactory,
66 		const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
67 			&inputProtocolFactory,
68 		const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
69 			&outputProtocolFactory);
70 
71 	TSimpleServer(
72 		const std::shared_ptr<apache::thrift::TProcessor> &processor,
73 		const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
74 		const std::shared_ptr<apache::thrift::transport::TTransportFactory>
75 			&inputTransportFactory,
76 		const std::shared_ptr<apache::thrift::transport::TTransportFactory>
77 			&outputTransportFactory,
78 		const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
79 			&inputProtocolFactory,
80 		const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
81 			&outputProtocolFactory);
82 
83 	~TSimpleServer();
84 
85 protected:
86 	void onClientConnected(const std::shared_ptr<TConnectedClient> &pClient) override
87 		/* override */;
88 	void onClientDisconnected(TConnectedClient *pClient) override /* override */;
89 
90 private:
91 	void setConcurrentClientLimit(int64_t newLimit) override; // hide
92 };
93 } // namespace server
94 } // namespace thrift
95 } // namespace apache
96 
97 #endif // #ifndef _THRIFT_SERVER_TSIMPLESERVER_H_
98