blob: 14a8a8efa4b8786afc7684e98d54c50b75f53dd5 [file] [log] [blame]
Marc Slemko6be374b2006-08-04 03:16:25 +00001#include <concurrency/ThreadManager.h>
2#include <concurrency/PosixThreadFactory.h>
3#include <protocol/TBinaryProtocol.h>
4#include <server/TSimpleServer.h>
Mark Slee0c2dff32007-03-09 19:26:57 +00005#include <server/TThreadedServer.h>
Marc Slemko6be374b2006-08-04 03:16:25 +00006#include <server/TThreadPoolServer.h>
Mark Sleeb9acf982006-10-10 01:57:32 +00007#include <server/TNonblockingServer.h>
Marc Slemko6be374b2006-08-04 03:16:25 +00008#include <transport/TServerSocket.h>
Mark Sleea3302652006-10-25 19:03:32 +00009#include <transport/TTransportUtils.h>
Mark Slee95771002006-06-07 06:53:25 +000010#include "ThriftTest.h"
Marc Slemko6be374b2006-08-04 03:16:25 +000011
12#include <iostream>
13#include <stdexcept>
14#include <sstream>
15
David Reissbc3dddb2007-08-22 23:20:24 +000016#define __STDC_FORMAT_MACROS
17#include <inttypes.h>
18
Mark Sleee8540632006-05-30 09:24:40 +000019using namespace std;
Mark Slee0c2dff32007-03-09 19:26:57 +000020using namespace boost;
Mark Sleee8540632006-05-30 09:24:40 +000021
Marc Slemko6be374b2006-08-04 03:16:25 +000022using namespace facebook::thrift;
Mark Slee0c2dff32007-03-09 19:26:57 +000023using namespace facebook::thrift::concurrency;
Marc Slemko6be374b2006-08-04 03:16:25 +000024using namespace facebook::thrift::protocol;
25using namespace facebook::thrift::transport;
26using namespace facebook::thrift::server;
27
Marc Slemkobf4fd192006-08-15 21:29:39 +000028using namespace thrift::test;
29
Mark Sleed2655522006-09-05 22:09:57 +000030class TestHandler : public ThriftTestIf {
Mark Sleee8540632006-05-30 09:24:40 +000031 public:
Mark Sleed2655522006-09-05 22:09:57 +000032 TestHandler() {}
Mark Sleee8540632006-05-30 09:24:40 +000033
34 void testVoid() {
35 printf("testVoid()\n");
36 }
37
Mark Slee1921d202007-01-24 19:43:06 +000038 void testString(string& out, const string &thing) {
Mark Sleee8540632006-05-30 09:24:40 +000039 printf("testString(\"%s\")\n", thing.c_str());
Mark Slee1921d202007-01-24 19:43:06 +000040 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +000041 }
42
Mark Slee1921d202007-01-24 19:43:06 +000043 int8_t testByte(const int8_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000044 printf("testByte(%d)\n", (int)thing);
45 return thing;
46 }
47
Mark Slee1921d202007-01-24 19:43:06 +000048 int32_t testI32(const int32_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000049 printf("testI32(%d)\n", thing);
50 return thing;
51 }
52
Mark Slee1921d202007-01-24 19:43:06 +000053 int64_t testI64(const int64_t thing) {
David Reissbc3dddb2007-08-22 23:20:24 +000054 printf("testI64(%"PRId64")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +000055 return thing;
56 }
57
Mark Slee1921d202007-01-24 19:43:06 +000058 double testDouble(const double thing) {
Mark Sleec98d0502006-09-06 02:42:25 +000059 printf("testDouble(%lf)\n", thing);
60 return thing;
61 }
62
Mark Slee1921d202007-01-24 19:43:06 +000063 void testStruct(Xtruct& out, const Xtruct &thing) {
David Reissbc3dddb2007-08-22 23:20:24 +000064 printf("testStruct({\"%s\", %d, %d, %"PRId64"})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing);
Mark Slee1921d202007-01-24 19:43:06 +000065 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +000066 }
67
Mark Slee1921d202007-01-24 19:43:06 +000068 void testNest(Xtruct2& out, const Xtruct2& nest) {
69 const Xtruct &thing = nest.struct_thing;
David Reissbc3dddb2007-08-22 23:20:24 +000070 printf("testNest({%d, {\"%s\", %d, %d, %"PRId64"}, %d})\n", (int)nest.byte_thing, thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing, nest.i32_thing);
Mark Slee1921d202007-01-24 19:43:06 +000071 out = nest;
Mark Sleee8540632006-05-30 09:24:40 +000072 }
73
Mark Slee1921d202007-01-24 19:43:06 +000074 void testMap(map<int32_t, int32_t> &out, const map<int32_t, int32_t> &thing) {
Mark Sleee8540632006-05-30 09:24:40 +000075 printf("testMap({");
76 map<int32_t, int32_t>::const_iterator m_iter;
77 bool first = true;
78 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
79 if (first) {
80 first = false;
81 } else {
82 printf(", ");
83 }
84 printf("%d => %d", m_iter->first, m_iter->second);
85 }
86 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +000087 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +000088 }
89
Mark Slee1921d202007-01-24 19:43:06 +000090 void testSet(set<int32_t> &out, const set<int32_t> &thing) {
Mark Sleee8540632006-05-30 09:24:40 +000091 printf("testSet({");
92 set<int32_t>::const_iterator s_iter;
93 bool first = true;
94 for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) {
95 if (first) {
96 first = false;
97 } else {
98 printf(", ");
99 }
100 printf("%d", *s_iter);
101 }
102 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000103 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000104 }
105
Mark Slee1921d202007-01-24 19:43:06 +0000106 void testList(vector<int32_t> &out, const vector<int32_t> &thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000107 printf("testList({");
Mark Sleeb9acf982006-10-10 01:57:32 +0000108 vector<int32_t>::const_iterator l_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000109 bool first = true;
110 for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) {
111 if (first) {
112 first = false;
113 } else {
114 printf(", ");
115 }
116 printf("%d", *l_iter);
117 }
118 printf("})\n");
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 Numberz testEnum(const Numberz thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000123 printf("testEnum(%d)\n", thing);
124 return thing;
125 }
126
Mark Slee1921d202007-01-24 19:43:06 +0000127 UserId testTypedef(const UserId thing) {
David Reissbc3dddb2007-08-22 23:20:24 +0000128 printf("testTypedef(%"PRId64")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +0000129 return thing;
130 }
131
Mark Slee1921d202007-01-24 19:43:06 +0000132 void testMapMap(map<int32_t, map<int32_t,int32_t> > &mapmap, const int32_t hello) {
Mark Sleee8540632006-05-30 09:24:40 +0000133 printf("testMapMap(%d)\n", hello);
Mark Sleee8540632006-05-30 09:24:40 +0000134
135 map<int32_t,int32_t> pos;
136 map<int32_t,int32_t> neg;
137 for (int i = 1; i < 5; i++) {
138 pos.insert(make_pair(i,i));
139 neg.insert(make_pair(-i,-i));
140 }
141
142 mapmap.insert(make_pair(4, pos));
143 mapmap.insert(make_pair(-4, neg));
144
Mark Sleee8540632006-05-30 09:24:40 +0000145 }
146
Mark Slee1921d202007-01-24 19:43:06 +0000147 void testInsanity(map<UserId, map<Numberz,Insanity> > &insane, const Insanity &argument) {
Mark Sleee8540632006-05-30 09:24:40 +0000148 printf("testInsanity()\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000149
Mark Sleee8540632006-05-30 09:24:40 +0000150 Xtruct hello;
151 hello.string_thing = "Hello2";
152 hello.byte_thing = 2;
Mark Sleee8540632006-05-30 09:24:40 +0000153 hello.i32_thing = 2;
Mark Sleee8540632006-05-30 09:24:40 +0000154 hello.i64_thing = 2;
155
156 Xtruct goodbye;
157 goodbye.string_thing = "Goodbye4";
158 goodbye.byte_thing = 4;
Mark Sleee8540632006-05-30 09:24:40 +0000159 goodbye.i32_thing = 4;
Mark Sleee8540632006-05-30 09:24:40 +0000160 goodbye.i64_thing = 4;
161
162 Insanity crazy;
163 crazy.userMap.insert(make_pair(EIGHT, 8));
164 crazy.xtructs.push_back(goodbye);
165
166 Insanity looney;
167 crazy.userMap.insert(make_pair(FIVE, 5));
168 crazy.xtructs.push_back(hello);
169
170 map<Numberz, Insanity> first_map;
171 map<Numberz, Insanity> second_map;
172
173 first_map.insert(make_pair(TWO, crazy));
174 first_map.insert(make_pair(THREE, crazy));
175
176 second_map.insert(make_pair(SIX, looney));
177
Mark Sleee8540632006-05-30 09:24:40 +0000178 insane.insert(make_pair(1, first_map));
179 insane.insert(make_pair(2, second_map));
180
181 printf("return");
182 printf(" = {");
183 map<UserId, map<Numberz,Insanity> >::const_iterator i_iter;
184 for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
David Reissbc3dddb2007-08-22 23:20:24 +0000185 printf("%"PRId64" => {", i_iter->first);
Mark Sleee8540632006-05-30 09:24:40 +0000186 map<Numberz,Insanity>::const_iterator i2_iter;
187 for (i2_iter = i_iter->second.begin();
188 i2_iter != i_iter->second.end();
189 ++i2_iter) {
190 printf("%d => {", i2_iter->first);
191 map<Numberz, UserId> userMap = i2_iter->second.userMap;
192 map<Numberz, UserId>::const_iterator um;
193 printf("{");
194 for (um = userMap.begin(); um != userMap.end(); ++um) {
David Reissbc3dddb2007-08-22 23:20:24 +0000195 printf("%d => %"PRId64", ", um->first, um->second);
Mark Sleee8540632006-05-30 09:24:40 +0000196 }
197 printf("}, ");
198
Mark Sleeb9acf982006-10-10 01:57:32 +0000199 vector<Xtruct> xtructs = i2_iter->second.xtructs;
200 vector<Xtruct>::const_iterator x;
Mark Sleee8540632006-05-30 09:24:40 +0000201 printf("{");
202 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
David Reissbc3dddb2007-08-22 23:20:24 +0000203 printf("{\"%s\", %d, %d, %"PRId64"}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing);
Mark Sleee8540632006-05-30 09:24:40 +0000204 }
205 printf("}");
206
207 printf("}, ");
208 }
209 printf("}, ");
210 }
211 printf("}\n");
212
David Reiss0c90f6f2008-02-06 22:18:40 +0000213
Mark Sleee8540632006-05-30 09:24:40 +0000214 }
Marc Slemkoe6889de2006-08-12 00:32:53 +0000215
Mark Slee1921d202007-01-24 19:43:06 +0000216 void testMulti(Xtruct &hello, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> &arg3, const Numberz arg4, const UserId arg5) {
Marc Slemkoe6889de2006-08-12 00:32:53 +0000217 printf("testMulti()\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000218
Marc Slemkoe6889de2006-08-12 00:32:53 +0000219 hello.string_thing = "Hello2";
220 hello.byte_thing = arg0;
221 hello.i32_thing = arg1;
222 hello.i64_thing = (int64_t)arg2;
Marc Slemkoe6889de2006-08-12 00:32:53 +0000223 }
Marc Slemkobf4fd192006-08-15 21:29:39 +0000224
Mark Slee1921d202007-01-24 19:43:06 +0000225 void testException(const std::string &arg) throw(Xception) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000226 printf("testException(%s)\n", arg.c_str());
Mark Sleed3d733a2006-09-01 22:19:06 +0000227 if (arg.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000228 Xception e;
229 e.errorCode = 1001;
230 e.message = "This is an Xception";
231 throw e;
232 } else {
233 Xtruct result;
234 result.string_thing = arg;
235 return;
236 }
237 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000238
Mark Slee1921d202007-01-24 19:43:06 +0000239 void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000240
Marc Slemko71d4e472006-08-15 22:34:04 +0000241 printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000242
Mark Sleef5f2be42006-09-05 21:05:31 +0000243 if (arg0.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000244 Xception e;
245 e.errorCode = 1001;
246 e.message = "This is an Xception";
247 throw e;
Mark Sleef5f2be42006-09-05 21:05:31 +0000248 } else if (arg0.compare("Xception2") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000249 Xception2 e;
250 e.errorCode = 2002;
251 e.struct_thing.string_thing = "This is an Xception2";
252 throw e;
253 } else {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000254 result.string_thing = arg1;
Mark Slee1921d202007-01-24 19:43:06 +0000255 return;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000256 }
257 }
David Reiss2ab6fe82008-02-18 02:11:44 +0000258
259 void testAsync(int sleepFor) {
260 printf("testAsync(%d): Sleeping...\n", sleepFor);
261 sleep(sleepFor);
262 printf("testAsync(%d): done sleeping!\n", sleepFor);
263 }
Mark Sleee8540632006-05-30 09:24:40 +0000264};
265
266int main(int argc, char **argv) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000267
Mark Sleee8540632006-05-30 09:24:40 +0000268 int port = 9090;
Marc Slemko6be374b2006-08-04 03:16:25 +0000269 string serverType = "simple";
270 string protocolType = "binary";
271 size_t workerCount = 4;
Mark Sleea3302652006-10-25 19:03:32 +0000272 bool frameOutput = true;
Marc Slemko6be374b2006-08-04 03:16:25 +0000273
274 ostringstream usage;
275
276 usage <<
277 argv[0] << " [--port=<port number>] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>]" << endl <<
278
Mark Slee0c2dff32007-03-09 19:26:57 +0000279 "\t\tserver-type\t\ttype of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\". Default is " << serverType << endl <<
Marc Slemko6be374b2006-08-04 03:16:25 +0000280
281 "\t\tprotocol-type\t\ttype of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl <<
282
283 "\t\tworkers\t\tNumber of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +0000284
Marc Slemko6be374b2006-08-04 03:16:25 +0000285 map<string, string> args;
David Reiss0c90f6f2008-02-06 22:18:40 +0000286
Mark Sleef5f2be42006-09-05 21:05:31 +0000287 for (int ix = 1; ix < argc; ix++) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000288 string arg(argv[ix]);
Mark Sleef5f2be42006-09-05 21:05:31 +0000289 if (arg.compare(0,2, "--") == 0) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000290 size_t end = arg.find_first_of("=", 2);
Mark Sleef5f2be42006-09-05 21:05:31 +0000291 if (end != string::npos) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000292 args[string(arg, 2, end - 2)] = string(arg, end + 1);
293 } else {
Mark Sleea3302652006-10-25 19:03:32 +0000294 args[string(arg, 2)] = "true";
Marc Slemko6be374b2006-08-04 03:16:25 +0000295 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000296 } else {
297 throw invalid_argument("Unexcepted command line token: "+arg);
298 }
Mark Sleee8540632006-05-30 09:24:40 +0000299 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000300
301 try {
302
Mark Sleef5f2be42006-09-05 21:05:31 +0000303 if (!args["port"].empty()) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000304 port = atoi(args["port"].c_str());
305 }
306
Mark Sleea3302652006-10-25 19:03:32 +0000307 if (!args["noframe"].empty()) {
308 frameOutput = false;
309 }
310
Mark Sleef5f2be42006-09-05 21:05:31 +0000311 if (!args["server-type"].empty()) {
David Reiss0c90f6f2008-02-06 22:18:40 +0000312 serverType = args["server-type"];
Mark Sleef5f2be42006-09-05 21:05:31 +0000313 if (serverType == "simple") {
314 } else if (serverType == "thread-pool") {
Mark Slee0c2dff32007-03-09 19:26:57 +0000315 } else if (serverType == "threaded") {
Mark Sleeb9acf982006-10-10 01:57:32 +0000316 } else if (serverType == "nonblocking") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000317 } else {
Marc Slemko6be374b2006-08-04 03:16:25 +0000318 throw invalid_argument("Unknown server type "+serverType);
319 }
320 }
321
Mark Sleef5f2be42006-09-05 21:05:31 +0000322 if (!args["protocol-type"].empty()) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000323 protocolType = args["protocol-type"];
Mark Sleef5f2be42006-09-05 21:05:31 +0000324 if (protocolType == "binary") {
325 } else if (protocolType == "ascii") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000326 throw invalid_argument("ASCII protocol not supported");
Mark Sleef5f2be42006-09-05 21:05:31 +0000327 } else if (protocolType == "xml") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000328 throw invalid_argument("XML protocol not supported");
329 } else {
330 throw invalid_argument("Unknown protocol type "+protocolType);
331 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000332 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000333
Mark Sleef5f2be42006-09-05 21:05:31 +0000334 if (!args["workers"].empty()) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000335 workerCount = atoi(args["workers"].c_str());
336 }
Mark Sleef5f2be42006-09-05 21:05:31 +0000337 } catch (exception& e) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000338 cerr << e.what() << endl;
339 cerr << usage;
340 }
341
Mark Sleee8540632006-05-30 09:24:40 +0000342 // Dispatcher
Mark Sleea3302652006-10-25 19:03:32 +0000343 shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Marc Slemko6be374b2006-08-04 03:16:25 +0000344
Mark Sleed2655522006-09-05 22:09:57 +0000345 shared_ptr<TestHandler> testHandler(new TestHandler());
346
Mark Sleea3302652006-10-25 19:03:32 +0000347 shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
Mark Sleee8540632006-05-30 09:24:40 +0000348
Mark Sleee8540632006-05-30 09:24:40 +0000349 // Transport
Marc Slemko6be374b2006-08-04 03:16:25 +0000350 shared_ptr<TServerSocket> serverSocket(new TServerSocket(port));
Mark Sleee8540632006-05-30 09:24:40 +0000351
Mark Sleed788b2e2006-09-07 01:26:35 +0000352 // Factory
353 shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
354
Mark Sleed3d733a2006-09-01 22:19:06 +0000355 if (serverType == "simple") {
Mark Sleee8540632006-05-30 09:24:40 +0000356
Marc Slemko6be374b2006-08-04 03:16:25 +0000357 // Server
Mark Slee018b6992006-09-07 21:31:12 +0000358 TSimpleServer simpleServer(testProcessor,
Mark Sleed788b2e2006-09-07 01:26:35 +0000359 serverSocket,
360 transportFactory,
Mark Sleea3302652006-10-25 19:03:32 +0000361 protocolFactory);
Marc Slemko6be374b2006-08-04 03:16:25 +0000362
363 printf("Starting the server on port %d...\n", port);
Mark Slee794993d2006-09-20 01:56:10 +0000364 simpleServer.serve();
Marc Slemko6be374b2006-08-04 03:16:25 +0000365
Mark Sleed3d733a2006-09-01 22:19:06 +0000366 } else if (serverType == "thread-pool") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000367
Mark Sleef5f2be42006-09-05 21:05:31 +0000368 shared_ptr<ThreadManager> threadManager =
369 ThreadManager::newSimpleThreadManager(workerCount);
Marc Slemko6be374b2006-08-04 03:16:25 +0000370
Mark Sleef5f2be42006-09-05 21:05:31 +0000371 shared_ptr<PosixThreadFactory> threadFactory =
372 shared_ptr<PosixThreadFactory>(new PosixThreadFactory());
Marc Slemko6be374b2006-08-04 03:16:25 +0000373
374 threadManager->threadFactory(threadFactory);
375
376 threadManager->start();
377
Mark Slee018b6992006-09-07 21:31:12 +0000378 TThreadPoolServer threadPoolServer(testProcessor,
Marc Slemko6be374b2006-08-04 03:16:25 +0000379 serverSocket,
Mark Sleed788b2e2006-09-07 01:26:35 +0000380 transportFactory,
Mark Sleea3302652006-10-25 19:03:32 +0000381 protocolFactory,
382 threadManager);
Marc Slemko6be374b2006-08-04 03:16:25 +0000383
384 printf("Starting the server on port %d...\n", port);
Mark Slee794993d2006-09-20 01:56:10 +0000385 threadPoolServer.serve();
Mark Sleeb9acf982006-10-10 01:57:32 +0000386
Mark Slee0c2dff32007-03-09 19:26:57 +0000387 } else if (serverType == "threaded") {
David Reiss0c90f6f2008-02-06 22:18:40 +0000388
Mark Slee0c2dff32007-03-09 19:26:57 +0000389 TThreadedServer threadedServer(testProcessor,
390 serverSocket,
391 transportFactory,
392 protocolFactory);
393
394 printf("Starting the server on port %d...\n", port);
395 threadedServer.serve();
396
Mark Sleeb9acf982006-10-10 01:57:32 +0000397 } else if (serverType == "nonblocking") {
398
Mark Sleea3302652006-10-25 19:03:32 +0000399 TNonblockingServer nonblockingServer(testProcessor, port);
400 nonblockingServer.setFrameResponses(frameOutput);
401 if (frameOutput) {
402 printf("Using framed output mode\n");
403 } else {
404 printf("Using non-framed output mode\n");
405 }
406
Mark Sleeb9acf982006-10-10 01:57:32 +0000407 printf("Starting the nonblocking server on port %d...\n", port);
408 nonblockingServer.serve();
409
Marc Slemko6be374b2006-08-04 03:16:25 +0000410 }
411
Mark Sleee8540632006-05-30 09:24:40 +0000412 printf("done.\n");
413 return 0;
414}