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