blob: 270506436ede3f56bc4bb44ac16f57e9bf514977 [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
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100421 virtual void testBinary(tcxx::function<void(std::string const& _return)> cob, const std::string& thing) {
422 std::string res;
423 _delegate->testBinary(res, thing);
424 cob(res);
425 }
426
Roger Meier0a7c69c2014-05-02 21:15:45 +0200427 virtual void testStruct(tcxx::function<void(Xtruct const& _return)> cob, const Xtruct& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000428 Xtruct res;
429 _delegate->testStruct(res, thing);
430 cob(res);
431 }
432
Roger Meier0a7c69c2014-05-02 21:15:45 +0200433 virtual void testNest(tcxx::function<void(Xtruct2 const& _return)> cob, const Xtruct2& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000434 Xtruct2 res;
435 _delegate->testNest(res, thing);
436 cob(res);
437 }
438
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100439 virtual void testMap(tcxx::function<void(std::map<int32_t, int32_t> const& _return)> cob,
440 const std::map<int32_t, int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000441 std::map<int32_t, int32_t> res;
442 _delegate->testMap(res, thing);
443 cob(res);
444 }
445
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100446 virtual void testStringMap(
447 tcxx::function<void(std::map<std::string, std::string> const& _return)> cob,
448 const std::map<std::string, std::string>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000449 std::map<std::string, std::string> res;
450 _delegate->testStringMap(res, thing);
451 cob(res);
452 }
453
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100454 virtual void testSet(tcxx::function<void(std::set<int32_t> const& _return)> cob,
455 const std::set<int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000456 std::set<int32_t> res;
457 _delegate->testSet(res, thing);
458 cob(res);
459 }
460
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100461 virtual void testList(tcxx::function<void(std::vector<int32_t> const& _return)> cob,
462 const std::vector<int32_t>& thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000463 std::vector<int32_t> res;
464 _delegate->testList(res, thing);
465 cob(res);
466 }
467
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100468 virtual void testEnum(tcxx::function<void(Numberz::type const& _return)> cob,
469 const Numberz::type thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000470 Numberz::type res = _delegate->testEnum(thing);
471 cob(res);
472 }
473
Roger Meier0a7c69c2014-05-02 21:15:45 +0200474 virtual void testTypedef(tcxx::function<void(UserId const& _return)> cob, const UserId thing) {
Roger Meier7e056e72011-07-17 07:28:28 +0000475 UserId res = _delegate->testTypedef(thing);
476 cob(res);
477 }
478
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100479 virtual void testMapMap(
480 tcxx::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob,
481 const int32_t hello) {
Roger Meier7e056e72011-07-17 07:28:28 +0000482 std::map<int32_t, std::map<int32_t, int32_t> > res;
483 _delegate->testMapMap(res, hello);
484 cob(res);
485 }
486
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100487 virtual void testInsanity(
488 tcxx::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob,
489 const Insanity& argument) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500490 std::map<UserId, std::map<Numberz::type, Insanity> > res;
Roger Meier7e056e72011-07-17 07:28:28 +0000491 _delegate->testInsanity(res, argument);
492 cob(res);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100493 }
Roger Meier7e056e72011-07-17 07:28:28 +0000494
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100495 virtual void testMulti(tcxx::function<void(Xtruct const& _return)> cob,
496 const int8_t arg0,
497 const int32_t arg1,
498 const int64_t arg2,
499 const std::map<int16_t, std::string>& arg3,
500 const Numberz::type arg4,
501 const UserId arg5) {
Roger Meier7e056e72011-07-17 07:28:28 +0000502 Xtruct res;
503 _delegate->testMulti(res, arg0, arg1, arg2, arg3, arg4, arg5);
504 cob(res);
505 }
506
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100507 virtual void testException(
508 tcxx::function<void()> cob,
509 tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
510 const std::string& arg) {
Roger Meier7e056e72011-07-17 07:28:28 +0000511 try {
512 _delegate->testException(arg);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100513 } catch (const apache::thrift::TException& e) {
Roger Meier7e056e72011-07-17 07:28:28 +0000514 exn_cob(apache::thrift::TDelayedException::delayException(e));
515 return;
516 }
517 cob();
518 }
519
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100520 virtual void testMultiException(
521 tcxx::function<void(Xtruct const& _return)> cob,
522 tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
523 const std::string& arg0,
524 const std::string& arg1) {
Roger Meier7e056e72011-07-17 07:28:28 +0000525 Xtruct res;
526 try {
527 _delegate->testMultiException(res, arg0, arg1);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100528 } catch (const apache::thrift::TException& e) {
Roger Meier7e056e72011-07-17 07:28:28 +0000529 exn_cob(apache::thrift::TDelayedException::delayException(e));
530 return;
531 }
532 cob(res);
533 }
534
Roger Meier0a7c69c2014-05-02 21:15:45 +0200535 virtual void testOneway(tcxx::function<void()> cob, const int32_t secondsToSleep) {
Roger Meier7e056e72011-07-17 07:28:28 +0000536 _delegate->testOneway(secondsToSleep);
537 cob();
538 }
539
540protected:
Roger Meier611f90c2011-12-11 22:08:51 +0000541 boost::shared_ptr<TestHandler> _delegate;
Roger Meier7e056e72011-07-17 07:28:28 +0000542};
543
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100544int main(int argc, char** argv) {
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530545
546 string file_path = boost::filesystem::system_complete(argv[0]).string();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100547 string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530548
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100549#if _WIN32
Jake Farrell5d02b802014-01-07 21:42:01 -0500550 transport::TWinsockSingleton::create();
551#endif
Mark Sleee8540632006-05-30 09:24:40 +0000552 int port = 9090;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000553 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000554 string transport_type = "buffered";
555 string protocol_type = "binary";
556 string server_type = "simple";
557 string domain_socket = "";
558 size_t workers = 4;
Marc Slemko6be374b2006-08-04 03:16:25 +0000559
Jake Farrell5d02b802014-01-07 21:42:01 -0500560 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100561 desc.add_options()("help,h", "produce help message")(
562 "port",
563 boost::program_options::value<int>(&port)->default_value(port),
564 "Port number to listen")("domain-socket",
565 boost::program_options::value<string>(&domain_socket)
566 ->default_value(domain_socket),
567 "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)")(
568 "server-type",
569 boost::program_options::value<string>(&server_type)->default_value(server_type),
570 "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"")(
571 "transport",
572 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
573 "transport: buffered, framed, http")(
574 "protocol",
575 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
576 "protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")(
577 "processor-events",
578 "processor-events")("workers,n",
579 boost::program_options::value<size_t>(&workers)->default_value(workers),
580 "Number of thread pools workers. Only valid for thread-pool server type");
Marc Slemko6be374b2006-08-04 03:16:25 +0000581
Jake Farrell5d02b802014-01-07 21:42:01 -0500582 boost::program_options::variables_map vm;
583 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
584 boost::program_options::notify(vm);
Marc Slemko6be374b2006-08-04 03:16:25 +0000585
Roger Meierca142b02011-06-07 17:59:07 +0000586 if (vm.count("help")) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100587 cout << desc << "\n";
588 return 1;
Mark Sleee8540632006-05-30 09:24:40 +0000589 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500590
Marc Slemko6be374b2006-08-04 03:16:25 +0000591 try {
Roger Meierca142b02011-06-07 17:59:07 +0000592 if (!server_type.empty()) {
593 if (server_type == "simple") {
594 } else if (server_type == "thread-pool") {
595 } else if (server_type == "threaded") {
596 } else if (server_type == "nonblocking") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000597 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100598 throw invalid_argument("Unknown server type " + server_type);
Roger Meierca142b02011-06-07 17:59:07 +0000599 }
600 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500601
Roger Meierca142b02011-06-07 17:59:07 +0000602 if (!protocol_type.empty()) {
603 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100604 } else if (protocol_type == "compact") {
Roger Meierca142b02011-06-07 17:59:07 +0000605 } else if (protocol_type == "json") {
606 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100607 throw invalid_argument("Unknown protocol type " + protocol_type);
Marc Slemko6be374b2006-08-04 03:16:25 +0000608 }
609 }
610
Roger Meier284101c2014-03-11 21:20:35 +0100611 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000612 if (transport_type == "buffered") {
613 } else if (transport_type == "framed") {
614 } else if (transport_type == "http") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000615 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100616 throw invalid_argument("Unknown transport type " + transport_type);
Marc Slemko6be374b2006-08-04 03:16:25 +0000617 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000618 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000619
Bryan Duxbury833ae492010-09-27 17:26:02 +0000620 } catch (std::exception& e) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000621 cerr << e.what() << endl;
Roger Meierca142b02011-06-07 17:59:07 +0000622 cout << desc << "\n";
623 return 1;
Marc Slemko6be374b2006-08-04 03:16:25 +0000624 }
625
Roger Meierca142b02011-06-07 17:59:07 +0000626 if (vm.count("ssl")) {
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000627 ssl = true;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000628 }
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;
Roger Meierca142b02011-06-07 17:59:07 +0000638 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100639 boost::shared_ptr<TProtocolFactory> binaryProtocolFactory(
640 new TBinaryProtocolFactoryT<TBufferBase>());
Roger Meierca142b02011-06-07 17:59:07 +0000641 protocolFactory = binaryProtocolFactory;
642 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000643
Roger Meierca142b02011-06-07 17:59:07 +0000644 // Processor
Roger Meier611f90c2011-12-11 22:08:51 +0000645 boost::shared_ptr<TestHandler> testHandler(new TestHandler());
646 boost::shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
Jake Farrell5d02b802014-01-07 21:42:01 -0500647
Roger Meierca142b02011-06-07 17:59:07 +0000648 if (vm.count("processor-events")) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100649 testProcessor->setEventHandler(
650 boost::shared_ptr<TProcessorEventHandler>(new TestProcessorEventHandler()));
David Reissd7192062010-10-06 17:09:33 +0000651 }
Jake Farrell5d02b802014-01-07 21:42:01 -0500652
Mark Sleee8540632006-05-30 09:24:40 +0000653 // Transport
Roger Meier611f90c2011-12-11 22:08:51 +0000654 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory;
655 boost::shared_ptr<TServerSocket> serverSocket;
Mark Sleee8540632006-05-30 09:24:40 +0000656
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000657 if (ssl) {
Roger Meier611f90c2011-12-11 22:08:51 +0000658 sslSocketFactory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530659 sslSocketFactory->loadCertificate((dir_path + "../keys/server.crt").c_str());
660 sslSocketFactory->loadPrivateKey((dir_path + "../keys/server.key").c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000661 sslSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Roger Meier611f90c2011-12-11 22:08:51 +0000662 serverSocket = boost::shared_ptr<TServerSocket>(new TSSLServerSocket(port, sslSocketFactory));
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000663 } else {
Roger Meierc94b2932014-02-22 20:07:33 +0100664 if (domain_socket != "") {
665 unlink(domain_socket.c_str());
666 serverSocket = boost::shared_ptr<TServerSocket>(new TServerSocket(domain_socket));
667 port = 0;
668 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000669 serverSocket = boost::shared_ptr<TServerSocket>(new TServerSocket(port));
Roger Meierc94b2932014-02-22 20:07:33 +0100670 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000671 }
Roger Meierca142b02011-06-07 17:59:07 +0000672
Mark Sleed788b2e2006-09-07 01:26:35 +0000673 // Factory
Roger Meier611f90c2011-12-11 22:08:51 +0000674 boost::shared_ptr<TTransportFactory> transportFactory;
Jake Farrell5d02b802014-01-07 21:42:01 -0500675
Roger Meier7e056e72011-07-17 07:28:28 +0000676 if (transport_type == "http" && server_type != "nonblocking") {
Jake Farrell5d02b802014-01-07 21:42:01 -0500677 boost::shared_ptr<TTransportFactory> httpTransportFactory(new THttpServerTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000678 transportFactory = httpTransportFactory;
679 } else if (transport_type == "framed") {
Jake Farrell5d02b802014-01-07 21:42:01 -0500680 boost::shared_ptr<TTransportFactory> framedTransportFactory(new TFramedTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000681 transportFactory = framedTransportFactory;
682 } else {
Jake Farrell5d02b802014-01-07 21:42:01 -0500683 boost::shared_ptr<TTransportFactory> bufferedTransportFactory(new TBufferedTransportFactory());
Roger Meierca142b02011-06-07 17:59:07 +0000684 transportFactory = bufferedTransportFactory;
685 }
Mark Sleed788b2e2006-09-07 01:26:35 +0000686
Roger Meierca142b02011-06-07 17:59:07 +0000687 // Server Info
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100688 cout << "Starting \"" << server_type << "\" server (" << transport_type << "/" << protocol_type
689 << ") listen on: " << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000690 if (port != 0) {
691 cout << port;
692 }
693 cout << endl;
Mark Sleee8540632006-05-30 09:24:40 +0000694
Roger Meierca142b02011-06-07 17:59:07 +0000695 // Server
Jake Farrell5d02b802014-01-07 21:42:01 -0500696 boost::shared_ptr<apache::thrift::server::TServer> server;
697
Roger Meierca142b02011-06-07 17:59:07 +0000698 if (server_type == "simple") {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100699 server.reset(new TSimpleServer(testProcessor, serverSocket, transportFactory, protocolFactory));
Roger Meierca142b02011-06-07 17:59:07 +0000700 } else if (server_type == "thread-pool") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000701
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100702 boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workers);
Marc Slemko6be374b2006-08-04 03:16:25 +0000703
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100704 boost::shared_ptr<PlatformThreadFactory> threadFactory
705 = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
Marc Slemko6be374b2006-08-04 03:16:25 +0000706
707 threadManager->threadFactory(threadFactory);
708
709 threadManager->start();
710
Jake Farrell5d02b802014-01-07 21:42:01 -0500711 server.reset(new TThreadPoolServer(testProcessor,
Roger Meierca142b02011-06-07 17:59:07 +0000712 serverSocket,
Mark Sleed788b2e2006-09-07 01:26:35 +0000713 transportFactory,
Mark Sleea3302652006-10-25 19:03:32 +0000714 protocolFactory,
Jake Farrell5d02b802014-01-07 21:42:01 -0500715 threadManager));
Roger Meierca142b02011-06-07 17:59:07 +0000716 } else if (server_type == "threaded") {
David Reiss0c90f6f2008-02-06 22:18:40 +0000717
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100718 server.reset(
719 new TThreadedServer(testProcessor, serverSocket, transportFactory, protocolFactory));
Roger Meierca142b02011-06-07 17:59:07 +0000720 } else if (server_type == "nonblocking") {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100721 if (transport_type == "http") {
Roger Meier611f90c2011-12-11 22:08:51 +0000722 boost::shared_ptr<TestHandlerAsync> testHandlerAsync(new TestHandlerAsync(testHandler));
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100723 boost::shared_ptr<TAsyncProcessor> testProcessorAsync(
724 new ThriftTestAsyncProcessor(testHandlerAsync));
725 boost::shared_ptr<TAsyncBufferProcessor> testBufferProcessor(
726 new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory));
Jake Farrell5d02b802014-01-07 21:42:01 -0500727
728 // not loading nonblockingServer into "server" because
729 // TEvhttpServer doesn't inherit from TServer, and doesn't
730 // provide a stop method.
Roger Meier7e056e72011-07-17 07:28:28 +0000731 TEvhttpServer nonblockingServer(testBufferProcessor, port);
732 nonblockingServer.serve();
Jake Farrell5d02b802014-01-07 21:42:01 -0500733 } else {
734 server.reset(new TNonblockingServer(testProcessor, port));
Roger Meier7e056e72011-07-17 07:28:28 +0000735 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000736 }
737
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100738 if (server.get() != NULL) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500739 apache::thrift::concurrency::PlatformThreadFactory factory;
740 factory.setDetached(false);
741 boost::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100742 boost::shared_ptr<apache::thrift::concurrency::Thread> thread
743 = factory.newThread(serverThreadRunner);
Jake Farrell5d02b802014-01-07 21:42:01 -0500744 thread->start();
745
Roger Meier284101c2014-03-11 21:20:35 +0100746 // HACK: cross language test suite is unable to handle cin properly
747 // that's why we stay in a endless loop here
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100748 while (1) {
749 }
Roger Meier284101c2014-03-11 21:20:35 +0100750 // FIXME: find another way to stop the server (e.g. a signal)
751 // cout<<"Press enter to stop the server."<<endl;
752 // cin.ignore(); //wait until a key is pressed
Jake Farrell5d02b802014-01-07 21:42:01 -0500753
754 server->stop();
755 thread->join();
756 server.reset();
757 }
758
Roger Meierca142b02011-06-07 17:59:07 +0000759 cout << "done." << endl;
Mark Sleee8540632006-05-30 09:24:40 +0000760 return 0;
761}