blob: 12c4b973db62664df3b07c0997772901dc3b55fe [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +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
Roger Meierd3b9dca2011-06-24 14:01:10 +000020#define __STDC_FORMAT_MACROS
21#include <inttypes.h>
22
Roger Meier49ff8b12012-04-13 09:12:31 +000023#include <thrift/concurrency/ThreadManager.h>
24#include <thrift/concurrency/PlatformThreadFactory.h>
25#include <thrift/protocol/TBinaryProtocol.h>
Roger Meier023192f2014-02-12 09:35:12 +010026#include <thrift/protocol/TCompactProtocol.h>
Dave Watson792db4e2015-01-16 11:22:01 -080027#include <thrift/protocol/THeaderProtocol.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000028#include <thrift/protocol/TJSONProtocol.h>
29#include <thrift/server/TSimpleServer.h>
30#include <thrift/server/TThreadedServer.h>
31#include <thrift/server/TThreadPoolServer.h>
32#include <thrift/async/TEvhttpServer.h>
33#include <thrift/async/TAsyncBufferProcessor.h>
34#include <thrift/async/TAsyncProtocolProcessor.h>
35#include <thrift/server/TNonblockingServer.h>
36#include <thrift/transport/TServerSocket.h>
37#include <thrift/transport/TSSLServerSocket.h>
38#include <thrift/transport/TSSLSocket.h>
39#include <thrift/transport/THttpServer.h>
40#include <thrift/transport/THttpTransport.h>
41#include <thrift/transport/TTransportUtils.h>
Mark Slee95771002006-06-07 06:53:25 +000042#include "ThriftTest.h"
Marc Slemko6be374b2006-08-04 03:16:25 +000043
44#include <iostream>
45#include <stdexcept>
46#include <sstream>
47
Roger Meierca142b02011-06-07 17:59:07 +000048#include <boost/program_options.hpp>
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053049#include <boost/filesystem.hpp>
Roger Meier0a7c69c2014-05-02 21:15:45 +020050#include <thrift/cxxfunctional.h>
Roger Meierca142b02011-06-07 17:59:07 +000051
Bryan Duxburycd9aea12011-02-22 18:12:06 +000052#include <signal.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050053#if _WIN32
Konrad Grochowski16a23a62014-11-13 15:33:38 +010054#include <thrift/windows/TWinsockSingleton.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050055#endif
David Reissbc3dddb2007-08-22 23:20:24 +000056
Mark Sleee8540632006-05-30 09:24:40 +000057using namespace std;
58
T Jake Lucianib5e62212009-01-31 22:36:20 +000059using namespace apache::thrift;
60using namespace apache::thrift::concurrency;
61using namespace apache::thrift::protocol;
62using namespace apache::thrift::transport;
63using namespace apache::thrift::server;
Roger Meier7e056e72011-07-17 07:28:28 +000064using namespace apache::thrift::async;
Marc Slemko6be374b2006-08-04 03:16:25 +000065
Marc Slemkobf4fd192006-08-15 21:29:39 +000066using namespace thrift::test;
67
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053068// Length of argv[0] - Length of script dir
69#define EXECUTABLE_FILE_NAME_LENGTH 19
70
Mark Sleed2655522006-09-05 22:09:57 +000071class TestHandler : public ThriftTestIf {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010072public:
Mark Sleed2655522006-09-05 22:09:57 +000073 TestHandler() {}
Mark Sleee8540632006-05-30 09:24:40 +000074
Konrad Grochowski16a23a62014-11-13 15:33:38 +010075 void testVoid() { printf("testVoid()\n"); }
Mark Sleee8540632006-05-30 09:24:40 +000076
Konrad Grochowski16a23a62014-11-13 15:33:38 +010077 void testString(string& out, const string& thing) {
Mark Sleee8540632006-05-30 09:24:40 +000078 printf("testString(\"%s\")\n", thing.c_str());
Mark Slee1921d202007-01-24 19:43:06 +000079 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +000080 }
81
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +090082 bool testBool(const bool thing) {
83 printf("testBool(%s)\n", thing ? "true" : "false");
84 return thing;
85 }
86
Mark Slee1921d202007-01-24 19:43:06 +000087 int8_t testByte(const int8_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000088 printf("testByte(%d)\n", (int)thing);
89 return thing;
90 }
91
Mark Slee1921d202007-01-24 19:43:06 +000092 int32_t testI32(const int32_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000093 printf("testI32(%d)\n", thing);
94 return thing;
95 }
96
Mark Slee1921d202007-01-24 19:43:06 +000097 int64_t testI64(const int64_t thing) {
Roger Meier0e814802014-01-17 21:07:58 +010098 printf("testI64(%" PRId64 ")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +000099 return thing;
100 }
101
Mark Slee1921d202007-01-24 19:43:06 +0000102 double testDouble(const double thing) {
Roger Meiera8cef6e2011-07-17 18:55:59 +0000103 printf("testDouble(%f)\n", thing);
Mark Sleec98d0502006-09-06 02:42:25 +0000104 return thing;
105 }
106
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100107 void testBinary(std::string& _return, const std::string& thing) {
108 std::ostringstream hexstr;
109 hexstr << std::hex << thing;
110 printf("testBinary(%s)\n", hexstr.str().c_str());
111 _return = thing;
112 }
113
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100114 void testStruct(Xtruct& out, const Xtruct& thing) {
115 printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n",
116 thing.string_thing.c_str(),
117 (int)thing.byte_thing,
118 thing.i32_thing,
119 thing.i64_thing);
Mark Slee1921d202007-01-24 19:43:06 +0000120 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000121 }
122
Mark Slee1921d202007-01-24 19:43:06 +0000123 void testNest(Xtruct2& out, const Xtruct2& nest) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100124 const Xtruct& thing = nest.struct_thing;
125 printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n",
126 (int)nest.byte_thing,
127 thing.string_thing.c_str(),
128 (int)thing.byte_thing,
129 thing.i32_thing,
130 thing.i64_thing,
131 nest.i32_thing);
Mark Slee1921d202007-01-24 19:43:06 +0000132 out = nest;
Mark Sleee8540632006-05-30 09:24:40 +0000133 }
134
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100135 void testMap(map<int32_t, int32_t>& out, const map<int32_t, int32_t>& thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000136 printf("testMap({");
137 map<int32_t, int32_t>::const_iterator m_iter;
138 bool first = true;
139 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
140 if (first) {
141 first = false;
142 } else {
143 printf(", ");
144 }
145 printf("%d => %d", m_iter->first, m_iter->second);
146 }
147 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000148 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000149 }
150
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100151 void testStringMap(map<std::string, std::string>& out,
152 const map<std::string, std::string>& thing) {
Roger Meierd3b9dca2011-06-24 14:01:10 +0000153 printf("testMap({");
154 map<std::string, std::string>::const_iterator m_iter;
155 bool first = true;
156 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
157 if (first) {
158 first = false;
159 } else {
160 printf(", ");
161 }
162 printf("%s => %s", (m_iter->first).c_str(), (m_iter->second).c_str());
163 }
164 printf("})\n");
165 out = thing;
166 }
167
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100168 void testSet(set<int32_t>& out, const set<int32_t>& thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000169 printf("testSet({");
170 set<int32_t>::const_iterator s_iter;
171 bool first = true;
172 for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) {
173 if (first) {
174 first = false;
175 } else {
176 printf(", ");
177 }
178 printf("%d", *s_iter);
179 }
180 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000181 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000182 }
183
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100184 void testList(vector<int32_t>& out, const vector<int32_t>& thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000185 printf("testList({");
Mark Sleeb9acf982006-10-10 01:57:32 +0000186 vector<int32_t>::const_iterator l_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000187 bool first = true;
188 for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) {
189 if (first) {
190 first = false;
191 } else {
192 printf(", ");
193 }
194 printf("%d", *l_iter);
195 }
196 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000197 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000198 }
199
Bryan Duxbury833ae492010-09-27 17:26:02 +0000200 Numberz::type testEnum(const Numberz::type thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000201 printf("testEnum(%d)\n", thing);
202 return thing;
203 }
204
Mark Slee1921d202007-01-24 19:43:06 +0000205 UserId testTypedef(const UserId thing) {
Roger Meier0e814802014-01-17 21:07:58 +0100206 printf("testTypedef(%" PRId64 ")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +0000207 return thing;
208 }
209
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100210 void testMapMap(map<int32_t, map<int32_t, int32_t> >& mapmap, const int32_t hello) {
Mark Sleee8540632006-05-30 09:24:40 +0000211 printf("testMapMap(%d)\n", hello);
Mark Sleee8540632006-05-30 09:24:40 +0000212
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100213 map<int32_t, int32_t> pos;
214 map<int32_t, int32_t> neg;
Mark Sleee8540632006-05-30 09:24:40 +0000215 for (int i = 1; i < 5; i++) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100216 pos.insert(make_pair(i, i));
217 neg.insert(make_pair(-i, -i));
Mark Sleee8540632006-05-30 09:24:40 +0000218 }
219
220 mapmap.insert(make_pair(4, pos));
221 mapmap.insert(make_pair(-4, neg));
Mark Sleee8540632006-05-30 09:24:40 +0000222 }
223
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100224 void testInsanity(map<UserId, map<Numberz::type, Insanity> >& insane, const Insanity& argument) {
Mark Sleee8540632006-05-30 09:24:40 +0000225 printf("testInsanity()\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000226
Mark Sleee8540632006-05-30 09:24:40 +0000227 Insanity looney;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000228 map<Numberz::type, Insanity> first_map;
229 map<Numberz::type, Insanity> second_map;
Mark Sleee8540632006-05-30 09:24:40 +0000230
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900231 first_map.insert(make_pair(Numberz::TWO, argument));
232 first_map.insert(make_pair(Numberz::THREE, argument));
Mark Sleee8540632006-05-30 09:24:40 +0000233
Bryan Duxbury833ae492010-09-27 17:26:02 +0000234 second_map.insert(make_pair(Numberz::SIX, looney));
Mark Sleee8540632006-05-30 09:24:40 +0000235
Mark Sleee8540632006-05-30 09:24:40 +0000236 insane.insert(make_pair(1, first_map));
237 insane.insert(make_pair(2, second_map));
238
239 printf("return");
240 printf(" = {");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100241 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000242 for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
Roger Meier0e814802014-01-17 21:07:58 +0100243 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100244 map<Numberz::type, Insanity>::const_iterator i2_iter;
245 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Mark Sleee8540632006-05-30 09:24:40 +0000246 printf("%d => {", i2_iter->first);
Bryan Duxbury833ae492010-09-27 17:26:02 +0000247 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
248 map<Numberz::type, UserId>::const_iterator um;
Mark Sleee8540632006-05-30 09:24:40 +0000249 printf("{");
250 for (um = userMap.begin(); um != userMap.end(); ++um) {
Roger Meier0e814802014-01-17 21:07:58 +0100251 printf("%d => %" PRId64 ", ", um->first, um->second);
Mark Sleee8540632006-05-30 09:24:40 +0000252 }
253 printf("}, ");
254
Mark Sleeb9acf982006-10-10 01:57:32 +0000255 vector<Xtruct> xtructs = i2_iter->second.xtructs;
256 vector<Xtruct>::const_iterator x;
Mark Sleee8540632006-05-30 09:24:40 +0000257 printf("{");
258 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100259 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
260 x->string_thing.c_str(),
261 (int)x->byte_thing,
262 x->i32_thing,
263 x->i64_thing);
Mark Sleee8540632006-05-30 09:24:40 +0000264 }
265 printf("}");
266
267 printf("}, ");
268 }
269 printf("}, ");
270 }
271 printf("}\n");
Mark Sleee8540632006-05-30 09:24:40 +0000272 }
Marc Slemkoe6889de2006-08-12 00:32:53 +0000273
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100274 void testMulti(Xtruct& hello,
275 const int8_t arg0,
276 const int32_t arg1,
277 const int64_t arg2,
278 const std::map<int16_t, std::string>& arg3,
279 const Numberz::type arg4,
280 const UserId arg5) {
281 (void)arg3;
282 (void)arg4;
283 (void)arg5;
Jake Farrell5d02b802014-01-07 21:42:01 -0500284
Marc Slemkoe6889de2006-08-12 00:32:53 +0000285 printf("testMulti()\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000286
Marc Slemkoe6889de2006-08-12 00:32:53 +0000287 hello.string_thing = "Hello2";
288 hello.byte_thing = arg0;
289 hello.i32_thing = arg1;
290 hello.i64_thing = (int64_t)arg2;
Marc Slemkoe6889de2006-08-12 00:32:53 +0000291 }
Marc Slemkobf4fd192006-08-15 21:29:39 +0000292
ben-craigfae08e72015-07-15 11:34:47 -0500293 void testException(const std::string& arg) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000294 printf("testException(%s)\n", arg.c_str());
Mark Sleed3d733a2006-09-01 22:19:06 +0000295 if (arg.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000296 Xception e;
297 e.errorCode = 1001;
David Reiss9813cbe2009-01-31 21:39:11 +0000298 e.message = arg;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000299 throw e;
Roger Meier1f8b48f2012-05-02 22:56:47 +0000300 } else if (arg.compare("TException") == 0) {
T Jake Lucianib5e62212009-01-31 22:36:20 +0000301 apache::thrift::TException e;
David Reiss55ff70f2008-06-11 00:58:25 +0000302 throw e;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000303 } else {
304 Xtruct result;
305 result.string_thing = arg;
306 return;
307 }
308 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000309
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100310 void testMultiException(Xtruct& result,
311 const std::string& arg0,
ben-craigfae08e72015-07-15 11:34:47 -0500312 const std::string& arg1) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000313
Marc Slemko71d4e472006-08-15 22:34:04 +0000314 printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000315
Mark Sleef5f2be42006-09-05 21:05:31 +0000316 if (arg0.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000317 Xception e;
318 e.errorCode = 1001;
319 e.message = "This is an Xception";
320 throw e;
Mark Sleef5f2be42006-09-05 21:05:31 +0000321 } else if (arg0.compare("Xception2") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000322 Xception2 e;
323 e.errorCode = 2002;
324 e.struct_thing.string_thing = "This is an Xception2";
325 throw e;
326 } else {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000327 result.string_thing = arg1;
Mark Slee1921d202007-01-24 19:43:06 +0000328 return;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000329 }
330 }
David Reiss2ab6fe82008-02-18 02:11:44 +0000331
Jake Farrell5d02b802014-01-07 21:42:01 -0500332 void testOneway(const int32_t sleepFor) {
David Reiss6ce401d2009-03-24 20:01:58 +0000333 printf("testOneway(%d): Sleeping...\n", sleepFor);
Jake Farrell5d02b802014-01-07 21:42:01 -0500334 THRIFT_SLEEP_SEC(sleepFor);
David Reiss6ce401d2009-03-24 20:01:58 +0000335 printf("testOneway(%d): done sleeping!\n", sleepFor);
David Reiss2ab6fe82008-02-18 02:11:44 +0000336 }
Mark Sleee8540632006-05-30 09:24:40 +0000337};
338
David Reissd7192062010-10-06 17:09:33 +0000339class TestProcessorEventHandler : public TProcessorEventHandler {
David Reiss23248712010-10-06 17:10:08 +0000340 virtual void* getContext(const char* fn_name, void* serverContext) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100341 (void)serverContext;
David Reissd7192062010-10-06 17:09:33 +0000342 return new std::string(fn_name);
343 }
344 virtual void freeContext(void* ctx, const char* fn_name) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100345 (void)fn_name;
David Reissd7192062010-10-06 17:09:33 +0000346 delete static_cast<std::string*>(ctx);
347 }
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100348 virtual void preRead(void* ctx, const char* fn_name) { communicate("preRead", ctx, fn_name); }
David Reissef7200f2010-10-06 17:09:42 +0000349 virtual void postRead(void* ctx, const char* fn_name, uint32_t bytes) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100350 (void)bytes;
David Reissd7192062010-10-06 17:09:33 +0000351 communicate("postRead", ctx, fn_name);
352 }
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100353 virtual void preWrite(void* ctx, const char* fn_name) { communicate("preWrite", ctx, fn_name); }
David Reissef7200f2010-10-06 17:09:42 +0000354 virtual void postWrite(void* ctx, const char* fn_name, uint32_t bytes) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100355 (void)bytes;
David Reissd7192062010-10-06 17:09:33 +0000356 communicate("postWrite", ctx, fn_name);
357 }
358 virtual void asyncComplete(void* ctx, const char* fn_name) {
359 communicate("asyncComplete", ctx, fn_name);
360 }
361 virtual void handlerError(void* ctx, const char* fn_name) {
362 communicate("handlerError", ctx, fn_name);
363 }
364
365 void communicate(const char* event, void* ctx, const char* fn_name) {
366 std::cout << event << ": " << *static_cast<std::string*>(ctx) << " = " << fn_name << std::endl;
367 }
368};
369
Roger Meier7e056e72011-07-17 07:28:28 +0000370class TestHandlerAsync : public ThriftTestCobSvIf {
371public:
Roger Meier611f90c2011-12-11 22:08:51 +0000372 TestHandlerAsync(boost::shared_ptr<TestHandler>& handler) : _delegate(handler) {}
Roger Meier7e056e72011-07-17 07:28:28 +0000373 virtual ~TestHandlerAsync() {}
374
Roger Meier0a7c69c2014-05-02 21:15:45 +0200375 virtual void testVoid(tcxx::function<void()> cob) {
Roger Meier7e056e72011-07-17 07:28:28 +0000376 _delegate->testVoid();
377 cob();
378 }
379
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100380 virtual void testString(tcxx::function<void(std::string const& _return)> cob,
381 const std::string& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000382 std::string res;
383 _delegate->testString(res, thing);
384 cob(res);
385 }
386
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900387 virtual void testBool(tcxx::function<void(bool const& _return)> cob, const bool thing) {
388 bool res = _delegate->testBool(thing);
389 cob(res);
390 }
391
Roger Meier0a7c69c2014-05-02 21:15:45 +0200392 virtual void testByte(tcxx::function<void(int8_t const& _return)> cob, const int8_t thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000393 int8_t res = _delegate->testByte(thing);
394 cob(res);
395 }
396
Roger Meier0a7c69c2014-05-02 21:15:45 +0200397 virtual void testI32(tcxx::function<void(int32_t const& _return)> cob, const int32_t thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000398 int32_t res = _delegate->testI32(thing);
399 cob(res);
400 }
401
Roger Meier0a7c69c2014-05-02 21:15:45 +0200402 virtual void testI64(tcxx::function<void(int64_t const& _return)> cob, const int64_t thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000403 int64_t res = _delegate->testI64(thing);
404 cob(res);
405 }
406
Roger Meier0a7c69c2014-05-02 21:15:45 +0200407 virtual void testDouble(tcxx::function<void(double const& _return)> cob, const double thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000408 double res = _delegate->testDouble(thing);
409 cob(res);
410 }
411
Konrad Grochowski1f6e3802015-05-18 18:10:06 +0200412 virtual void testBinary(tcxx::function<void(std::string const& _return)> cob,
413 const std::string& thing) {
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100414 std::string res;
415 _delegate->testBinary(res, thing);
416 cob(res);
417 }
418
Roger Meier0a7c69c2014-05-02 21:15:45 +0200419 virtual void testStruct(tcxx::function<void(Xtruct const& _return)> cob, const Xtruct& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000420 Xtruct res;
421 _delegate->testStruct(res, thing);
422 cob(res);
423 }
424
Roger Meier0a7c69c2014-05-02 21:15:45 +0200425 virtual void testNest(tcxx::function<void(Xtruct2 const& _return)> cob, const Xtruct2& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000426 Xtruct2 res;
427 _delegate->testNest(res, thing);
428 cob(res);
429 }
430
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100431 virtual void testMap(tcxx::function<void(std::map<int32_t, int32_t> const& _return)> cob,
432 const std::map<int32_t, int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000433 std::map<int32_t, int32_t> res;
434 _delegate->testMap(res, thing);
435 cob(res);
436 }
437
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100438 virtual void testStringMap(
439 tcxx::function<void(std::map<std::string, std::string> const& _return)> cob,
440 const std::map<std::string, std::string>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000441 std::map<std::string, std::string> res;
442 _delegate->testStringMap(res, thing);
443 cob(res);
444 }
445
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100446 virtual void testSet(tcxx::function<void(std::set<int32_t> const& _return)> cob,
447 const std::set<int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000448 std::set<int32_t> res;
449 _delegate->testSet(res, thing);
450 cob(res);
451 }
452
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100453 virtual void testList(tcxx::function<void(std::vector<int32_t> const& _return)> cob,
454 const std::vector<int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000455 std::vector<int32_t> res;
456 _delegate->testList(res, thing);
457 cob(res);
458 }
459
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100460 virtual void testEnum(tcxx::function<void(Numberz::type const& _return)> cob,
461 const Numberz::type thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000462 Numberz::type res = _delegate->testEnum(thing);
463 cob(res);
464 }
465
Roger Meier0a7c69c2014-05-02 21:15:45 +0200466 virtual void testTypedef(tcxx::function<void(UserId const& _return)> cob, const UserId thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000467 UserId res = _delegate->testTypedef(thing);
468 cob(res);
469 }
470
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100471 virtual void testMapMap(
472 tcxx::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob,
473 const int32_t hello) {
Roger Meier7e056e72011-07-17 07:28:28 +0000474 std::map<int32_t, std::map<int32_t, int32_t> > res;
475 _delegate->testMapMap(res, hello);
476 cob(res);
477 }
478
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100479 virtual void testInsanity(
480 tcxx::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob,
481 const Insanity& argument) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500482 std::map<UserId, std::map<Numberz::type, Insanity> > res;
Roger Meier7e056e72011-07-17 07:28:28 +0000483 _delegate->testInsanity(res, argument);
484 cob(res);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100485 }
Roger Meier7e056e72011-07-17 07:28:28 +0000486
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100487 virtual void testMulti(tcxx::function<void(Xtruct const& _return)> cob,
488 const int8_t arg0,
489 const int32_t arg1,
490 const int64_t arg2,
491 const std::map<int16_t, std::string>& arg3,
492 const Numberz::type arg4,
493 const UserId arg5) {
Roger Meier7e056e72011-07-17 07:28:28 +0000494 Xtruct res;
495 _delegate->testMulti(res, arg0, arg1, arg2, arg3, arg4, arg5);
496 cob(res);
497 }
498
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100499 virtual void testException(
500 tcxx::function<void()> cob,
501 tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
502 const std::string& arg) {
Roger Meier7e056e72011-07-17 07:28:28 +0000503 try {
504 _delegate->testException(arg);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100505 } catch (const apache::thrift::TException& e) {
Roger Meier7e056e72011-07-17 07:28:28 +0000506 exn_cob(apache::thrift::TDelayedException::delayException(e));
507 return;
508 }
509 cob();
510 }
511
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100512 virtual void testMultiException(
513 tcxx::function<void(Xtruct const& _return)> cob,
514 tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
515 const std::string& arg0,
516 const std::string& arg1) {
Roger Meier7e056e72011-07-17 07:28:28 +0000517 Xtruct res;
518 try {
519 _delegate->testMultiException(res, arg0, arg1);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100520 } catch (const apache::thrift::TException& e) {
Roger Meier7e056e72011-07-17 07:28:28 +0000521 exn_cob(apache::thrift::TDelayedException::delayException(e));
522 return;
523 }
524 cob(res);
525 }
526
Roger Meier0a7c69c2014-05-02 21:15:45 +0200527 virtual void testOneway(tcxx::function<void()> cob, const int32_t secondsToSleep) {
Roger Meier7e056e72011-07-17 07:28:28 +0000528 _delegate->testOneway(secondsToSleep);
529 cob();
530 }
531
532protected:
Roger Meier611f90c2011-12-11 22:08:51 +0000533 boost::shared_ptr<TestHandler> _delegate;
Roger Meier7e056e72011-07-17 07:28:28 +0000534};
535
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100536int main(int argc, char** argv) {
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530537
538 string file_path = boost::filesystem::system_complete(argv[0]).string();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100539 string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530540
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100541#if _WIN32
Jake Farrell5d02b802014-01-07 21:42:01 -0500542 transport::TWinsockSingleton::create();
543#endif
Mark Sleee8540632006-05-30 09:24:40 +0000544 int port = 9090;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000545 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000546 string transport_type = "buffered";
547 string protocol_type = "binary";
548 string server_type = "simple";
549 string domain_socket = "";
pavlodd08f6e2015-10-08 16:43:56 -0400550 bool abstract_namespace = false;
Roger Meierca142b02011-06-07 17:59:07 +0000551 size_t workers = 4;
Marc Slemko6be374b2006-08-04 03:16:25 +0000552
Jake Farrell5d02b802014-01-07 21:42:01 -0500553 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100554 desc.add_options()("help,h", "produce help message")(
555 "port",
556 boost::program_options::value<int>(&port)->default_value(port),
557 "Port number to listen")("domain-socket",
558 boost::program_options::value<string>(&domain_socket)
559 ->default_value(domain_socket),
560 "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)")(
pavlodd08f6e2015-10-08 16:43:56 -0400561 "abstract-namespace",
562 "Create the domain socket in the Abstract Namespace (no connection with filesystem pathnames)")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100563 "server-type",
564 boost::program_options::value<string>(&server_type)->default_value(server_type),
565 "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"")(
566 "transport",
567 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
568 "transport: buffered, framed, http")(
569 "protocol",
570 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
Dave Watson792db4e2015-01-16 11:22:01 -0800571 "protocol: binary, compact, header, json")("ssl", "Encrypted Transport using SSL")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100572 "processor-events",
573 "processor-events")("workers,n",
574 boost::program_options::value<size_t>(&workers)->default_value(workers),
575 "Number of thread pools workers. Only valid for thread-pool server type");
Marc Slemko6be374b2006-08-04 03:16:25 +0000576
Jake Farrell5d02b802014-01-07 21:42:01 -0500577 boost::program_options::variables_map vm;
578 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
579 boost::program_options::notify(vm);
Marc Slemko6be374b2006-08-04 03:16:25 +0000580
Roger Meierca142b02011-06-07 17:59:07 +0000581 if (vm.count("help")) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100582 cout << desc << "\n";
583 return 1;
Mark Sleee8540632006-05-30 09:24:40 +0000584 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500585
Marc Slemko6be374b2006-08-04 03:16:25 +0000586 try {
Roger Meierca142b02011-06-07 17:59:07 +0000587 if (!server_type.empty()) {
588 if (server_type == "simple") {
589 } else if (server_type == "thread-pool") {
590 } else if (server_type == "threaded") {
591 } else if (server_type == "nonblocking") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000592 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100593 throw invalid_argument("Unknown server type " + server_type);
Roger Meierca142b02011-06-07 17:59:07 +0000594 }
595 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500596
Roger Meierca142b02011-06-07 17:59:07 +0000597 if (!protocol_type.empty()) {
598 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100599 } else if (protocol_type == "compact") {
Roger Meierca142b02011-06-07 17:59:07 +0000600 } else if (protocol_type == "json") {
Dave Watson792db4e2015-01-16 11:22:01 -0800601 } else if (protocol_type == "header") {
Roger Meierca142b02011-06-07 17:59:07 +0000602 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100603 throw invalid_argument("Unknown protocol type " + protocol_type);
Marc Slemko6be374b2006-08-04 03:16:25 +0000604 }
605 }
606
Roger Meier284101c2014-03-11 21:20:35 +0100607 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000608 if (transport_type == "buffered") {
609 } else if (transport_type == "framed") {
610 } else if (transport_type == "http") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000611 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100612 throw invalid_argument("Unknown transport type " + transport_type);
Marc Slemko6be374b2006-08-04 03:16:25 +0000613 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000614 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000615
Bryan Duxbury833ae492010-09-27 17:26:02 +0000616 } catch (std::exception& e) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000617 cerr << e.what() << endl;
Roger Meierca142b02011-06-07 17:59:07 +0000618 cout << desc << "\n";
619 return 1;
Marc Slemko6be374b2006-08-04 03:16:25 +0000620 }
621
Roger Meierca142b02011-06-07 17:59:07 +0000622 if (vm.count("ssl")) {
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000623 ssl = true;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000624 }
625
pavlodd08f6e2015-10-08 16:43:56 -0400626 if (vm.count("abstract-namespace")) {
627 abstract_namespace = true;
628 }
629
Mark Sleee8540632006-05-30 09:24:40 +0000630 // Dispatcher
Roger Meier611f90c2011-12-11 22:08:51 +0000631 boost::shared_ptr<TProtocolFactory> protocolFactory;
Roger Meierca142b02011-06-07 17:59:07 +0000632 if (protocol_type == "json") {
Roger Meier611f90c2011-12-11 22:08:51 +0000633 boost::shared_ptr<TProtocolFactory> jsonProtocolFactory(new TJSONProtocolFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000634 protocolFactory = jsonProtocolFactory;
Roger Meier023192f2014-02-12 09:35:12 +0100635 } else if (protocol_type == "compact") {
636 boost::shared_ptr<TProtocolFactory> compactProtocolFactory(new TCompactProtocolFactory());
637 protocolFactory = compactProtocolFactory;
Dave Watson792db4e2015-01-16 11:22:01 -0800638 } else if (protocol_type == "header") {
639 boost::shared_ptr<TProtocolFactory> headerProtocolFactory(new THeaderProtocolFactory());
640 protocolFactory = headerProtocolFactory;
Roger Meierca142b02011-06-07 17:59:07 +0000641 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100642 boost::shared_ptr<TProtocolFactory> binaryProtocolFactory(
643 new TBinaryProtocolFactoryT<TBufferBase>());
Roger Meierca142b02011-06-07 17:59:07 +0000644 protocolFactory = binaryProtocolFactory;
645 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000646
Roger Meierca142b02011-06-07 17:59:07 +0000647 // Processor
Roger Meier611f90c2011-12-11 22:08:51 +0000648 boost::shared_ptr<TestHandler> testHandler(new TestHandler());
649 boost::shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
Jake Farrell5d02b802014-01-07 21:42:01 -0500650
Roger Meierca142b02011-06-07 17:59:07 +0000651 if (vm.count("processor-events")) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100652 testProcessor->setEventHandler(
653 boost::shared_ptr<TProcessorEventHandler>(new TestProcessorEventHandler()));
David Reissd7192062010-10-06 17:09:33 +0000654 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500655
Mark Sleee8540632006-05-30 09:24:40 +0000656 // Transport
Roger Meier611f90c2011-12-11 22:08:51 +0000657 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory;
658 boost::shared_ptr<TServerSocket> serverSocket;
Mark Sleee8540632006-05-30 09:24:40 +0000659
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000660 if (ssl) {
Roger Meier611f90c2011-12-11 22:08:51 +0000661 sslSocketFactory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530662 sslSocketFactory->loadCertificate((dir_path + "../keys/server.crt").c_str());
663 sslSocketFactory->loadPrivateKey((dir_path + "../keys/server.key").c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000664 sslSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Roger Meier611f90c2011-12-11 22:08:51 +0000665 serverSocket = boost::shared_ptr<TServerSocket>(new TSSLServerSocket(port, sslSocketFactory));
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000666 } else {
Roger Meierc94b2932014-02-22 20:07:33 +0100667 if (domain_socket != "") {
pavlodd08f6e2015-10-08 16:43:56 -0400668 if (abstract_namespace) {
669 std::string abstract_socket("\0", 1);
670 abstract_socket += domain_socket;
671 serverSocket = boost::shared_ptr<TServerSocket>(new TServerSocket(abstract_socket));
672 } else {
673 unlink(domain_socket.c_str());
674 serverSocket = boost::shared_ptr<TServerSocket>(new TServerSocket(domain_socket));
675 }
Roger Meierc94b2932014-02-22 20:07:33 +0100676 port = 0;
677 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000678 serverSocket = boost::shared_ptr<TServerSocket>(new TServerSocket(port));
Roger Meierc94b2932014-02-22 20:07:33 +0100679 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000680 }
Roger Meierca142b02011-06-07 17:59:07 +0000681
Mark Sleed788b2e2006-09-07 01:26:35 +0000682 // Factory
Roger Meier611f90c2011-12-11 22:08:51 +0000683 boost::shared_ptr<TTransportFactory> transportFactory;
Jake Farrell5d02b802014-01-07 21:42:01 -0500684
Roger Meier7e056e72011-07-17 07:28:28 +0000685 if (transport_type == "http" && server_type != "nonblocking") {
Jake Farrell5d02b802014-01-07 21:42:01 -0500686 boost::shared_ptr<TTransportFactory> httpTransportFactory(new THttpServerTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000687 transportFactory = httpTransportFactory;
688 } else if (transport_type == "framed") {
Jake Farrell5d02b802014-01-07 21:42:01 -0500689 boost::shared_ptr<TTransportFactory> framedTransportFactory(new TFramedTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000690 transportFactory = framedTransportFactory;
691 } else {
Jake Farrell5d02b802014-01-07 21:42:01 -0500692 boost::shared_ptr<TTransportFactory> bufferedTransportFactory(new TBufferedTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000693 transportFactory = bufferedTransportFactory;
694 }
Mark Sleed788b2e2006-09-07 01:26:35 +0000695
Roger Meierca142b02011-06-07 17:59:07 +0000696 // Server Info
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100697 cout << "Starting \"" << server_type << "\" server (" << transport_type << "/" << protocol_type
pavlodd08f6e2015-10-08 16:43:56 -0400698 << ") listen on: ";
699 if (abstract_namespace) {
700 cout << '@';
701 }
702 cout << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000703 if (port != 0) {
704 cout << port;
705 }
706 cout << endl;
Mark Sleee8540632006-05-30 09:24:40 +0000707
Roger Meierca142b02011-06-07 17:59:07 +0000708 // Server
Jake Farrell5d02b802014-01-07 21:42:01 -0500709 boost::shared_ptr<apache::thrift::server::TServer> server;
710
Roger Meierca142b02011-06-07 17:59:07 +0000711 if (server_type == "simple") {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100712 server.reset(new TSimpleServer(testProcessor, serverSocket, transportFactory, protocolFactory));
Roger Meierca142b02011-06-07 17:59:07 +0000713 } else if (server_type == "thread-pool") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000714
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100715 boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workers);
Marc Slemko6be374b2006-08-04 03:16:25 +0000716
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100717 boost::shared_ptr<PlatformThreadFactory> threadFactory
718 = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
Marc Slemko6be374b2006-08-04 03:16:25 +0000719
720 threadManager->threadFactory(threadFactory);
721
722 threadManager->start();
723
Jake Farrell5d02b802014-01-07 21:42:01 -0500724 server.reset(new TThreadPoolServer(testProcessor,
Roger Meierca142b02011-06-07 17:59:07 +0000725 serverSocket,
Mark Sleed788b2e2006-09-07 01:26:35 +0000726 transportFactory,
Mark Sleea3302652006-10-25 19:03:32 +0000727 protocolFactory,
Jake Farrell5d02b802014-01-07 21:42:01 -0500728 threadManager));
Roger Meierca142b02011-06-07 17:59:07 +0000729 } else if (server_type == "threaded") {
David Reiss0c90f6f2008-02-06 22:18:40 +0000730
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100731 server.reset(
732 new TThreadedServer(testProcessor, serverSocket, transportFactory, protocolFactory));
Roger Meierca142b02011-06-07 17:59:07 +0000733 } else if (server_type == "nonblocking") {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100734 if (transport_type == "http") {
Roger Meier611f90c2011-12-11 22:08:51 +0000735 boost::shared_ptr<TestHandlerAsync> testHandlerAsync(new TestHandlerAsync(testHandler));
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100736 boost::shared_ptr<TAsyncProcessor> testProcessorAsync(
737 new ThriftTestAsyncProcessor(testHandlerAsync));
738 boost::shared_ptr<TAsyncBufferProcessor> testBufferProcessor(
739 new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory));
Jake Farrell5d02b802014-01-07 21:42:01 -0500740
741 // not loading nonblockingServer into "server" because
742 // TEvhttpServer doesn't inherit from TServer, and doesn't
743 // provide a stop method.
Roger Meier7e056e72011-07-17 07:28:28 +0000744 TEvhttpServer nonblockingServer(testBufferProcessor, port);
745 nonblockingServer.serve();
Jake Farrell5d02b802014-01-07 21:42:01 -0500746 } else {
Dave Watson792db4e2015-01-16 11:22:01 -0800747 server.reset(new TNonblockingServer(testProcessor, protocolFactory, port));
Roger Meier7e056e72011-07-17 07:28:28 +0000748 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000749 }
750
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100751 if (server.get() != NULL) {
Dave Watson792db4e2015-01-16 11:22:01 -0800752 if (protocol_type == "header") {
753 // Tell the server to use the same protocol for input / output
754 // if using header
755 server->setOutputProtocolFactory(boost::shared_ptr<TProtocolFactory>());
756 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500757 apache::thrift::concurrency::PlatformThreadFactory factory;
758 factory.setDetached(false);
759 boost::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100760 boost::shared_ptr<apache::thrift::concurrency::Thread> thread
761 = factory.newThread(serverThreadRunner);
Jake Farrell5d02b802014-01-07 21:42:01 -0500762 thread->start();
763
Roger Meier284101c2014-03-11 21:20:35 +0100764 // HACK: cross language test suite is unable to handle cin properly
765 // that's why we stay in a endless loop here
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100766 while (1) {
767 }
Roger Meier284101c2014-03-11 21:20:35 +0100768 // FIXME: find another way to stop the server (e.g. a signal)
769 // cout<<"Press enter to stop the server."<<endl;
770 // cin.ignore(); //wait until a key is pressed
Jake Farrell5d02b802014-01-07 21:42:01 -0500771
772 server->stop();
773 thread->join();
774 server.reset();
775 }
776
Roger Meierca142b02011-06-07 17:59:07 +0000777 cout << "done." << endl;
Mark Sleee8540632006-05-30 09:24:40 +0000778 return 0;
779}