blob: e5bc31e93fd6537c427fdb79a21276e0c9b4f181 [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>
Roger Meier49ff8b12012-04-13 09:12:31 +000027#include <thrift/protocol/TJSONProtocol.h>
28#include <thrift/server/TSimpleServer.h>
29#include <thrift/server/TThreadedServer.h>
30#include <thrift/server/TThreadPoolServer.h>
31#include <thrift/async/TEvhttpServer.h>
32#include <thrift/async/TAsyncBufferProcessor.h>
33#include <thrift/async/TAsyncProtocolProcessor.h>
34#include <thrift/server/TNonblockingServer.h>
35#include <thrift/transport/TServerSocket.h>
36#include <thrift/transport/TSSLServerSocket.h>
37#include <thrift/transport/TSSLSocket.h>
38#include <thrift/transport/THttpServer.h>
39#include <thrift/transport/THttpTransport.h>
40#include <thrift/transport/TTransportUtils.h>
Mark Slee95771002006-06-07 06:53:25 +000041#include "ThriftTest.h"
Marc Slemko6be374b2006-08-04 03:16:25 +000042
43#include <iostream>
44#include <stdexcept>
45#include <sstream>
46
Roger Meierca142b02011-06-07 17:59:07 +000047#include <boost/program_options.hpp>
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053048#include <boost/filesystem.hpp>
Roger Meier0a7c69c2014-05-02 21:15:45 +020049#include <thrift/cxxfunctional.h>
Roger Meierca142b02011-06-07 17:59:07 +000050
Bryan Duxburycd9aea12011-02-22 18:12:06 +000051#include <signal.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050052#if _WIN32
Konrad Grochowski16a23a62014-11-13 15:33:38 +010053#include <thrift/windows/TWinsockSingleton.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050054#endif
David Reissbc3dddb2007-08-22 23:20:24 +000055
Mark Sleee8540632006-05-30 09:24:40 +000056using namespace std;
57
T Jake Lucianib5e62212009-01-31 22:36:20 +000058using namespace apache::thrift;
59using namespace apache::thrift::concurrency;
60using namespace apache::thrift::protocol;
61using namespace apache::thrift::transport;
62using namespace apache::thrift::server;
Roger Meier7e056e72011-07-17 07:28:28 +000063using namespace apache::thrift::async;
Marc Slemko6be374b2006-08-04 03:16:25 +000064
Marc Slemkobf4fd192006-08-15 21:29:39 +000065using namespace thrift::test;
66
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053067// Length of argv[0] - Length of script dir
68#define EXECUTABLE_FILE_NAME_LENGTH 19
69
Mark Sleed2655522006-09-05 22:09:57 +000070class TestHandler : public ThriftTestIf {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010071public:
Mark Sleed2655522006-09-05 22:09:57 +000072 TestHandler() {}
Mark Sleee8540632006-05-30 09:24:40 +000073
Konrad Grochowski16a23a62014-11-13 15:33:38 +010074 void testVoid() { printf("testVoid()\n"); }
Mark Sleee8540632006-05-30 09:24:40 +000075
Konrad Grochowski16a23a62014-11-13 15:33:38 +010076 void testString(string& out, const string& thing) {
Mark Sleee8540632006-05-30 09:24:40 +000077 printf("testString(\"%s\")\n", thing.c_str());
Mark Slee1921d202007-01-24 19:43:06 +000078 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +000079 }
80
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +090081 bool testBool(const bool thing) {
82 printf("testBool(%s)\n", thing ? "true" : "false");
83 return thing;
84 }
85
Mark Slee1921d202007-01-24 19:43:06 +000086 int8_t testByte(const int8_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000087 printf("testByte(%d)\n", (int)thing);
88 return thing;
89 }
90
Mark Slee1921d202007-01-24 19:43:06 +000091 int32_t testI32(const int32_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000092 printf("testI32(%d)\n", thing);
93 return thing;
94 }
95
Mark Slee1921d202007-01-24 19:43:06 +000096 int64_t testI64(const int64_t thing) {
Roger Meier0e814802014-01-17 21:07:58 +010097 printf("testI64(%" PRId64 ")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +000098 return thing;
99 }
100
Mark Slee1921d202007-01-24 19:43:06 +0000101 double testDouble(const double thing) {
Roger Meiera8cef6e2011-07-17 18:55:59 +0000102 printf("testDouble(%f)\n", thing);
Mark Sleec98d0502006-09-06 02:42:25 +0000103 return thing;
104 }
105
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100106 void testBinary(std::string& _return, const std::string& thing) {
107 std::ostringstream hexstr;
108 hexstr << std::hex << thing;
109 printf("testBinary(%s)\n", hexstr.str().c_str());
110 _return = thing;
111 }
112
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100113 void testStruct(Xtruct& out, const Xtruct& thing) {
114 printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n",
115 thing.string_thing.c_str(),
116 (int)thing.byte_thing,
117 thing.i32_thing,
118 thing.i64_thing);
Mark Slee1921d202007-01-24 19:43:06 +0000119 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000120 }
121
Mark Slee1921d202007-01-24 19:43:06 +0000122 void testNest(Xtruct2& out, const Xtruct2& nest) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100123 const Xtruct& thing = nest.struct_thing;
124 printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n",
125 (int)nest.byte_thing,
126 thing.string_thing.c_str(),
127 (int)thing.byte_thing,
128 thing.i32_thing,
129 thing.i64_thing,
130 nest.i32_thing);
Mark Slee1921d202007-01-24 19:43:06 +0000131 out = nest;
Mark Sleee8540632006-05-30 09:24:40 +0000132 }
133
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100134 void testMap(map<int32_t, int32_t>& out, const map<int32_t, int32_t>& thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000135 printf("testMap({");
136 map<int32_t, int32_t>::const_iterator m_iter;
137 bool first = true;
138 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
139 if (first) {
140 first = false;
141 } else {
142 printf(", ");
143 }
144 printf("%d => %d", m_iter->first, m_iter->second);
145 }
146 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000147 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000148 }
149
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100150 void testStringMap(map<std::string, std::string>& out,
151 const map<std::string, std::string>& thing) {
Roger Meierd3b9dca2011-06-24 14:01:10 +0000152 printf("testMap({");
153 map<std::string, std::string>::const_iterator m_iter;
154 bool first = true;
155 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
156 if (first) {
157 first = false;
158 } else {
159 printf(", ");
160 }
161 printf("%s => %s", (m_iter->first).c_str(), (m_iter->second).c_str());
162 }
163 printf("})\n");
164 out = thing;
165 }
166
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100167 void testSet(set<int32_t>& out, const set<int32_t>& thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000168 printf("testSet({");
169 set<int32_t>::const_iterator s_iter;
170 bool first = true;
171 for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) {
172 if (first) {
173 first = false;
174 } else {
175 printf(", ");
176 }
177 printf("%d", *s_iter);
178 }
179 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000180 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000181 }
182
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100183 void testList(vector<int32_t>& out, const vector<int32_t>& thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000184 printf("testList({");
Mark Sleeb9acf982006-10-10 01:57:32 +0000185 vector<int32_t>::const_iterator l_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000186 bool first = true;
187 for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) {
188 if (first) {
189 first = false;
190 } else {
191 printf(", ");
192 }
193 printf("%d", *l_iter);
194 }
195 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000196 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000197 }
198
Bryan Duxbury833ae492010-09-27 17:26:02 +0000199 Numberz::type testEnum(const Numberz::type thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000200 printf("testEnum(%d)\n", thing);
201 return thing;
202 }
203
Mark Slee1921d202007-01-24 19:43:06 +0000204 UserId testTypedef(const UserId thing) {
Roger Meier0e814802014-01-17 21:07:58 +0100205 printf("testTypedef(%" PRId64 ")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +0000206 return thing;
207 }
208
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100209 void testMapMap(map<int32_t, map<int32_t, int32_t> >& mapmap, const int32_t hello) {
Mark Sleee8540632006-05-30 09:24:40 +0000210 printf("testMapMap(%d)\n", hello);
Mark Sleee8540632006-05-30 09:24:40 +0000211
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100212 map<int32_t, int32_t> pos;
213 map<int32_t, int32_t> neg;
Mark Sleee8540632006-05-30 09:24:40 +0000214 for (int i = 1; i < 5; i++) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100215 pos.insert(make_pair(i, i));
216 neg.insert(make_pair(-i, -i));
Mark Sleee8540632006-05-30 09:24:40 +0000217 }
218
219 mapmap.insert(make_pair(4, pos));
220 mapmap.insert(make_pair(-4, neg));
Mark Sleee8540632006-05-30 09:24:40 +0000221 }
222
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100223 void testInsanity(map<UserId, map<Numberz::type, Insanity> >& insane, const Insanity& argument) {
224 (void)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 Xtruct hello;
228 hello.string_thing = "Hello2";
229 hello.byte_thing = 2;
Mark Sleee8540632006-05-30 09:24:40 +0000230 hello.i32_thing = 2;
Mark Sleee8540632006-05-30 09:24:40 +0000231 hello.i64_thing = 2;
232
233 Xtruct goodbye;
234 goodbye.string_thing = "Goodbye4";
235 goodbye.byte_thing = 4;
Mark Sleee8540632006-05-30 09:24:40 +0000236 goodbye.i32_thing = 4;
Mark Sleee8540632006-05-30 09:24:40 +0000237 goodbye.i64_thing = 4;
238
239 Insanity crazy;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000240 crazy.userMap.insert(make_pair(Numberz::EIGHT, 8));
Mark Sleee8540632006-05-30 09:24:40 +0000241 crazy.xtructs.push_back(goodbye);
242
243 Insanity looney;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000244 crazy.userMap.insert(make_pair(Numberz::FIVE, 5));
Mark Sleee8540632006-05-30 09:24:40 +0000245 crazy.xtructs.push_back(hello);
246
Bryan Duxbury833ae492010-09-27 17:26:02 +0000247 map<Numberz::type, Insanity> first_map;
248 map<Numberz::type, Insanity> second_map;
Mark Sleee8540632006-05-30 09:24:40 +0000249
Bryan Duxbury833ae492010-09-27 17:26:02 +0000250 first_map.insert(make_pair(Numberz::TWO, crazy));
251 first_map.insert(make_pair(Numberz::THREE, crazy));
Mark Sleee8540632006-05-30 09:24:40 +0000252
Bryan Duxbury833ae492010-09-27 17:26:02 +0000253 second_map.insert(make_pair(Numberz::SIX, looney));
Mark Sleee8540632006-05-30 09:24:40 +0000254
Mark Sleee8540632006-05-30 09:24:40 +0000255 insane.insert(make_pair(1, first_map));
256 insane.insert(make_pair(2, second_map));
257
258 printf("return");
259 printf(" = {");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100260 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000261 for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
Roger Meier0e814802014-01-17 21:07:58 +0100262 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100263 map<Numberz::type, Insanity>::const_iterator i2_iter;
264 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Mark Sleee8540632006-05-30 09:24:40 +0000265 printf("%d => {", i2_iter->first);
Bryan Duxbury833ae492010-09-27 17:26:02 +0000266 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
267 map<Numberz::type, UserId>::const_iterator um;
Mark Sleee8540632006-05-30 09:24:40 +0000268 printf("{");
269 for (um = userMap.begin(); um != userMap.end(); ++um) {
Roger Meier0e814802014-01-17 21:07:58 +0100270 printf("%d => %" PRId64 ", ", um->first, um->second);
Mark Sleee8540632006-05-30 09:24:40 +0000271 }
272 printf("}, ");
273
Mark Sleeb9acf982006-10-10 01:57:32 +0000274 vector<Xtruct> xtructs = i2_iter->second.xtructs;
275 vector<Xtruct>::const_iterator x;
Mark Sleee8540632006-05-30 09:24:40 +0000276 printf("{");
277 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100278 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
279 x->string_thing.c_str(),
280 (int)x->byte_thing,
281 x->i32_thing,
282 x->i64_thing);
Mark Sleee8540632006-05-30 09:24:40 +0000283 }
284 printf("}");
285
286 printf("}, ");
287 }
288 printf("}, ");
289 }
290 printf("}\n");
Mark Sleee8540632006-05-30 09:24:40 +0000291 }
Marc Slemkoe6889de2006-08-12 00:32:53 +0000292
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100293 void testMulti(Xtruct& hello,
294 const int8_t arg0,
295 const int32_t arg1,
296 const int64_t arg2,
297 const std::map<int16_t, std::string>& arg3,
298 const Numberz::type arg4,
299 const UserId arg5) {
300 (void)arg3;
301 (void)arg4;
302 (void)arg5;
Jake Farrell5d02b802014-01-07 21:42:01 -0500303
Marc Slemkoe6889de2006-08-12 00:32:53 +0000304 printf("testMulti()\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000305
Marc Slemkoe6889de2006-08-12 00:32:53 +0000306 hello.string_thing = "Hello2";
307 hello.byte_thing = arg0;
308 hello.i32_thing = arg1;
309 hello.i64_thing = (int64_t)arg2;
Marc Slemkoe6889de2006-08-12 00:32:53 +0000310 }
Marc Slemkobf4fd192006-08-15 21:29:39 +0000311
ben-craigfae08e72015-07-15 11:34:47 -0500312 void testException(const std::string& arg) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000313 printf("testException(%s)\n", arg.c_str());
Mark Sleed3d733a2006-09-01 22:19:06 +0000314 if (arg.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000315 Xception e;
316 e.errorCode = 1001;
David Reiss9813cbe2009-01-31 21:39:11 +0000317 e.message = arg;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000318 throw e;
Roger Meier1f8b48f2012-05-02 22:56:47 +0000319 } else if (arg.compare("TException") == 0) {
T Jake Lucianib5e62212009-01-31 22:36:20 +0000320 apache::thrift::TException e;
David Reiss55ff70f2008-06-11 00:58:25 +0000321 throw e;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000322 } else {
323 Xtruct result;
324 result.string_thing = arg;
325 return;
326 }
327 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000328
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100329 void testMultiException(Xtruct& result,
330 const std::string& arg0,
ben-craigfae08e72015-07-15 11:34:47 -0500331 const std::string& arg1) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000332
Marc Slemko71d4e472006-08-15 22:34:04 +0000333 printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000334
Mark Sleef5f2be42006-09-05 21:05:31 +0000335 if (arg0.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000336 Xception e;
337 e.errorCode = 1001;
338 e.message = "This is an Xception";
339 throw e;
Mark Sleef5f2be42006-09-05 21:05:31 +0000340 } else if (arg0.compare("Xception2") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000341 Xception2 e;
342 e.errorCode = 2002;
343 e.struct_thing.string_thing = "This is an Xception2";
344 throw e;
345 } else {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000346 result.string_thing = arg1;
Mark Slee1921d202007-01-24 19:43:06 +0000347 return;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000348 }
349 }
David Reiss2ab6fe82008-02-18 02:11:44 +0000350
Jake Farrell5d02b802014-01-07 21:42:01 -0500351 void testOneway(const int32_t sleepFor) {
David Reiss6ce401d2009-03-24 20:01:58 +0000352 printf("testOneway(%d): Sleeping...\n", sleepFor);
Jake Farrell5d02b802014-01-07 21:42:01 -0500353 THRIFT_SLEEP_SEC(sleepFor);
David Reiss6ce401d2009-03-24 20:01:58 +0000354 printf("testOneway(%d): done sleeping!\n", sleepFor);
David Reiss2ab6fe82008-02-18 02:11:44 +0000355 }
Mark Sleee8540632006-05-30 09:24:40 +0000356};
357
David Reissd7192062010-10-06 17:09:33 +0000358class TestProcessorEventHandler : public TProcessorEventHandler {
David Reiss23248712010-10-06 17:10:08 +0000359 virtual void* getContext(const char* fn_name, void* serverContext) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100360 (void)serverContext;
David Reissd7192062010-10-06 17:09:33 +0000361 return new std::string(fn_name);
362 }
363 virtual void freeContext(void* ctx, const char* fn_name) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100364 (void)fn_name;
David Reissd7192062010-10-06 17:09:33 +0000365 delete static_cast<std::string*>(ctx);
366 }
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100367 virtual void preRead(void* ctx, const char* fn_name) { communicate("preRead", ctx, fn_name); }
David Reissef7200f2010-10-06 17:09:42 +0000368 virtual void postRead(void* ctx, const char* fn_name, uint32_t bytes) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100369 (void)bytes;
David Reissd7192062010-10-06 17:09:33 +0000370 communicate("postRead", ctx, fn_name);
371 }
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100372 virtual void preWrite(void* ctx, const char* fn_name) { communicate("preWrite", ctx, fn_name); }
David Reissef7200f2010-10-06 17:09:42 +0000373 virtual void postWrite(void* ctx, const char* fn_name, uint32_t bytes) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100374 (void)bytes;
David Reissd7192062010-10-06 17:09:33 +0000375 communicate("postWrite", ctx, fn_name);
376 }
377 virtual void asyncComplete(void* ctx, const char* fn_name) {
378 communicate("asyncComplete", ctx, fn_name);
379 }
380 virtual void handlerError(void* ctx, const char* fn_name) {
381 communicate("handlerError", ctx, fn_name);
382 }
383
384 void communicate(const char* event, void* ctx, const char* fn_name) {
385 std::cout << event << ": " << *static_cast<std::string*>(ctx) << " = " << fn_name << std::endl;
386 }
387};
388
Roger Meier7e056e72011-07-17 07:28:28 +0000389class TestHandlerAsync : public ThriftTestCobSvIf {
390public:
Roger Meier611f90c2011-12-11 22:08:51 +0000391 TestHandlerAsync(boost::shared_ptr<TestHandler>& handler) : _delegate(handler) {}
Roger Meier7e056e72011-07-17 07:28:28 +0000392 virtual ~TestHandlerAsync() {}
393
Roger Meier0a7c69c2014-05-02 21:15:45 +0200394 virtual void testVoid(tcxx::function<void()> cob) {
Roger Meier7e056e72011-07-17 07:28:28 +0000395 _delegate->testVoid();
396 cob();
397 }
398
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100399 virtual void testString(tcxx::function<void(std::string const& _return)> cob,
400 const std::string& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000401 std::string res;
402 _delegate->testString(res, thing);
403 cob(res);
404 }
405
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900406 virtual void testBool(tcxx::function<void(bool const& _return)> cob, const bool thing) {
407 bool res = _delegate->testBool(thing);
408 cob(res);
409 }
410
Roger Meier0a7c69c2014-05-02 21:15:45 +0200411 virtual void testByte(tcxx::function<void(int8_t const& _return)> cob, const int8_t thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000412 int8_t res = _delegate->testByte(thing);
413 cob(res);
414 }
415
Roger Meier0a7c69c2014-05-02 21:15:45 +0200416 virtual void testI32(tcxx::function<void(int32_t const& _return)> cob, const int32_t thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000417 int32_t res = _delegate->testI32(thing);
418 cob(res);
419 }
420
Roger Meier0a7c69c2014-05-02 21:15:45 +0200421 virtual void testI64(tcxx::function<void(int64_t const& _return)> cob, const int64_t thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000422 int64_t res = _delegate->testI64(thing);
423 cob(res);
424 }
425
Roger Meier0a7c69c2014-05-02 21:15:45 +0200426 virtual void testDouble(tcxx::function<void(double const& _return)> cob, const double thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000427 double res = _delegate->testDouble(thing);
428 cob(res);
429 }
430
Konrad Grochowski1f6e3802015-05-18 18:10:06 +0200431 virtual void testBinary(tcxx::function<void(std::string const& _return)> cob,
432 const std::string& thing) {
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100433 std::string res;
434 _delegate->testBinary(res, thing);
435 cob(res);
436 }
437
Roger Meier0a7c69c2014-05-02 21:15:45 +0200438 virtual void testStruct(tcxx::function<void(Xtruct const& _return)> cob, const Xtruct& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000439 Xtruct res;
440 _delegate->testStruct(res, thing);
441 cob(res);
442 }
443
Roger Meier0a7c69c2014-05-02 21:15:45 +0200444 virtual void testNest(tcxx::function<void(Xtruct2 const& _return)> cob, const Xtruct2& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000445 Xtruct2 res;
446 _delegate->testNest(res, thing);
447 cob(res);
448 }
449
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100450 virtual void testMap(tcxx::function<void(std::map<int32_t, int32_t> const& _return)> cob,
451 const std::map<int32_t, int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000452 std::map<int32_t, int32_t> res;
453 _delegate->testMap(res, thing);
454 cob(res);
455 }
456
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100457 virtual void testStringMap(
458 tcxx::function<void(std::map<std::string, std::string> const& _return)> cob,
459 const std::map<std::string, std::string>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000460 std::map<std::string, std::string> res;
461 _delegate->testStringMap(res, thing);
462 cob(res);
463 }
464
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100465 virtual void testSet(tcxx::function<void(std::set<int32_t> const& _return)> cob,
466 const std::set<int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000467 std::set<int32_t> res;
468 _delegate->testSet(res, thing);
469 cob(res);
470 }
471
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100472 virtual void testList(tcxx::function<void(std::vector<int32_t> const& _return)> cob,
473 const std::vector<int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000474 std::vector<int32_t> res;
475 _delegate->testList(res, thing);
476 cob(res);
477 }
478
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100479 virtual void testEnum(tcxx::function<void(Numberz::type const& _return)> cob,
480 const Numberz::type thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000481 Numberz::type res = _delegate->testEnum(thing);
482 cob(res);
483 }
484
Roger Meier0a7c69c2014-05-02 21:15:45 +0200485 virtual void testTypedef(tcxx::function<void(UserId const& _return)> cob, const UserId thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000486 UserId res = _delegate->testTypedef(thing);
487 cob(res);
488 }
489
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100490 virtual void testMapMap(
491 tcxx::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob,
492 const int32_t hello) {
Roger Meier7e056e72011-07-17 07:28:28 +0000493 std::map<int32_t, std::map<int32_t, int32_t> > res;
494 _delegate->testMapMap(res, hello);
495 cob(res);
496 }
497
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100498 virtual void testInsanity(
499 tcxx::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob,
500 const Insanity& argument) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500501 std::map<UserId, std::map<Numberz::type, Insanity> > res;
Roger Meier7e056e72011-07-17 07:28:28 +0000502 _delegate->testInsanity(res, argument);
503 cob(res);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100504 }
Roger Meier7e056e72011-07-17 07:28:28 +0000505
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100506 virtual void testMulti(tcxx::function<void(Xtruct const& _return)> cob,
507 const int8_t arg0,
508 const int32_t arg1,
509 const int64_t arg2,
510 const std::map<int16_t, std::string>& arg3,
511 const Numberz::type arg4,
512 const UserId arg5) {
Roger Meier7e056e72011-07-17 07:28:28 +0000513 Xtruct res;
514 _delegate->testMulti(res, arg0, arg1, arg2, arg3, arg4, arg5);
515 cob(res);
516 }
517
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100518 virtual void testException(
519 tcxx::function<void()> cob,
520 tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
521 const std::string& arg) {
Roger Meier7e056e72011-07-17 07:28:28 +0000522 try {
523 _delegate->testException(arg);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100524 } catch (const apache::thrift::TException& e) {
Roger Meier7e056e72011-07-17 07:28:28 +0000525 exn_cob(apache::thrift::TDelayedException::delayException(e));
526 return;
527 }
528 cob();
529 }
530
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100531 virtual void testMultiException(
532 tcxx::function<void(Xtruct const& _return)> cob,
533 tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
534 const std::string& arg0,
535 const std::string& arg1) {
Roger Meier7e056e72011-07-17 07:28:28 +0000536 Xtruct res;
537 try {
538 _delegate->testMultiException(res, arg0, arg1);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100539 } catch (const apache::thrift::TException& e) {
Roger Meier7e056e72011-07-17 07:28:28 +0000540 exn_cob(apache::thrift::TDelayedException::delayException(e));
541 return;
542 }
543 cob(res);
544 }
545
Roger Meier0a7c69c2014-05-02 21:15:45 +0200546 virtual void testOneway(tcxx::function<void()> cob, const int32_t secondsToSleep) {
Roger Meier7e056e72011-07-17 07:28:28 +0000547 _delegate->testOneway(secondsToSleep);
548 cob();
549 }
550
551protected:
Roger Meier611f90c2011-12-11 22:08:51 +0000552 boost::shared_ptr<TestHandler> _delegate;
Roger Meier7e056e72011-07-17 07:28:28 +0000553};
554
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100555int main(int argc, char** argv) {
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530556
557 string file_path = boost::filesystem::system_complete(argv[0]).string();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100558 string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530559
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100560#if _WIN32
Jake Farrell5d02b802014-01-07 21:42:01 -0500561 transport::TWinsockSingleton::create();
562#endif
Mark Sleee8540632006-05-30 09:24:40 +0000563 int port = 9090;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000564 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000565 string transport_type = "buffered";
566 string protocol_type = "binary";
567 string server_type = "simple";
568 string domain_socket = "";
569 size_t workers = 4;
Marc Slemko6be374b2006-08-04 03:16:25 +0000570
Jake Farrell5d02b802014-01-07 21:42:01 -0500571 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100572 desc.add_options()("help,h", "produce help message")(
573 "port",
574 boost::program_options::value<int>(&port)->default_value(port),
575 "Port number to listen")("domain-socket",
576 boost::program_options::value<string>(&domain_socket)
577 ->default_value(domain_socket),
578 "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)")(
579 "server-type",
580 boost::program_options::value<string>(&server_type)->default_value(server_type),
581 "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"")(
582 "transport",
583 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
584 "transport: buffered, framed, http")(
585 "protocol",
586 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
587 "protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")(
588 "processor-events",
589 "processor-events")("workers,n",
590 boost::program_options::value<size_t>(&workers)->default_value(workers),
591 "Number of thread pools workers. Only valid for thread-pool server type");
Marc Slemko6be374b2006-08-04 03:16:25 +0000592
Jake Farrell5d02b802014-01-07 21:42:01 -0500593 boost::program_options::variables_map vm;
594 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
595 boost::program_options::notify(vm);
Marc Slemko6be374b2006-08-04 03:16:25 +0000596
Roger Meierca142b02011-06-07 17:59:07 +0000597 if (vm.count("help")) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100598 cout << desc << "\n";
599 return 1;
Mark Sleee8540632006-05-30 09:24:40 +0000600 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500601
Marc Slemko6be374b2006-08-04 03:16:25 +0000602 try {
Roger Meierca142b02011-06-07 17:59:07 +0000603 if (!server_type.empty()) {
604 if (server_type == "simple") {
605 } else if (server_type == "thread-pool") {
606 } else if (server_type == "threaded") {
607 } else if (server_type == "nonblocking") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000608 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100609 throw invalid_argument("Unknown server type " + server_type);
Roger Meierca142b02011-06-07 17:59:07 +0000610 }
611 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500612
Roger Meierca142b02011-06-07 17:59:07 +0000613 if (!protocol_type.empty()) {
614 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100615 } else if (protocol_type == "compact") {
Roger Meierca142b02011-06-07 17:59:07 +0000616 } else if (protocol_type == "json") {
617 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100618 throw invalid_argument("Unknown protocol type " + protocol_type);
Marc Slemko6be374b2006-08-04 03:16:25 +0000619 }
620 }
621
Roger Meier284101c2014-03-11 21:20:35 +0100622 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000623 if (transport_type == "buffered") {
624 } else if (transport_type == "framed") {
625 } else if (transport_type == "http") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000626 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100627 throw invalid_argument("Unknown transport type " + transport_type);
Marc Slemko6be374b2006-08-04 03:16:25 +0000628 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000629 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000630
Bryan Duxbury833ae492010-09-27 17:26:02 +0000631 } catch (std::exception& e) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000632 cerr << e.what() << endl;
Roger Meierca142b02011-06-07 17:59:07 +0000633 cout << desc << "\n";
634 return 1;
Marc Slemko6be374b2006-08-04 03:16:25 +0000635 }
636
Roger Meierca142b02011-06-07 17:59:07 +0000637 if (vm.count("ssl")) {
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000638 ssl = true;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000639 }
640
Mark Sleee8540632006-05-30 09:24:40 +0000641 // Dispatcher
Roger Meier611f90c2011-12-11 22:08:51 +0000642 boost::shared_ptr<TProtocolFactory> protocolFactory;
Roger Meierca142b02011-06-07 17:59:07 +0000643 if (protocol_type == "json") {
Roger Meier611f90c2011-12-11 22:08:51 +0000644 boost::shared_ptr<TProtocolFactory> jsonProtocolFactory(new TJSONProtocolFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000645 protocolFactory = jsonProtocolFactory;
Roger Meier023192f2014-02-12 09:35:12 +0100646 } else if (protocol_type == "compact") {
647 boost::shared_ptr<TProtocolFactory> compactProtocolFactory(new TCompactProtocolFactory());
648 protocolFactory = compactProtocolFactory;
Roger Meierca142b02011-06-07 17:59:07 +0000649 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100650 boost::shared_ptr<TProtocolFactory> binaryProtocolFactory(
651 new TBinaryProtocolFactoryT<TBufferBase>());
Roger Meierca142b02011-06-07 17:59:07 +0000652 protocolFactory = binaryProtocolFactory;
653 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000654
Roger Meierca142b02011-06-07 17:59:07 +0000655 // Processor
Roger Meier611f90c2011-12-11 22:08:51 +0000656 boost::shared_ptr<TestHandler> testHandler(new TestHandler());
657 boost::shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
Jake Farrell5d02b802014-01-07 21:42:01 -0500658
Roger Meierca142b02011-06-07 17:59:07 +0000659 if (vm.count("processor-events")) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100660 testProcessor->setEventHandler(
661 boost::shared_ptr<TProcessorEventHandler>(new TestProcessorEventHandler()));
David Reissd7192062010-10-06 17:09:33 +0000662 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500663
Mark Sleee8540632006-05-30 09:24:40 +0000664 // Transport
Roger Meier611f90c2011-12-11 22:08:51 +0000665 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory;
666 boost::shared_ptr<TServerSocket> serverSocket;
Mark Sleee8540632006-05-30 09:24:40 +0000667
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000668 if (ssl) {
Roger Meier611f90c2011-12-11 22:08:51 +0000669 sslSocketFactory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530670 sslSocketFactory->loadCertificate((dir_path + "../keys/server.crt").c_str());
671 sslSocketFactory->loadPrivateKey((dir_path + "../keys/server.key").c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000672 sslSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Roger Meier611f90c2011-12-11 22:08:51 +0000673 serverSocket = boost::shared_ptr<TServerSocket>(new TSSLServerSocket(port, sslSocketFactory));
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000674 } else {
Roger Meierc94b2932014-02-22 20:07:33 +0100675 if (domain_socket != "") {
676 unlink(domain_socket.c_str());
677 serverSocket = boost::shared_ptr<TServerSocket>(new TServerSocket(domain_socket));
678 port = 0;
679 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000680 serverSocket = boost::shared_ptr<TServerSocket>(new TServerSocket(port));
Roger Meierc94b2932014-02-22 20:07:33 +0100681 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000682 }
Roger Meierca142b02011-06-07 17:59:07 +0000683
Mark Sleed788b2e2006-09-07 01:26:35 +0000684 // Factory
Roger Meier611f90c2011-12-11 22:08:51 +0000685 boost::shared_ptr<TTransportFactory> transportFactory;
Jake Farrell5d02b802014-01-07 21:42:01 -0500686
Roger Meier7e056e72011-07-17 07:28:28 +0000687 if (transport_type == "http" && server_type != "nonblocking") {
Jake Farrell5d02b802014-01-07 21:42:01 -0500688 boost::shared_ptr<TTransportFactory> httpTransportFactory(new THttpServerTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000689 transportFactory = httpTransportFactory;
690 } else if (transport_type == "framed") {
Jake Farrell5d02b802014-01-07 21:42:01 -0500691 boost::shared_ptr<TTransportFactory> framedTransportFactory(new TFramedTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000692 transportFactory = framedTransportFactory;
693 } else {
Jake Farrell5d02b802014-01-07 21:42:01 -0500694 boost::shared_ptr<TTransportFactory> bufferedTransportFactory(new TBufferedTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000695 transportFactory = bufferedTransportFactory;
696 }
Mark Sleed788b2e2006-09-07 01:26:35 +0000697
Roger Meierca142b02011-06-07 17:59:07 +0000698 // Server Info
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100699 cout << "Starting \"" << server_type << "\" server (" << transport_type << "/" << protocol_type
700 << ") listen on: " << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000701 if (port != 0) {
702 cout << port;
703 }
704 cout << endl;
Mark Sleee8540632006-05-30 09:24:40 +0000705
Roger Meierca142b02011-06-07 17:59:07 +0000706 // Server
Jake Farrell5d02b802014-01-07 21:42:01 -0500707 boost::shared_ptr<apache::thrift::server::TServer> server;
708
Roger Meierca142b02011-06-07 17:59:07 +0000709 if (server_type == "simple") {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100710 server.reset(new TSimpleServer(testProcessor, serverSocket, transportFactory, protocolFactory));
Roger Meierca142b02011-06-07 17:59:07 +0000711 } else if (server_type == "thread-pool") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000712
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100713 boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workers);
Marc Slemko6be374b2006-08-04 03:16:25 +0000714
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100715 boost::shared_ptr<PlatformThreadFactory> threadFactory
716 = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
Marc Slemko6be374b2006-08-04 03:16:25 +0000717
718 threadManager->threadFactory(threadFactory);
719
720 threadManager->start();
721
Jake Farrell5d02b802014-01-07 21:42:01 -0500722 server.reset(new TThreadPoolServer(testProcessor,
Roger Meierca142b02011-06-07 17:59:07 +0000723 serverSocket,
Mark Sleed788b2e2006-09-07 01:26:35 +0000724 transportFactory,
Mark Sleea3302652006-10-25 19:03:32 +0000725 protocolFactory,
Jake Farrell5d02b802014-01-07 21:42:01 -0500726 threadManager));
Roger Meierca142b02011-06-07 17:59:07 +0000727 } else if (server_type == "threaded") {
David Reiss0c90f6f2008-02-06 22:18:40 +0000728
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100729 server.reset(
730 new TThreadedServer(testProcessor, serverSocket, transportFactory, protocolFactory));
Roger Meierca142b02011-06-07 17:59:07 +0000731 } else if (server_type == "nonblocking") {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100732 if (transport_type == "http") {
Roger Meier611f90c2011-12-11 22:08:51 +0000733 boost::shared_ptr<TestHandlerAsync> testHandlerAsync(new TestHandlerAsync(testHandler));
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100734 boost::shared_ptr<TAsyncProcessor> testProcessorAsync(
735 new ThriftTestAsyncProcessor(testHandlerAsync));
736 boost::shared_ptr<TAsyncBufferProcessor> testBufferProcessor(
737 new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory));
Jake Farrell5d02b802014-01-07 21:42:01 -0500738
739 // not loading nonblockingServer into "server" because
740 // TEvhttpServer doesn't inherit from TServer, and doesn't
741 // provide a stop method.
Roger Meier7e056e72011-07-17 07:28:28 +0000742 TEvhttpServer nonblockingServer(testBufferProcessor, port);
743 nonblockingServer.serve();
Jake Farrell5d02b802014-01-07 21:42:01 -0500744 } else {
745 server.reset(new TNonblockingServer(testProcessor, port));
Roger Meier7e056e72011-07-17 07:28:28 +0000746 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000747 }
748
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100749 if (server.get() != NULL) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500750 apache::thrift::concurrency::PlatformThreadFactory factory;
751 factory.setDetached(false);
752 boost::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100753 boost::shared_ptr<apache::thrift::concurrency::Thread> thread
754 = factory.newThread(serverThreadRunner);
Jake Farrell5d02b802014-01-07 21:42:01 -0500755 thread->start();
756
Roger Meier284101c2014-03-11 21:20:35 +0100757 // HACK: cross language test suite is unable to handle cin properly
758 // that's why we stay in a endless loop here
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100759 while (1) {
760 }
Roger Meier284101c2014-03-11 21:20:35 +0100761 // FIXME: find another way to stop the server (e.g. a signal)
762 // cout<<"Press enter to stop the server."<<endl;
763 // cin.ignore(); //wait until a key is pressed
Jake Farrell5d02b802014-01-07 21:42:01 -0500764
765 server->stop();
766 thread->join();
767 server.reset();
768 }
769
Roger Meierca142b02011-06-07 17:59:07 +0000770 cout << "done." << endl;
Mark Sleee8540632006-05-30 09:24:40 +0000771 return 0;
772}