blob: 526cb0b6de427ad64905cfc0c34616744b695a4d [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
Mark Slee1921d202007-01-24 19:43:06 +000081 int8_t testByte(const int8_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000082 printf("testByte(%d)\n", (int)thing);
83 return thing;
84 }
85
Mark Slee1921d202007-01-24 19:43:06 +000086 int32_t testI32(const int32_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000087 printf("testI32(%d)\n", thing);
88 return thing;
89 }
90
Mark Slee1921d202007-01-24 19:43:06 +000091 int64_t testI64(const int64_t thing) {
Roger Meier0e814802014-01-17 21:07:58 +010092 printf("testI64(%" PRId64 ")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +000093 return thing;
94 }
95
Mark Slee1921d202007-01-24 19:43:06 +000096 double testDouble(const double thing) {
Roger Meiera8cef6e2011-07-17 18:55:59 +000097 printf("testDouble(%f)\n", thing);
Mark Sleec98d0502006-09-06 02:42:25 +000098 return thing;
99 }
100
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100101 void testBinary(std::string& _return, const std::string& thing) {
102 std::ostringstream hexstr;
103 hexstr << std::hex << thing;
104 printf("testBinary(%s)\n", hexstr.str().c_str());
105 _return = thing;
106 }
107
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100108 void testStruct(Xtruct& out, const Xtruct& thing) {
109 printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n",
110 thing.string_thing.c_str(),
111 (int)thing.byte_thing,
112 thing.i32_thing,
113 thing.i64_thing);
Mark Slee1921d202007-01-24 19:43:06 +0000114 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000115 }
116
Mark Slee1921d202007-01-24 19:43:06 +0000117 void testNest(Xtruct2& out, const Xtruct2& nest) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100118 const Xtruct& thing = nest.struct_thing;
119 printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n",
120 (int)nest.byte_thing,
121 thing.string_thing.c_str(),
122 (int)thing.byte_thing,
123 thing.i32_thing,
124 thing.i64_thing,
125 nest.i32_thing);
Mark Slee1921d202007-01-24 19:43:06 +0000126 out = nest;
Mark Sleee8540632006-05-30 09:24:40 +0000127 }
128
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100129 void testMap(map<int32_t, int32_t>& out, const map<int32_t, int32_t>& thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000130 printf("testMap({");
131 map<int32_t, int32_t>::const_iterator m_iter;
132 bool first = true;
133 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
134 if (first) {
135 first = false;
136 } else {
137 printf(", ");
138 }
139 printf("%d => %d", m_iter->first, m_iter->second);
140 }
141 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000142 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000143 }
144
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100145 void testStringMap(map<std::string, std::string>& out,
146 const map<std::string, std::string>& thing) {
Roger Meierd3b9dca2011-06-24 14:01:10 +0000147 printf("testMap({");
148 map<std::string, std::string>::const_iterator m_iter;
149 bool first = true;
150 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
151 if (first) {
152 first = false;
153 } else {
154 printf(", ");
155 }
156 printf("%s => %s", (m_iter->first).c_str(), (m_iter->second).c_str());
157 }
158 printf("})\n");
159 out = thing;
160 }
161
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100162 void testSet(set<int32_t>& out, const set<int32_t>& thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000163 printf("testSet({");
164 set<int32_t>::const_iterator s_iter;
165 bool first = true;
166 for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) {
167 if (first) {
168 first = false;
169 } else {
170 printf(", ");
171 }
172 printf("%d", *s_iter);
173 }
174 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000175 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000176 }
177
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100178 void testList(vector<int32_t>& out, const vector<int32_t>& thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000179 printf("testList({");
Mark Sleeb9acf982006-10-10 01:57:32 +0000180 vector<int32_t>::const_iterator l_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000181 bool first = true;
182 for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) {
183 if (first) {
184 first = false;
185 } else {
186 printf(", ");
187 }
188 printf("%d", *l_iter);
189 }
190 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000191 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000192 }
193
Bryan Duxbury833ae492010-09-27 17:26:02 +0000194 Numberz::type testEnum(const Numberz::type thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000195 printf("testEnum(%d)\n", thing);
196 return thing;
197 }
198
Mark Slee1921d202007-01-24 19:43:06 +0000199 UserId testTypedef(const UserId thing) {
Roger Meier0e814802014-01-17 21:07:58 +0100200 printf("testTypedef(%" PRId64 ")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +0000201 return thing;
202 }
203
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100204 void testMapMap(map<int32_t, map<int32_t, int32_t> >& mapmap, const int32_t hello) {
Mark Sleee8540632006-05-30 09:24:40 +0000205 printf("testMapMap(%d)\n", hello);
Mark Sleee8540632006-05-30 09:24:40 +0000206
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100207 map<int32_t, int32_t> pos;
208 map<int32_t, int32_t> neg;
Mark Sleee8540632006-05-30 09:24:40 +0000209 for (int i = 1; i < 5; i++) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100210 pos.insert(make_pair(i, i));
211 neg.insert(make_pair(-i, -i));
Mark Sleee8540632006-05-30 09:24:40 +0000212 }
213
214 mapmap.insert(make_pair(4, pos));
215 mapmap.insert(make_pair(-4, neg));
Mark Sleee8540632006-05-30 09:24:40 +0000216 }
217
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100218 void testInsanity(map<UserId, map<Numberz::type, Insanity> >& insane, const Insanity& argument) {
219 (void)argument;
Mark Sleee8540632006-05-30 09:24:40 +0000220 printf("testInsanity()\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000221
Mark Sleee8540632006-05-30 09:24:40 +0000222 Xtruct hello;
223 hello.string_thing = "Hello2";
224 hello.byte_thing = 2;
Mark Sleee8540632006-05-30 09:24:40 +0000225 hello.i32_thing = 2;
Mark Sleee8540632006-05-30 09:24:40 +0000226 hello.i64_thing = 2;
227
228 Xtruct goodbye;
229 goodbye.string_thing = "Goodbye4";
230 goodbye.byte_thing = 4;
Mark Sleee8540632006-05-30 09:24:40 +0000231 goodbye.i32_thing = 4;
Mark Sleee8540632006-05-30 09:24:40 +0000232 goodbye.i64_thing = 4;
233
234 Insanity crazy;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000235 crazy.userMap.insert(make_pair(Numberz::EIGHT, 8));
Mark Sleee8540632006-05-30 09:24:40 +0000236 crazy.xtructs.push_back(goodbye);
237
238 Insanity looney;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000239 crazy.userMap.insert(make_pair(Numberz::FIVE, 5));
Mark Sleee8540632006-05-30 09:24:40 +0000240 crazy.xtructs.push_back(hello);
241
Bryan Duxbury833ae492010-09-27 17:26:02 +0000242 map<Numberz::type, Insanity> first_map;
243 map<Numberz::type, Insanity> second_map;
Mark Sleee8540632006-05-30 09:24:40 +0000244
Bryan Duxbury833ae492010-09-27 17:26:02 +0000245 first_map.insert(make_pair(Numberz::TWO, crazy));
246 first_map.insert(make_pair(Numberz::THREE, crazy));
Mark Sleee8540632006-05-30 09:24:40 +0000247
Bryan Duxbury833ae492010-09-27 17:26:02 +0000248 second_map.insert(make_pair(Numberz::SIX, looney));
Mark Sleee8540632006-05-30 09:24:40 +0000249
Mark Sleee8540632006-05-30 09:24:40 +0000250 insane.insert(make_pair(1, first_map));
251 insane.insert(make_pair(2, second_map));
252
253 printf("return");
254 printf(" = {");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100255 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000256 for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
Roger Meier0e814802014-01-17 21:07:58 +0100257 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100258 map<Numberz::type, Insanity>::const_iterator i2_iter;
259 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Mark Sleee8540632006-05-30 09:24:40 +0000260 printf("%d => {", i2_iter->first);
Bryan Duxbury833ae492010-09-27 17:26:02 +0000261 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
262 map<Numberz::type, UserId>::const_iterator um;
Mark Sleee8540632006-05-30 09:24:40 +0000263 printf("{");
264 for (um = userMap.begin(); um != userMap.end(); ++um) {
Roger Meier0e814802014-01-17 21:07:58 +0100265 printf("%d => %" PRId64 ", ", um->first, um->second);
Mark Sleee8540632006-05-30 09:24:40 +0000266 }
267 printf("}, ");
268
Mark Sleeb9acf982006-10-10 01:57:32 +0000269 vector<Xtruct> xtructs = i2_iter->second.xtructs;
270 vector<Xtruct>::const_iterator x;
Mark Sleee8540632006-05-30 09:24:40 +0000271 printf("{");
272 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100273 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
274 x->string_thing.c_str(),
275 (int)x->byte_thing,
276 x->i32_thing,
277 x->i64_thing);
Mark Sleee8540632006-05-30 09:24:40 +0000278 }
279 printf("}");
280
281 printf("}, ");
282 }
283 printf("}, ");
284 }
285 printf("}\n");
Mark Sleee8540632006-05-30 09:24:40 +0000286 }
Marc Slemkoe6889de2006-08-12 00:32:53 +0000287
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100288 void testMulti(Xtruct& hello,
289 const int8_t arg0,
290 const int32_t arg1,
291 const int64_t arg2,
292 const std::map<int16_t, std::string>& arg3,
293 const Numberz::type arg4,
294 const UserId arg5) {
295 (void)arg3;
296 (void)arg4;
297 (void)arg5;
Jake Farrell5d02b802014-01-07 21:42:01 -0500298
Marc Slemkoe6889de2006-08-12 00:32:53 +0000299 printf("testMulti()\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000300
Marc Slemkoe6889de2006-08-12 00:32:53 +0000301 hello.string_thing = "Hello2";
302 hello.byte_thing = arg0;
303 hello.i32_thing = arg1;
304 hello.i64_thing = (int64_t)arg2;
Marc Slemkoe6889de2006-08-12 00:32:53 +0000305 }
Marc Slemkobf4fd192006-08-15 21:29:39 +0000306
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100307 void testException(const std::string& arg) throw(Xception, apache::thrift::TException) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000308 printf("testException(%s)\n", arg.c_str());
Mark Sleed3d733a2006-09-01 22:19:06 +0000309 if (arg.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000310 Xception e;
311 e.errorCode = 1001;
David Reiss9813cbe2009-01-31 21:39:11 +0000312 e.message = arg;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000313 throw e;
Roger Meier1f8b48f2012-05-02 22:56:47 +0000314 } else if (arg.compare("TException") == 0) {
T Jake Lucianib5e62212009-01-31 22:36:20 +0000315 apache::thrift::TException e;
David Reiss55ff70f2008-06-11 00:58:25 +0000316 throw e;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000317 } else {
318 Xtruct result;
319 result.string_thing = arg;
320 return;
321 }
322 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000323
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100324 void testMultiException(Xtruct& result,
325 const std::string& arg0,
326 const std::string& arg1) throw(Xception, Xception2) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000327
Marc Slemko71d4e472006-08-15 22:34:04 +0000328 printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000329
Mark Sleef5f2be42006-09-05 21:05:31 +0000330 if (arg0.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000331 Xception e;
332 e.errorCode = 1001;
333 e.message = "This is an Xception";
334 throw e;
Mark Sleef5f2be42006-09-05 21:05:31 +0000335 } else if (arg0.compare("Xception2") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000336 Xception2 e;
337 e.errorCode = 2002;
338 e.struct_thing.string_thing = "This is an Xception2";
339 throw e;
340 } else {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000341 result.string_thing = arg1;
Mark Slee1921d202007-01-24 19:43:06 +0000342 return;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000343 }
344 }
David Reiss2ab6fe82008-02-18 02:11:44 +0000345
Jake Farrell5d02b802014-01-07 21:42:01 -0500346 void testOneway(const int32_t sleepFor) {
David Reiss6ce401d2009-03-24 20:01:58 +0000347 printf("testOneway(%d): Sleeping...\n", sleepFor);
Jake Farrell5d02b802014-01-07 21:42:01 -0500348 THRIFT_SLEEP_SEC(sleepFor);
David Reiss6ce401d2009-03-24 20:01:58 +0000349 printf("testOneway(%d): done sleeping!\n", sleepFor);
David Reiss2ab6fe82008-02-18 02:11:44 +0000350 }
Mark Sleee8540632006-05-30 09:24:40 +0000351};
352
David Reissd7192062010-10-06 17:09:33 +0000353class TestProcessorEventHandler : public TProcessorEventHandler {
David Reiss23248712010-10-06 17:10:08 +0000354 virtual void* getContext(const char* fn_name, void* serverContext) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100355 (void)serverContext;
David Reissd7192062010-10-06 17:09:33 +0000356 return new std::string(fn_name);
357 }
358 virtual void freeContext(void* ctx, const char* fn_name) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100359 (void)fn_name;
David Reissd7192062010-10-06 17:09:33 +0000360 delete static_cast<std::string*>(ctx);
361 }
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100362 virtual void preRead(void* ctx, const char* fn_name) { communicate("preRead", ctx, fn_name); }
David Reissef7200f2010-10-06 17:09:42 +0000363 virtual void postRead(void* ctx, const char* fn_name, uint32_t bytes) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100364 (void)bytes;
David Reissd7192062010-10-06 17:09:33 +0000365 communicate("postRead", ctx, fn_name);
366 }
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100367 virtual void preWrite(void* ctx, const char* fn_name) { communicate("preWrite", ctx, fn_name); }
David Reissef7200f2010-10-06 17:09:42 +0000368 virtual void postWrite(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("postWrite", ctx, fn_name);
371 }
372 virtual void asyncComplete(void* ctx, const char* fn_name) {
373 communicate("asyncComplete", ctx, fn_name);
374 }
375 virtual void handlerError(void* ctx, const char* fn_name) {
376 communicate("handlerError", ctx, fn_name);
377 }
378
379 void communicate(const char* event, void* ctx, const char* fn_name) {
380 std::cout << event << ": " << *static_cast<std::string*>(ctx) << " = " << fn_name << std::endl;
381 }
382};
383
Roger Meier7e056e72011-07-17 07:28:28 +0000384class TestHandlerAsync : public ThriftTestCobSvIf {
385public:
Roger Meier611f90c2011-12-11 22:08:51 +0000386 TestHandlerAsync(boost::shared_ptr<TestHandler>& handler) : _delegate(handler) {}
Roger Meier7e056e72011-07-17 07:28:28 +0000387 virtual ~TestHandlerAsync() {}
388
Roger Meier0a7c69c2014-05-02 21:15:45 +0200389 virtual void testVoid(tcxx::function<void()> cob) {
Roger Meier7e056e72011-07-17 07:28:28 +0000390 _delegate->testVoid();
391 cob();
392 }
393
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100394 virtual void testString(tcxx::function<void(std::string const& _return)> cob,
395 const std::string& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000396 std::string res;
397 _delegate->testString(res, thing);
398 cob(res);
399 }
400
Roger Meier0a7c69c2014-05-02 21:15:45 +0200401 virtual void testByte(tcxx::function<void(int8_t const& _return)> cob, const int8_t thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000402 int8_t res = _delegate->testByte(thing);
403 cob(res);
404 }
405
Roger Meier0a7c69c2014-05-02 21:15:45 +0200406 virtual void testI32(tcxx::function<void(int32_t const& _return)> cob, const int32_t thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000407 int32_t res = _delegate->testI32(thing);
408 cob(res);
409 }
410
Roger Meier0a7c69c2014-05-02 21:15:45 +0200411 virtual void testI64(tcxx::function<void(int64_t const& _return)> cob, const int64_t thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000412 int64_t res = _delegate->testI64(thing);
413 cob(res);
414 }
415
Roger Meier0a7c69c2014-05-02 21:15:45 +0200416 virtual void testDouble(tcxx::function<void(double const& _return)> cob, const double thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000417 double res = _delegate->testDouble(thing);
418 cob(res);
419 }
420
Konrad Grochowski1f6e3802015-05-18 18:10:06 +0200421 virtual void testBinary(tcxx::function<void(std::string const& _return)> cob,
422 const std::string& thing) {
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100423 std::string res;
424 _delegate->testBinary(res, thing);
425 cob(res);
426 }
427
Roger Meier0a7c69c2014-05-02 21:15:45 +0200428 virtual void testStruct(tcxx::function<void(Xtruct const& _return)> cob, const Xtruct& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000429 Xtruct res;
430 _delegate->testStruct(res, thing);
431 cob(res);
432 }
433
Roger Meier0a7c69c2014-05-02 21:15:45 +0200434 virtual void testNest(tcxx::function<void(Xtruct2 const& _return)> cob, const Xtruct2& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000435 Xtruct2 res;
436 _delegate->testNest(res, thing);
437 cob(res);
438 }
439
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100440 virtual void testMap(tcxx::function<void(std::map<int32_t, int32_t> const& _return)> cob,
441 const std::map<int32_t, int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000442 std::map<int32_t, int32_t> res;
443 _delegate->testMap(res, thing);
444 cob(res);
445 }
446
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100447 virtual void testStringMap(
448 tcxx::function<void(std::map<std::string, std::string> const& _return)> cob,
449 const std::map<std::string, std::string>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000450 std::map<std::string, std::string> res;
451 _delegate->testStringMap(res, thing);
452 cob(res);
453 }
454
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100455 virtual void testSet(tcxx::function<void(std::set<int32_t> const& _return)> cob,
456 const std::set<int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000457 std::set<int32_t> res;
458 _delegate->testSet(res, thing);
459 cob(res);
460 }
461
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100462 virtual void testList(tcxx::function<void(std::vector<int32_t> const& _return)> cob,
463 const std::vector<int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000464 std::vector<int32_t> res;
465 _delegate->testList(res, thing);
466 cob(res);
467 }
468
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100469 virtual void testEnum(tcxx::function<void(Numberz::type const& _return)> cob,
470 const Numberz::type thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000471 Numberz::type res = _delegate->testEnum(thing);
472 cob(res);
473 }
474
Roger Meier0a7c69c2014-05-02 21:15:45 +0200475 virtual void testTypedef(tcxx::function<void(UserId const& _return)> cob, const UserId thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000476 UserId res = _delegate->testTypedef(thing);
477 cob(res);
478 }
479
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100480 virtual void testMapMap(
481 tcxx::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob,
482 const int32_t hello) {
Roger Meier7e056e72011-07-17 07:28:28 +0000483 std::map<int32_t, std::map<int32_t, int32_t> > res;
484 _delegate->testMapMap(res, hello);
485 cob(res);
486 }
487
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100488 virtual void testInsanity(
489 tcxx::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob,
490 const Insanity& argument) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500491 std::map<UserId, std::map<Numberz::type, Insanity> > res;
Roger Meier7e056e72011-07-17 07:28:28 +0000492 _delegate->testInsanity(res, argument);
493 cob(res);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100494 }
Roger Meier7e056e72011-07-17 07:28:28 +0000495
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100496 virtual void testMulti(tcxx::function<void(Xtruct const& _return)> cob,
497 const int8_t arg0,
498 const int32_t arg1,
499 const int64_t arg2,
500 const std::map<int16_t, std::string>& arg3,
501 const Numberz::type arg4,
502 const UserId arg5) {
Roger Meier7e056e72011-07-17 07:28:28 +0000503 Xtruct res;
504 _delegate->testMulti(res, arg0, arg1, arg2, arg3, arg4, arg5);
505 cob(res);
506 }
507
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100508 virtual void testException(
509 tcxx::function<void()> cob,
510 tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
511 const std::string& arg) {
Roger Meier7e056e72011-07-17 07:28:28 +0000512 try {
513 _delegate->testException(arg);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100514 } catch (const apache::thrift::TException& e) {
Roger Meier7e056e72011-07-17 07:28:28 +0000515 exn_cob(apache::thrift::TDelayedException::delayException(e));
516 return;
517 }
518 cob();
519 }
520
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100521 virtual void testMultiException(
522 tcxx::function<void(Xtruct const& _return)> cob,
523 tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
524 const std::string& arg0,
525 const std::string& arg1) {
Roger Meier7e056e72011-07-17 07:28:28 +0000526 Xtruct res;
527 try {
528 _delegate->testMultiException(res, arg0, arg1);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100529 } catch (const apache::thrift::TException& e) {
Roger Meier7e056e72011-07-17 07:28:28 +0000530 exn_cob(apache::thrift::TDelayedException::delayException(e));
531 return;
532 }
533 cob(res);
534 }
535
Roger Meier0a7c69c2014-05-02 21:15:45 +0200536 virtual void testOneway(tcxx::function<void()> cob, const int32_t secondsToSleep) {
Roger Meier7e056e72011-07-17 07:28:28 +0000537 _delegate->testOneway(secondsToSleep);
538 cob();
539 }
540
541protected:
Roger Meier611f90c2011-12-11 22:08:51 +0000542 boost::shared_ptr<TestHandler> _delegate;
Roger Meier7e056e72011-07-17 07:28:28 +0000543};
544
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100545int main(int argc, char** argv) {
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530546
547 string file_path = boost::filesystem::system_complete(argv[0]).string();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100548 string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530549
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100550#if _WIN32
Jake Farrell5d02b802014-01-07 21:42:01 -0500551 transport::TWinsockSingleton::create();
552#endif
Mark Sleee8540632006-05-30 09:24:40 +0000553 int port = 9090;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000554 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000555 string transport_type = "buffered";
556 string protocol_type = "binary";
557 string server_type = "simple";
558 string domain_socket = "";
559 size_t workers = 4;
Marc Slemko6be374b2006-08-04 03:16:25 +0000560
Jake Farrell5d02b802014-01-07 21:42:01 -0500561 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100562 desc.add_options()("help,h", "produce help message")(
563 "port",
564 boost::program_options::value<int>(&port)->default_value(port),
565 "Port number to listen")("domain-socket",
566 boost::program_options::value<string>(&domain_socket)
567 ->default_value(domain_socket),
568 "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)")(
569 "server-type",
570 boost::program_options::value<string>(&server_type)->default_value(server_type),
571 "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"")(
572 "transport",
573 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
574 "transport: buffered, framed, http")(
575 "protocol",
576 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
577 "protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")(
578 "processor-events",
579 "processor-events")("workers,n",
580 boost::program_options::value<size_t>(&workers)->default_value(workers),
581 "Number of thread pools workers. Only valid for thread-pool server type");
Marc Slemko6be374b2006-08-04 03:16:25 +0000582
Jake Farrell5d02b802014-01-07 21:42:01 -0500583 boost::program_options::variables_map vm;
584 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
585 boost::program_options::notify(vm);
Marc Slemko6be374b2006-08-04 03:16:25 +0000586
Roger Meierca142b02011-06-07 17:59:07 +0000587 if (vm.count("help")) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100588 cout << desc << "\n";
589 return 1;
Mark Sleee8540632006-05-30 09:24:40 +0000590 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500591
Marc Slemko6be374b2006-08-04 03:16:25 +0000592 try {
Roger Meierca142b02011-06-07 17:59:07 +0000593 if (!server_type.empty()) {
594 if (server_type == "simple") {
595 } else if (server_type == "thread-pool") {
596 } else if (server_type == "threaded") {
597 } else if (server_type == "nonblocking") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000598 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100599 throw invalid_argument("Unknown server type " + server_type);
Roger Meierca142b02011-06-07 17:59:07 +0000600 }
601 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500602
Roger Meierca142b02011-06-07 17:59:07 +0000603 if (!protocol_type.empty()) {
604 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100605 } else if (protocol_type == "compact") {
Roger Meierca142b02011-06-07 17:59:07 +0000606 } else if (protocol_type == "json") {
607 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100608 throw invalid_argument("Unknown protocol type " + protocol_type);
Marc Slemko6be374b2006-08-04 03:16:25 +0000609 }
610 }
611
Roger Meier284101c2014-03-11 21:20:35 +0100612 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000613 if (transport_type == "buffered") {
614 } else if (transport_type == "framed") {
615 } else if (transport_type == "http") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000616 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100617 throw invalid_argument("Unknown transport type " + transport_type);
Marc Slemko6be374b2006-08-04 03:16:25 +0000618 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000619 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000620
Bryan Duxbury833ae492010-09-27 17:26:02 +0000621 } catch (std::exception& e) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000622 cerr << e.what() << endl;
Roger Meierca142b02011-06-07 17:59:07 +0000623 cout << desc << "\n";
624 return 1;
Marc Slemko6be374b2006-08-04 03:16:25 +0000625 }
626
Roger Meierca142b02011-06-07 17:59:07 +0000627 if (vm.count("ssl")) {
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000628 ssl = true;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000629 }
630
Mark Sleee8540632006-05-30 09:24:40 +0000631 // Dispatcher
Roger Meier611f90c2011-12-11 22:08:51 +0000632 boost::shared_ptr<TProtocolFactory> protocolFactory;
Roger Meierca142b02011-06-07 17:59:07 +0000633 if (protocol_type == "json") {
Roger Meier611f90c2011-12-11 22:08:51 +0000634 boost::shared_ptr<TProtocolFactory> jsonProtocolFactory(new TJSONProtocolFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000635 protocolFactory = jsonProtocolFactory;
Roger Meier023192f2014-02-12 09:35:12 +0100636 } else if (protocol_type == "compact") {
637 boost::shared_ptr<TProtocolFactory> compactProtocolFactory(new TCompactProtocolFactory());
638 protocolFactory = compactProtocolFactory;
Roger Meierca142b02011-06-07 17:59:07 +0000639 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100640 boost::shared_ptr<TProtocolFactory> binaryProtocolFactory(
641 new TBinaryProtocolFactoryT<TBufferBase>());
Roger Meierca142b02011-06-07 17:59:07 +0000642 protocolFactory = binaryProtocolFactory;
643 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000644
Roger Meierca142b02011-06-07 17:59:07 +0000645 // Processor
Roger Meier611f90c2011-12-11 22:08:51 +0000646 boost::shared_ptr<TestHandler> testHandler(new TestHandler());
647 boost::shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
Jake Farrell5d02b802014-01-07 21:42:01 -0500648
Roger Meierca142b02011-06-07 17:59:07 +0000649 if (vm.count("processor-events")) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100650 testProcessor->setEventHandler(
651 boost::shared_ptr<TProcessorEventHandler>(new TestProcessorEventHandler()));
David Reissd7192062010-10-06 17:09:33 +0000652 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500653
Mark Sleee8540632006-05-30 09:24:40 +0000654 // Transport
Roger Meier611f90c2011-12-11 22:08:51 +0000655 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory;
656 boost::shared_ptr<TServerSocket> serverSocket;
Mark Sleee8540632006-05-30 09:24:40 +0000657
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000658 if (ssl) {
Roger Meier611f90c2011-12-11 22:08:51 +0000659 sslSocketFactory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530660 sslSocketFactory->loadCertificate((dir_path + "../keys/server.crt").c_str());
661 sslSocketFactory->loadPrivateKey((dir_path + "../keys/server.key").c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000662 sslSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Roger Meier611f90c2011-12-11 22:08:51 +0000663 serverSocket = boost::shared_ptr<TServerSocket>(new TSSLServerSocket(port, sslSocketFactory));
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000664 } else {
Roger Meierc94b2932014-02-22 20:07:33 +0100665 if (domain_socket != "") {
666 unlink(domain_socket.c_str());
667 serverSocket = boost::shared_ptr<TServerSocket>(new TServerSocket(domain_socket));
668 port = 0;
669 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000670 serverSocket = boost::shared_ptr<TServerSocket>(new TServerSocket(port));
Roger Meierc94b2932014-02-22 20:07:33 +0100671 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000672 }
Roger Meierca142b02011-06-07 17:59:07 +0000673
Mark Sleed788b2e2006-09-07 01:26:35 +0000674 // Factory
Roger Meier611f90c2011-12-11 22:08:51 +0000675 boost::shared_ptr<TTransportFactory> transportFactory;
Jake Farrell5d02b802014-01-07 21:42:01 -0500676
Roger Meier7e056e72011-07-17 07:28:28 +0000677 if (transport_type == "http" && server_type != "nonblocking") {
Jake Farrell5d02b802014-01-07 21:42:01 -0500678 boost::shared_ptr<TTransportFactory> httpTransportFactory(new THttpServerTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000679 transportFactory = httpTransportFactory;
680 } else if (transport_type == "framed") {
Jake Farrell5d02b802014-01-07 21:42:01 -0500681 boost::shared_ptr<TTransportFactory> framedTransportFactory(new TFramedTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000682 transportFactory = framedTransportFactory;
683 } else {
Jake Farrell5d02b802014-01-07 21:42:01 -0500684 boost::shared_ptr<TTransportFactory> bufferedTransportFactory(new TBufferedTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000685 transportFactory = bufferedTransportFactory;
686 }
Mark Sleed788b2e2006-09-07 01:26:35 +0000687
Roger Meierca142b02011-06-07 17:59:07 +0000688 // Server Info
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100689 cout << "Starting \"" << server_type << "\" server (" << transport_type << "/" << protocol_type
690 << ") listen on: " << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000691 if (port != 0) {
692 cout << port;
693 }
694 cout << endl;
Mark Sleee8540632006-05-30 09:24:40 +0000695
Roger Meierca142b02011-06-07 17:59:07 +0000696 // Server
Jake Farrell5d02b802014-01-07 21:42:01 -0500697 boost::shared_ptr<apache::thrift::server::TServer> server;
698
Roger Meierca142b02011-06-07 17:59:07 +0000699 if (server_type == "simple") {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100700 server.reset(new TSimpleServer(testProcessor, serverSocket, transportFactory, protocolFactory));
Roger Meierca142b02011-06-07 17:59:07 +0000701 } else if (server_type == "thread-pool") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000702
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100703 boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workers);
Marc Slemko6be374b2006-08-04 03:16:25 +0000704
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100705 boost::shared_ptr<PlatformThreadFactory> threadFactory
706 = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
Marc Slemko6be374b2006-08-04 03:16:25 +0000707
708 threadManager->threadFactory(threadFactory);
709
710 threadManager->start();
711
Jake Farrell5d02b802014-01-07 21:42:01 -0500712 server.reset(new TThreadPoolServer(testProcessor,
Roger Meierca142b02011-06-07 17:59:07 +0000713 serverSocket,
Mark Sleed788b2e2006-09-07 01:26:35 +0000714 transportFactory,
Mark Sleea3302652006-10-25 19:03:32 +0000715 protocolFactory,
Jake Farrell5d02b802014-01-07 21:42:01 -0500716 threadManager));
Roger Meierca142b02011-06-07 17:59:07 +0000717 } else if (server_type == "threaded") {
David Reiss0c90f6f2008-02-06 22:18:40 +0000718
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100719 server.reset(
720 new TThreadedServer(testProcessor, serverSocket, transportFactory, protocolFactory));
Roger Meierca142b02011-06-07 17:59:07 +0000721 } else if (server_type == "nonblocking") {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100722 if (transport_type == "http") {
Roger Meier611f90c2011-12-11 22:08:51 +0000723 boost::shared_ptr<TestHandlerAsync> testHandlerAsync(new TestHandlerAsync(testHandler));
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100724 boost::shared_ptr<TAsyncProcessor> testProcessorAsync(
725 new ThriftTestAsyncProcessor(testHandlerAsync));
726 boost::shared_ptr<TAsyncBufferProcessor> testBufferProcessor(
727 new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory));
Jake Farrell5d02b802014-01-07 21:42:01 -0500728
729 // not loading nonblockingServer into "server" because
730 // TEvhttpServer doesn't inherit from TServer, and doesn't
731 // provide a stop method.
Roger Meier7e056e72011-07-17 07:28:28 +0000732 TEvhttpServer nonblockingServer(testBufferProcessor, port);
733 nonblockingServer.serve();
Jake Farrell5d02b802014-01-07 21:42:01 -0500734 } else {
735 server.reset(new TNonblockingServer(testProcessor, port));
Roger Meier7e056e72011-07-17 07:28:28 +0000736 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000737 }
738
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100739 if (server.get() != NULL) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500740 apache::thrift::concurrency::PlatformThreadFactory factory;
741 factory.setDetached(false);
742 boost::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100743 boost::shared_ptr<apache::thrift::concurrency::Thread> thread
744 = factory.newThread(serverThreadRunner);
Jake Farrell5d02b802014-01-07 21:42:01 -0500745 thread->start();
746
Roger Meier284101c2014-03-11 21:20:35 +0100747 // HACK: cross language test suite is unable to handle cin properly
748 // that's why we stay in a endless loop here
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100749 while (1) {
750 }
Roger Meier284101c2014-03-11 21:20:35 +0100751 // FIXME: find another way to stop the server (e.g. a signal)
752 // cout<<"Press enter to stop the server."<<endl;
753 // cin.ignore(); //wait until a key is pressed
Jake Farrell5d02b802014-01-07 21:42:01 -0500754
755 server->stop();
756 thread->join();
757 server.reset();
758 }
759
Roger Meierca142b02011-06-07 17:59:07 +0000760 cout << "done." << endl;
Mark Sleee8540632006-05-30 09:24:40 +0000761 return 0;
762}