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