Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 1 | #include <concurrency/ThreadManager.h> |
| 2 | #include <concurrency/PosixThreadFactory.h> |
| 3 | #include <protocol/TBinaryProtocol.h> |
| 4 | #include <server/TSimpleServer.h> |
| 5 | #include <server/TThreadPoolServer.h> |
| 6 | #include <transport/TServerSocket.h> |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 7 | #include <transport/TBufferedTransportFactory.h> |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 8 | #include "ThriftTest.h" |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 9 | |
| 10 | #include <iostream> |
| 11 | #include <stdexcept> |
| 12 | #include <sstream> |
| 13 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 14 | using namespace std; |
| 15 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 16 | using namespace facebook::thrift; |
| 17 | using namespace facebook::thrift::protocol; |
| 18 | using namespace facebook::thrift::transport; |
| 19 | using namespace facebook::thrift::server; |
| 20 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 21 | using namespace thrift::test; |
| 22 | |
Mark Slee | d265552 | 2006-09-05 22:09:57 +0000 | [diff] [blame] | 23 | class TestHandler : public ThriftTestIf { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 24 | public: |
Mark Slee | d265552 | 2006-09-05 22:09:57 +0000 | [diff] [blame] | 25 | TestHandler() {} |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 26 | |
| 27 | void testVoid() { |
| 28 | printf("testVoid()\n"); |
| 29 | } |
| 30 | |
| 31 | string testString(string thing) { |
| 32 | printf("testString(\"%s\")\n", thing.c_str()); |
| 33 | return thing; |
| 34 | } |
| 35 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 36 | int8_t testByte(int8_t thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 37 | printf("testByte(%d)\n", (int)thing); |
| 38 | return thing; |
| 39 | } |
| 40 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 41 | int32_t testI32(int32_t thing) { |
| 42 | printf("testI32(%d)\n", thing); |
| 43 | return thing; |
| 44 | } |
| 45 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 46 | int64_t testI64(int64_t thing) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 47 | printf("testI64(%ld)\n", thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 48 | return thing; |
| 49 | } |
| 50 | |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 51 | double testDouble(double thing) { |
| 52 | printf("testDouble(%lf)\n", thing); |
| 53 | return thing; |
| 54 | } |
| 55 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 56 | Xtruct testStruct(Xtruct thing) { |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 57 | printf("testStruct({\"%s\", %d, %d, %ld})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 58 | return thing; |
| 59 | } |
| 60 | |
| 61 | Xtruct2 testNest(Xtruct2 nest) { |
| 62 | Xtruct thing = nest.struct_thing; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 63 | printf("testNest({%d, {\"%s\", %d, %d, %ld}, %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 Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 64 | return nest; |
| 65 | } |
| 66 | |
| 67 | map<int32_t, int32_t> testMap(map<int32_t, int32_t> thing) { |
| 68 | printf("testMap({"); |
| 69 | map<int32_t, int32_t>::const_iterator m_iter; |
| 70 | bool first = true; |
| 71 | for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) { |
| 72 | if (first) { |
| 73 | first = false; |
| 74 | } else { |
| 75 | printf(", "); |
| 76 | } |
| 77 | printf("%d => %d", m_iter->first, m_iter->second); |
| 78 | } |
| 79 | printf("})\n"); |
| 80 | return thing; |
| 81 | } |
| 82 | |
| 83 | set<int32_t> testSet(set<int32_t> thing) { |
| 84 | printf("testSet({"); |
| 85 | set<int32_t>::const_iterator s_iter; |
| 86 | bool first = true; |
| 87 | for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) { |
| 88 | if (first) { |
| 89 | first = false; |
| 90 | } else { |
| 91 | printf(", "); |
| 92 | } |
| 93 | printf("%d", *s_iter); |
| 94 | } |
| 95 | printf("})\n"); |
| 96 | return thing; |
| 97 | } |
| 98 | |
| 99 | list<int32_t> testList(list<int32_t> thing) { |
| 100 | printf("testList({"); |
| 101 | list<int32_t>::const_iterator l_iter; |
| 102 | bool first = true; |
| 103 | for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) { |
| 104 | if (first) { |
| 105 | first = false; |
| 106 | } else { |
| 107 | printf(", "); |
| 108 | } |
| 109 | printf("%d", *l_iter); |
| 110 | } |
| 111 | printf("})\n"); |
| 112 | return thing; |
| 113 | } |
| 114 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 115 | Numberz testEnum(Numberz thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 116 | printf("testEnum(%d)\n", thing); |
| 117 | return thing; |
| 118 | } |
| 119 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 120 | UserId testTypedef(UserId thing) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 121 | printf("testTypedef(%ld)\n", thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 122 | return thing; |
| 123 | } |
| 124 | |
| 125 | map<int32_t, map<int32_t,int32_t> > testMapMap(int32_t hello) { |
| 126 | printf("testMapMap(%d)\n", hello); |
| 127 | map<int32_t, map<int32_t,int32_t> > mapmap; |
| 128 | |
| 129 | map<int32_t,int32_t> pos; |
| 130 | map<int32_t,int32_t> neg; |
| 131 | for (int i = 1; i < 5; i++) { |
| 132 | pos.insert(make_pair(i,i)); |
| 133 | neg.insert(make_pair(-i,-i)); |
| 134 | } |
| 135 | |
| 136 | mapmap.insert(make_pair(4, pos)); |
| 137 | mapmap.insert(make_pair(-4, neg)); |
| 138 | |
| 139 | return mapmap; |
| 140 | } |
| 141 | |
| 142 | map<UserId, map<Numberz,Insanity> > testInsanity(Insanity argument) { |
| 143 | printf("testInsanity()\n"); |
| 144 | |
| 145 | Xtruct hello; |
| 146 | hello.string_thing = "Hello2"; |
| 147 | hello.byte_thing = 2; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 148 | hello.i32_thing = 2; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 149 | hello.i64_thing = 2; |
| 150 | |
| 151 | Xtruct goodbye; |
| 152 | goodbye.string_thing = "Goodbye4"; |
| 153 | goodbye.byte_thing = 4; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 154 | goodbye.i32_thing = 4; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 155 | goodbye.i64_thing = 4; |
| 156 | |
| 157 | Insanity crazy; |
| 158 | crazy.userMap.insert(make_pair(EIGHT, 8)); |
| 159 | crazy.xtructs.push_back(goodbye); |
| 160 | |
| 161 | Insanity looney; |
| 162 | crazy.userMap.insert(make_pair(FIVE, 5)); |
| 163 | crazy.xtructs.push_back(hello); |
| 164 | |
| 165 | map<Numberz, Insanity> first_map; |
| 166 | map<Numberz, Insanity> second_map; |
| 167 | |
| 168 | first_map.insert(make_pair(TWO, crazy)); |
| 169 | first_map.insert(make_pair(THREE, crazy)); |
| 170 | |
| 171 | second_map.insert(make_pair(SIX, looney)); |
| 172 | |
| 173 | map<UserId, map<Numberz,Insanity> > insane; |
| 174 | insane.insert(make_pair(1, first_map)); |
| 175 | insane.insert(make_pair(2, second_map)); |
| 176 | |
| 177 | printf("return"); |
| 178 | printf(" = {"); |
| 179 | map<UserId, map<Numberz,Insanity> >::const_iterator i_iter; |
| 180 | for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 181 | printf("%ld => {", i_iter->first); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 182 | map<Numberz,Insanity>::const_iterator i2_iter; |
| 183 | for (i2_iter = i_iter->second.begin(); |
| 184 | i2_iter != i_iter->second.end(); |
| 185 | ++i2_iter) { |
| 186 | printf("%d => {", i2_iter->first); |
| 187 | map<Numberz, UserId> userMap = i2_iter->second.userMap; |
| 188 | map<Numberz, UserId>::const_iterator um; |
| 189 | printf("{"); |
| 190 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 191 | printf("%d => %ld, ", um->first, um->second); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 192 | } |
| 193 | printf("}, "); |
| 194 | |
| 195 | list<Xtruct> xtructs = i2_iter->second.xtructs; |
| 196 | list<Xtruct>::const_iterator x; |
| 197 | printf("{"); |
| 198 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 199 | printf("{\"%s\", %d, %d, %ld}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 200 | } |
| 201 | printf("}"); |
| 202 | |
| 203 | printf("}, "); |
| 204 | } |
| 205 | printf("}, "); |
| 206 | } |
| 207 | printf("}\n"); |
| 208 | |
| 209 | return insane; |
| 210 | } |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 211 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 212 | Xtruct testMulti(int8_t arg0, int32_t arg1, int64_t arg2, std::map<int16_t, std::string> arg3, Numberz arg4, UserId arg5) { |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 213 | printf("testMulti()\n"); |
| 214 | |
| 215 | Xtruct hello; |
| 216 | hello.string_thing = "Hello2"; |
| 217 | hello.byte_thing = arg0; |
| 218 | hello.i32_thing = arg1; |
| 219 | hello.i64_thing = (int64_t)arg2; |
| 220 | |
| 221 | return hello; |
| 222 | } |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 223 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 224 | void testException(std::string arg) throw(Xception) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 225 | printf("testException(%s)\n", arg.c_str()); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 226 | if (arg.compare("Xception") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 227 | Xception e; |
| 228 | e.errorCode = 1001; |
| 229 | e.message = "This is an Xception"; |
| 230 | throw e; |
| 231 | } else { |
| 232 | Xtruct result; |
| 233 | result.string_thing = arg; |
| 234 | return; |
| 235 | } |
| 236 | } |
| 237 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 238 | Xtruct testMultiException(std::string arg0, std::string arg1) throw(Xception, Xception2) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 239 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 240 | printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 241 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 242 | if (arg0.compare("Xception") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 243 | Xception e; |
| 244 | e.errorCode = 1001; |
| 245 | e.message = "This is an Xception"; |
| 246 | throw e; |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 247 | } else if (arg0.compare("Xception2") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 248 | Xception2 e; |
| 249 | e.errorCode = 2002; |
| 250 | e.struct_thing.string_thing = "This is an Xception2"; |
| 251 | throw e; |
| 252 | } else { |
| 253 | Xtruct result; |
| 254 | result.string_thing = arg1; |
| 255 | return result; |
| 256 | } |
| 257 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 258 | }; |
| 259 | |
| 260 | int main(int argc, char **argv) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 261 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 262 | int port = 9090; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 263 | string serverType = "simple"; |
| 264 | string protocolType = "binary"; |
| 265 | size_t workerCount = 4; |
| 266 | |
| 267 | ostringstream usage; |
| 268 | |
| 269 | usage << |
| 270 | argv[0] << " [--port=<port number>] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>]" << endl << |
| 271 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 272 | "\t\tserver-type\t\ttype of server, \"simple\" or \"thread-pool\". Default is " << serverType << endl << |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 273 | |
| 274 | "\t\tprotocol-type\t\ttype of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl << |
| 275 | |
| 276 | "\t\tworkers\t\tNumber of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl; |
| 277 | |
| 278 | map<string, string> args; |
| 279 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 280 | for (int ix = 1; ix < argc; ix++) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 281 | string arg(argv[ix]); |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 282 | if (arg.compare(0,2, "--") == 0) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 283 | size_t end = arg.find_first_of("=", 2); |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 284 | if (end != string::npos) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 285 | args[string(arg, 2, end - 2)] = string(arg, end + 1); |
| 286 | } else { |
| 287 | args[string(arg, 2, end - 2)] = "true"; |
| 288 | } |
| 289 | ix++; |
| 290 | } else { |
| 291 | throw invalid_argument("Unexcepted command line token: "+arg); |
| 292 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 293 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 294 | |
| 295 | try { |
| 296 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 297 | if (!args["port"].empty()) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 298 | port = atoi(args["port"].c_str()); |
| 299 | } |
| 300 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 301 | if (!args["server-type"].empty()) { |
| 302 | serverType = args["server-type"]; |
| 303 | if (serverType == "simple") { |
| 304 | } else if (serverType == "thread-pool") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 305 | } else { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 306 | throw invalid_argument("Unknown server type "+serverType); |
| 307 | } |
| 308 | } |
| 309 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 310 | if (!args["protocol-type"].empty()) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 311 | protocolType = args["protocol-type"]; |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 312 | if (protocolType == "binary") { |
| 313 | } else if (protocolType == "ascii") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 314 | throw invalid_argument("ASCII protocol not supported"); |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 315 | } else if (protocolType == "xml") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 316 | throw invalid_argument("XML protocol not supported"); |
| 317 | } else { |
| 318 | throw invalid_argument("Unknown protocol type "+protocolType); |
| 319 | } |
| 320 | } |
| 321 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 322 | if (!args["workers"].empty()) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 323 | workerCount = atoi(args["workers"].c_str()); |
| 324 | } |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 325 | } catch (exception& e) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 326 | cerr << e.what() << endl; |
| 327 | cerr << usage; |
| 328 | } |
| 329 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 330 | // Dispatcher |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 331 | shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol); |
| 332 | |
Mark Slee | d265552 | 2006-09-05 22:09:57 +0000 | [diff] [blame] | 333 | shared_ptr<TestHandler> testHandler(new TestHandler()); |
| 334 | |
Mark Slee | 018b699 | 2006-09-07 21:31:12 +0000 | [diff] [blame] | 335 | shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler, binaryProtocol)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 336 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 337 | // Transport |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 338 | shared_ptr<TServerSocket> serverSocket(new TServerSocket(port)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 339 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 340 | // Factory |
| 341 | shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory()); |
| 342 | |
| 343 | // Options |
| 344 | shared_ptr<TServerOptions> serverOptions(new TServerOptions()); |
| 345 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 346 | if (serverType == "simple") { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 347 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 348 | // Server |
Mark Slee | 018b699 | 2006-09-07 21:31:12 +0000 | [diff] [blame] | 349 | TSimpleServer simpleServer(testProcessor, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 350 | serverSocket, |
| 351 | transportFactory, |
| 352 | serverOptions |
| 353 | ); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 354 | |
| 355 | printf("Starting the server on port %d...\n", port); |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame^] | 356 | simpleServer.serve(); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 357 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 358 | } else if (serverType == "thread-pool") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 359 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 360 | shared_ptr<ThreadManager> threadManager = |
| 361 | ThreadManager::newSimpleThreadManager(workerCount); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 362 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 363 | shared_ptr<PosixThreadFactory> threadFactory = |
| 364 | shared_ptr<PosixThreadFactory>(new PosixThreadFactory()); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 365 | |
| 366 | threadManager->threadFactory(threadFactory); |
| 367 | |
| 368 | threadManager->start(); |
| 369 | |
Mark Slee | 018b699 | 2006-09-07 21:31:12 +0000 | [diff] [blame] | 370 | TThreadPoolServer threadPoolServer(testProcessor, |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 371 | serverSocket, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 372 | transportFactory, |
| 373 | threadManager, |
| 374 | serverOptions); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 375 | |
| 376 | printf("Starting the server on port %d...\n", port); |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame^] | 377 | threadPoolServer.serve(); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 380 | printf("done.\n"); |
| 381 | return 0; |
| 382 | } |