David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 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 Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 20 | #include <thrift/concurrency/ThreadManager.h> |
| 21 | #include <thrift/concurrency/PlatformThreadFactory.h> |
| 22 | #include <thrift/protocol/TBinaryProtocol.h> |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 23 | #include <thrift/protocol/TCompactProtocol.h> |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 24 | #include <thrift/protocol/THeaderProtocol.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 25 | #include <thrift/protocol/TJSONProtocol.h> |
| 26 | #include <thrift/server/TSimpleServer.h> |
| 27 | #include <thrift/server/TThreadedServer.h> |
| 28 | #include <thrift/server/TThreadPoolServer.h> |
| 29 | #include <thrift/async/TEvhttpServer.h> |
| 30 | #include <thrift/async/TAsyncBufferProcessor.h> |
| 31 | #include <thrift/async/TAsyncProtocolProcessor.h> |
| 32 | #include <thrift/server/TNonblockingServer.h> |
| 33 | #include <thrift/transport/TServerSocket.h> |
| 34 | #include <thrift/transport/TSSLServerSocket.h> |
| 35 | #include <thrift/transport/TSSLSocket.h> |
Divya Thaluru | 808d143 | 2017-08-06 16:36:36 -0700 | [diff] [blame] | 36 | #include <thrift/transport/TNonblockingServerSocket.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 37 | #include <thrift/transport/THttpServer.h> |
| 38 | #include <thrift/transport/THttpTransport.h> |
| 39 | #include <thrift/transport/TTransportUtils.h> |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 40 | #include "ThriftTest.h" |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 41 | |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 42 | #ifdef HAVE_STDINT_H |
| 43 | #include <stdint.h> |
| 44 | #endif |
| 45 | #ifdef HAVE_INTTYPES_H |
| 46 | #include <inttypes.h> |
| 47 | #endif |
| 48 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 49 | #include <iostream> |
| 50 | #include <stdexcept> |
| 51 | #include <sstream> |
| 52 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 53 | #include <boost/program_options.hpp> |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 54 | #include <boost/filesystem.hpp> |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 55 | #include <thrift/stdcxx.h> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 56 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 57 | #include <signal.h> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 58 | #if _WIN32 |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 59 | #include <thrift/windows/TWinsockSingleton.h> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 60 | #endif |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 61 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 62 | using namespace std; |
| 63 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 64 | using namespace apache::thrift; |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 65 | using namespace apache::thrift::async; |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 66 | using namespace apache::thrift::concurrency; |
| 67 | using namespace apache::thrift::protocol; |
| 68 | using namespace apache::thrift::transport; |
| 69 | using namespace apache::thrift::server; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 70 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 71 | using namespace thrift::test; |
| 72 | |
Mark Slee | d265552 | 2006-09-05 22:09:57 +0000 | [diff] [blame] | 73 | class TestHandler : public ThriftTestIf { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 74 | public: |
Mark Slee | d265552 | 2006-09-05 22:09:57 +0000 | [diff] [blame] | 75 | TestHandler() {} |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 76 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 77 | void testVoid() { printf("testVoid()\n"); } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 78 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 79 | void testString(string& out, const string& thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 80 | printf("testString(\"%s\")\n", thing.c_str()); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 81 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 84 | bool testBool(const bool thing) { |
| 85 | printf("testBool(%s)\n", thing ? "true" : "false"); |
| 86 | return thing; |
| 87 | } |
| 88 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 89 | int8_t testByte(const int8_t thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 90 | printf("testByte(%d)\n", (int)thing); |
| 91 | return thing; |
| 92 | } |
| 93 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 94 | int32_t testI32(const int32_t thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 95 | printf("testI32(%d)\n", thing); |
| 96 | return thing; |
| 97 | } |
| 98 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 99 | int64_t testI64(const int64_t thing) { |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 100 | printf("testI64(%" PRId64 ")\n", thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 101 | return thing; |
| 102 | } |
| 103 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 104 | double testDouble(const double thing) { |
Roger Meier | a8cef6e | 2011-07-17 18:55:59 +0000 | [diff] [blame] | 105 | printf("testDouble(%f)\n", thing); |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 106 | return thing; |
| 107 | } |
| 108 | |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 109 | void testBinary(std::string& _return, const std::string& thing) { |
| 110 | std::ostringstream hexstr; |
| 111 | hexstr << std::hex << thing; |
| 112 | printf("testBinary(%s)\n", hexstr.str().c_str()); |
| 113 | _return = thing; |
| 114 | } |
| 115 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 116 | void testStruct(Xtruct& out, const Xtruct& thing) { |
| 117 | printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n", |
| 118 | thing.string_thing.c_str(), |
| 119 | (int)thing.byte_thing, |
| 120 | thing.i32_thing, |
| 121 | thing.i64_thing); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 122 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 125 | void testNest(Xtruct2& out, const Xtruct2& nest) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 126 | const Xtruct& thing = nest.struct_thing; |
| 127 | printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n", |
| 128 | (int)nest.byte_thing, |
| 129 | thing.string_thing.c_str(), |
| 130 | (int)thing.byte_thing, |
| 131 | thing.i32_thing, |
| 132 | thing.i64_thing, |
| 133 | nest.i32_thing); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 134 | out = nest; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 137 | void testMap(map<int32_t, int32_t>& out, const map<int32_t, int32_t>& thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 138 | printf("testMap({"); |
| 139 | map<int32_t, int32_t>::const_iterator m_iter; |
| 140 | bool first = true; |
| 141 | for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) { |
| 142 | if (first) { |
| 143 | first = false; |
| 144 | } else { |
| 145 | printf(", "); |
| 146 | } |
| 147 | printf("%d => %d", m_iter->first, m_iter->second); |
| 148 | } |
| 149 | printf("})\n"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 150 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 153 | void testStringMap(map<std::string, std::string>& out, |
| 154 | const map<std::string, std::string>& thing) { |
Roger Meier | d3b9dca | 2011-06-24 14:01:10 +0000 | [diff] [blame] | 155 | printf("testMap({"); |
| 156 | map<std::string, std::string>::const_iterator m_iter; |
| 157 | bool first = true; |
| 158 | for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) { |
| 159 | if (first) { |
| 160 | first = false; |
| 161 | } else { |
| 162 | printf(", "); |
| 163 | } |
| 164 | printf("%s => %s", (m_iter->first).c_str(), (m_iter->second).c_str()); |
| 165 | } |
| 166 | printf("})\n"); |
| 167 | out = thing; |
| 168 | } |
| 169 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 170 | void testSet(set<int32_t>& out, const set<int32_t>& thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 171 | printf("testSet({"); |
| 172 | set<int32_t>::const_iterator s_iter; |
| 173 | bool first = true; |
| 174 | for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) { |
| 175 | if (first) { |
| 176 | first = false; |
| 177 | } else { |
| 178 | printf(", "); |
| 179 | } |
| 180 | printf("%d", *s_iter); |
| 181 | } |
| 182 | printf("})\n"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 183 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 186 | void testList(vector<int32_t>& out, const vector<int32_t>& thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 187 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 188 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 189 | bool first = true; |
| 190 | for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) { |
| 191 | if (first) { |
| 192 | first = false; |
| 193 | } else { |
| 194 | printf(", "); |
| 195 | } |
| 196 | printf("%d", *l_iter); |
| 197 | } |
| 198 | printf("})\n"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 199 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 202 | Numberz::type testEnum(const Numberz::type thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 203 | printf("testEnum(%d)\n", thing); |
| 204 | return thing; |
| 205 | } |
| 206 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 207 | UserId testTypedef(const UserId thing) { |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 208 | printf("testTypedef(%" PRId64 ")\n", thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 209 | return thing; |
| 210 | } |
| 211 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 212 | void testMapMap(map<int32_t, map<int32_t, int32_t> >& mapmap, const int32_t hello) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 213 | printf("testMapMap(%d)\n", hello); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 214 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 215 | map<int32_t, int32_t> pos; |
| 216 | map<int32_t, int32_t> neg; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 217 | for (int i = 1; i < 5; i++) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 218 | pos.insert(make_pair(i, i)); |
| 219 | neg.insert(make_pair(-i, -i)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | mapmap.insert(make_pair(4, pos)); |
| 223 | mapmap.insert(make_pair(-4, neg)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 226 | void testInsanity(map<UserId, map<Numberz::type, Insanity> >& insane, const Insanity& argument) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 227 | printf("testInsanity()\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 228 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 229 | Insanity looney; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 230 | map<Numberz::type, Insanity> first_map; |
| 231 | map<Numberz::type, Insanity> second_map; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 232 | |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 233 | first_map.insert(make_pair(Numberz::TWO, argument)); |
| 234 | first_map.insert(make_pair(Numberz::THREE, argument)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 235 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 236 | second_map.insert(make_pair(Numberz::SIX, looney)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 237 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 238 | insane.insert(make_pair(1, first_map)); |
| 239 | insane.insert(make_pair(2, second_map)); |
| 240 | |
| 241 | printf("return"); |
| 242 | printf(" = {"); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 243 | map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 244 | for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) { |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 245 | printf("%" PRId64 " => {", i_iter->first); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 246 | map<Numberz::type, Insanity>::const_iterator i2_iter; |
| 247 | for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 248 | printf("%d => {", i2_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 249 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 250 | map<Numberz::type, UserId>::const_iterator um; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 251 | printf("{"); |
| 252 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 253 | printf("%d => %" PRId64 ", ", um->first, um->second); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 254 | } |
| 255 | printf("}, "); |
| 256 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 257 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 258 | vector<Xtruct>::const_iterator x; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 259 | printf("{"); |
| 260 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 261 | printf("{\"%s\", %d, %d, %" PRId64 "}, ", |
| 262 | x->string_thing.c_str(), |
| 263 | (int)x->byte_thing, |
| 264 | x->i32_thing, |
| 265 | x->i64_thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 266 | } |
| 267 | printf("}"); |
| 268 | |
| 269 | printf("}, "); |
| 270 | } |
| 271 | printf("}, "); |
| 272 | } |
| 273 | printf("}\n"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 274 | } |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 275 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 276 | void testMulti(Xtruct& hello, |
| 277 | const int8_t arg0, |
| 278 | const int32_t arg1, |
| 279 | const int64_t arg2, |
| 280 | const std::map<int16_t, std::string>& arg3, |
| 281 | const Numberz::type arg4, |
| 282 | const UserId arg5) { |
| 283 | (void)arg3; |
| 284 | (void)arg4; |
| 285 | (void)arg5; |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 286 | |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 287 | printf("testMulti()\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 288 | |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 289 | hello.string_thing = "Hello2"; |
| 290 | hello.byte_thing = arg0; |
| 291 | hello.i32_thing = arg1; |
| 292 | hello.i64_thing = (int64_t)arg2; |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 293 | } |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 294 | |
ben-craig | fae08e7 | 2015-07-15 11:34:47 -0500 | [diff] [blame] | 295 | void testException(const std::string& arg) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 296 | printf("testException(%s)\n", arg.c_str()); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 297 | if (arg.compare("Xception") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 298 | Xception e; |
| 299 | e.errorCode = 1001; |
David Reiss | 9813cbe | 2009-01-31 21:39:11 +0000 | [diff] [blame] | 300 | e.message = arg; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 301 | throw e; |
Roger Meier | 1f8b48f | 2012-05-02 22:56:47 +0000 | [diff] [blame] | 302 | } else if (arg.compare("TException") == 0) { |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 303 | apache::thrift::TException e; |
David Reiss | 55ff70f | 2008-06-11 00:58:25 +0000 | [diff] [blame] | 304 | throw e; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 305 | } else { |
| 306 | Xtruct result; |
| 307 | result.string_thing = arg; |
| 308 | return; |
| 309 | } |
| 310 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 311 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 312 | void testMultiException(Xtruct& result, |
| 313 | const std::string& arg0, |
ben-craig | fae08e7 | 2015-07-15 11:34:47 -0500 | [diff] [blame] | 314 | const std::string& arg1) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 315 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 316 | printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 317 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 318 | if (arg0.compare("Xception") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 319 | Xception e; |
| 320 | e.errorCode = 1001; |
| 321 | e.message = "This is an Xception"; |
| 322 | throw e; |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 323 | } else if (arg0.compare("Xception2") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 324 | Xception2 e; |
| 325 | e.errorCode = 2002; |
| 326 | e.struct_thing.string_thing = "This is an Xception2"; |
| 327 | throw e; |
| 328 | } else { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 329 | result.string_thing = arg1; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 330 | return; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 331 | } |
| 332 | } |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 333 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 334 | void testOneway(const int32_t sleepFor) { |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 335 | printf("testOneway(%d): Sleeping...\n", sleepFor); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 336 | THRIFT_SLEEP_SEC(sleepFor); |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 337 | printf("testOneway(%d): done sleeping!\n", sleepFor); |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 338 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 339 | }; |
| 340 | |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 341 | class TestProcessorEventHandler : public TProcessorEventHandler { |
David Reiss | 2324871 | 2010-10-06 17:10:08 +0000 | [diff] [blame] | 342 | virtual void* getContext(const char* fn_name, void* serverContext) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 343 | (void)serverContext; |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 344 | return new std::string(fn_name); |
| 345 | } |
| 346 | virtual void freeContext(void* ctx, const char* fn_name) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 347 | (void)fn_name; |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 348 | delete static_cast<std::string*>(ctx); |
| 349 | } |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 350 | virtual void preRead(void* ctx, const char* fn_name) { communicate("preRead", ctx, fn_name); } |
David Reiss | ef7200f | 2010-10-06 17:09:42 +0000 | [diff] [blame] | 351 | virtual void postRead(void* ctx, const char* fn_name, uint32_t bytes) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 352 | (void)bytes; |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 353 | communicate("postRead", ctx, fn_name); |
| 354 | } |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 355 | virtual void preWrite(void* ctx, const char* fn_name) { communicate("preWrite", ctx, fn_name); } |
David Reiss | ef7200f | 2010-10-06 17:09:42 +0000 | [diff] [blame] | 356 | virtual void postWrite(void* ctx, const char* fn_name, uint32_t bytes) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 357 | (void)bytes; |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 358 | communicate("postWrite", ctx, fn_name); |
| 359 | } |
| 360 | virtual void asyncComplete(void* ctx, const char* fn_name) { |
| 361 | communicate("asyncComplete", ctx, fn_name); |
| 362 | } |
| 363 | virtual void handlerError(void* ctx, const char* fn_name) { |
| 364 | communicate("handlerError", ctx, fn_name); |
| 365 | } |
| 366 | |
| 367 | void communicate(const char* event, void* ctx, const char* fn_name) { |
| 368 | std::cout << event << ": " << *static_cast<std::string*>(ctx) << " = " << fn_name << std::endl; |
| 369 | } |
| 370 | }; |
| 371 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 372 | class TestHandlerAsync : public ThriftTestCobSvIf { |
| 373 | public: |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 374 | TestHandlerAsync(stdcxx::shared_ptr<TestHandler>& handler) : _delegate(handler) {} |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 375 | virtual ~TestHandlerAsync() {} |
| 376 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 377 | virtual void testVoid(stdcxx::function<void()> cob) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 378 | _delegate->testVoid(); |
| 379 | cob(); |
| 380 | } |
| 381 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 382 | virtual void testString(stdcxx::function<void(std::string const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 383 | const std::string& thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 384 | std::string res; |
| 385 | _delegate->testString(res, thing); |
| 386 | cob(res); |
| 387 | } |
| 388 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 389 | virtual void testBool(stdcxx::function<void(bool const& _return)> cob, const bool thing) { |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 390 | bool res = _delegate->testBool(thing); |
| 391 | cob(res); |
| 392 | } |
| 393 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 394 | virtual void testByte(stdcxx::function<void(int8_t const& _return)> cob, const int8_t thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 395 | int8_t res = _delegate->testByte(thing); |
| 396 | cob(res); |
| 397 | } |
| 398 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 399 | virtual void testI32(stdcxx::function<void(int32_t const& _return)> cob, const int32_t thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 400 | int32_t res = _delegate->testI32(thing); |
| 401 | cob(res); |
| 402 | } |
| 403 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 404 | virtual void testI64(stdcxx::function<void(int64_t const& _return)> cob, const int64_t thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 405 | int64_t res = _delegate->testI64(thing); |
| 406 | cob(res); |
| 407 | } |
| 408 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 409 | virtual void testDouble(stdcxx::function<void(double const& _return)> cob, const double thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 410 | double res = _delegate->testDouble(thing); |
| 411 | cob(res); |
| 412 | } |
| 413 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 414 | virtual void testBinary(stdcxx::function<void(std::string const& _return)> cob, |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 415 | const std::string& thing) { |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 416 | std::string res; |
| 417 | _delegate->testBinary(res, thing); |
| 418 | cob(res); |
| 419 | } |
| 420 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 421 | virtual void testStruct(stdcxx::function<void(Xtruct const& _return)> cob, const Xtruct& thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 422 | Xtruct res; |
| 423 | _delegate->testStruct(res, thing); |
| 424 | cob(res); |
| 425 | } |
| 426 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 427 | virtual void testNest(stdcxx::function<void(Xtruct2 const& _return)> cob, const Xtruct2& thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 428 | Xtruct2 res; |
| 429 | _delegate->testNest(res, thing); |
| 430 | cob(res); |
| 431 | } |
| 432 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 433 | virtual void testMap(stdcxx::function<void(std::map<int32_t, int32_t> const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 434 | const std::map<int32_t, int32_t>& thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 435 | std::map<int32_t, int32_t> res; |
| 436 | _delegate->testMap(res, thing); |
| 437 | cob(res); |
| 438 | } |
| 439 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 440 | virtual void testStringMap( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 441 | stdcxx::function<void(std::map<std::string, std::string> const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 442 | const std::map<std::string, std::string>& thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 443 | std::map<std::string, std::string> res; |
| 444 | _delegate->testStringMap(res, thing); |
| 445 | cob(res); |
| 446 | } |
| 447 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 448 | virtual void testSet(stdcxx::function<void(std::set<int32_t> const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 449 | const std::set<int32_t>& thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 450 | std::set<int32_t> res; |
| 451 | _delegate->testSet(res, thing); |
| 452 | cob(res); |
| 453 | } |
| 454 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 455 | virtual void testList(stdcxx::function<void(std::vector<int32_t> const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 456 | const std::vector<int32_t>& thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 457 | std::vector<int32_t> res; |
| 458 | _delegate->testList(res, thing); |
| 459 | cob(res); |
| 460 | } |
| 461 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 462 | virtual void testEnum(stdcxx::function<void(Numberz::type const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 463 | const Numberz::type thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 464 | Numberz::type res = _delegate->testEnum(thing); |
| 465 | cob(res); |
| 466 | } |
| 467 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 468 | virtual void testTypedef(stdcxx::function<void(UserId const& _return)> cob, const UserId thing) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 469 | UserId res = _delegate->testTypedef(thing); |
| 470 | cob(res); |
| 471 | } |
| 472 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 473 | virtual void testMapMap( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 474 | stdcxx::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 475 | const int32_t hello) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 476 | std::map<int32_t, std::map<int32_t, int32_t> > res; |
| 477 | _delegate->testMapMap(res, hello); |
| 478 | cob(res); |
| 479 | } |
| 480 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 481 | virtual void testInsanity( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 482 | stdcxx::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 483 | const Insanity& argument) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 484 | std::map<UserId, std::map<Numberz::type, Insanity> > res; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 485 | _delegate->testInsanity(res, argument); |
| 486 | cob(res); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 487 | } |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 488 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 489 | virtual void testMulti(stdcxx::function<void(Xtruct const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 490 | const int8_t arg0, |
| 491 | const int32_t arg1, |
| 492 | const int64_t arg2, |
| 493 | const std::map<int16_t, std::string>& arg3, |
| 494 | const Numberz::type arg4, |
| 495 | const UserId arg5) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 496 | Xtruct res; |
| 497 | _delegate->testMulti(res, arg0, arg1, arg2, arg3, arg4, arg5); |
| 498 | cob(res); |
| 499 | } |
| 500 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 501 | virtual void testException( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 502 | stdcxx::function<void()> cob, |
| 503 | stdcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 504 | const std::string& arg) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 505 | try { |
| 506 | _delegate->testException(arg); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 507 | } catch (const apache::thrift::TException& e) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 508 | exn_cob(apache::thrift::TDelayedException::delayException(e)); |
| 509 | return; |
| 510 | } |
| 511 | cob(); |
| 512 | } |
| 513 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 514 | virtual void testMultiException( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 515 | stdcxx::function<void(Xtruct const& _return)> cob, |
| 516 | stdcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 517 | const std::string& arg0, |
| 518 | const std::string& arg1) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 519 | Xtruct res; |
| 520 | try { |
| 521 | _delegate->testMultiException(res, arg0, arg1); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 522 | } catch (const apache::thrift::TException& e) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 523 | exn_cob(apache::thrift::TDelayedException::delayException(e)); |
| 524 | return; |
| 525 | } |
| 526 | cob(res); |
| 527 | } |
| 528 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 529 | virtual void testOneway(stdcxx::function<void()> cob, const int32_t secondsToSleep) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 530 | _delegate->testOneway(secondsToSleep); |
| 531 | cob(); |
| 532 | } |
| 533 | |
| 534 | protected: |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 535 | stdcxx::shared_ptr<TestHandler> _delegate; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 536 | }; |
| 537 | |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 538 | namespace po = boost::program_options; |
| 539 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 540 | int main(int argc, char** argv) { |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 541 | |
Nobuaki Sukegawa | c874408 | 2016-03-09 19:55:56 +0900 | [diff] [blame] | 542 | string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string(); |
| 543 | string certPath = testDir + "/keys/server.crt"; |
| 544 | string keyPath = testDir + "/keys/server.key"; |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 545 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 546 | #if _WIN32 |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 547 | transport::TWinsockSingleton::create(); |
| 548 | #endif |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 549 | int port = 9090; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 550 | bool ssl = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 551 | string transport_type = "buffered"; |
| 552 | string protocol_type = "binary"; |
| 553 | string server_type = "simple"; |
| 554 | string domain_socket = ""; |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 555 | bool abstract_namespace = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 556 | size_t workers = 4; |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 557 | int string_limit = 0; |
| 558 | int container_limit = 0; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 559 | |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 560 | po::options_description desc("Allowed options"); |
| 561 | desc.add_options() |
| 562 | ("help,h", "produce help message") |
| 563 | ("port", po::value<int>(&port)->default_value(port), "Port number to listen") |
| 564 | ("domain-socket", po::value<string>(&domain_socket) ->default_value(domain_socket), "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)") |
| 565 | ("abstract-namespace", "Create the domain socket in the Abstract Namespace (no connection with filesystem pathnames)") |
| 566 | ("server-type", po::value<string>(&server_type)->default_value(server_type), "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"") |
| 567 | ("transport", po::value<string>(&transport_type)->default_value(transport_type), "transport: buffered, framed, http") |
| 568 | ("protocol", po::value<string>(&protocol_type)->default_value(protocol_type), "protocol: binary, compact, header, json") |
| 569 | ("ssl", "Encrypted Transport using SSL") |
| 570 | ("processor-events", "processor-events") |
| 571 | ("workers,n", po::value<size_t>(&workers)->default_value(workers), "Number of thread pools workers. Only valid for thread-pool server type") |
| 572 | ("string-limit", po::value<int>(&string_limit)) |
| 573 | ("container-limit", po::value<int>(&container_limit)); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 574 | |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 575 | po::variables_map vm; |
| 576 | po::store(po::parse_command_line(argc, argv, desc), vm); |
| 577 | po::notify(vm); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 578 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 579 | if (vm.count("help")) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 580 | cout << desc << "\n"; |
| 581 | return 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 582 | } |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 583 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 584 | try { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 585 | if (!server_type.empty()) { |
| 586 | if (server_type == "simple") { |
| 587 | } else if (server_type == "thread-pool") { |
| 588 | } else if (server_type == "threaded") { |
| 589 | } else if (server_type == "nonblocking") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 590 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 591 | throw invalid_argument("Unknown server type " + server_type); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 592 | } |
| 593 | } |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 594 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 595 | if (!protocol_type.empty()) { |
| 596 | if (protocol_type == "binary") { |
Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 597 | } else if (protocol_type == "compact") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 598 | } else if (protocol_type == "json") { |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 599 | } else if (protocol_type == "header") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 600 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 601 | throw invalid_argument("Unknown protocol type " + protocol_type); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 605 | if (!transport_type.empty()) { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 606 | if (transport_type == "buffered") { |
| 607 | } else if (transport_type == "framed") { |
| 608 | } else if (transport_type == "http") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 609 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 610 | throw invalid_argument("Unknown transport type " + transport_type); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 611 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 612 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 613 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 614 | } catch (std::exception& e) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 615 | cerr << e.what() << endl; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 616 | cout << desc << "\n"; |
| 617 | return 1; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 620 | if (vm.count("ssl")) { |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 621 | ssl = true; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 622 | } |
| 623 | |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 624 | if (vm.count("abstract-namespace")) { |
| 625 | abstract_namespace = true; |
| 626 | } |
| 627 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 628 | // Dispatcher |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 629 | stdcxx::shared_ptr<TProtocolFactory> protocolFactory; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 630 | if (protocol_type == "json") { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 631 | stdcxx::shared_ptr<TProtocolFactory> jsonProtocolFactory(new TJSONProtocolFactory()); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 632 | protocolFactory = jsonProtocolFactory; |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 633 | } else if (protocol_type == "compact") { |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 634 | TCompactProtocolFactoryT<TBufferBase> *compactProtocolFactory = new TCompactProtocolFactoryT<TBufferBase>(); |
| 635 | compactProtocolFactory->setContainerSizeLimit(container_limit); |
| 636 | compactProtocolFactory->setStringSizeLimit(string_limit); |
| 637 | protocolFactory.reset(compactProtocolFactory); |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 638 | } else if (protocol_type == "header") { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 639 | stdcxx::shared_ptr<TProtocolFactory> headerProtocolFactory(new THeaderProtocolFactory()); |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 640 | protocolFactory = headerProtocolFactory; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 641 | } else { |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 642 | TBinaryProtocolFactoryT<TBufferBase>* binaryProtocolFactory = new TBinaryProtocolFactoryT<TBufferBase>(); |
| 643 | binaryProtocolFactory->setContainerSizeLimit(container_limit); |
| 644 | binaryProtocolFactory->setStringSizeLimit(string_limit); |
| 645 | protocolFactory.reset(binaryProtocolFactory); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 646 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 647 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 648 | // Processor |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 649 | stdcxx::shared_ptr<TestHandler> testHandler(new TestHandler()); |
| 650 | stdcxx::shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler)); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 651 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 652 | if (vm.count("processor-events")) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 653 | testProcessor->setEventHandler( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 654 | stdcxx::shared_ptr<TProcessorEventHandler>(new TestProcessorEventHandler())); |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 655 | } |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 656 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 657 | // Transport |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 658 | stdcxx::shared_ptr<TSSLSocketFactory> sslSocketFactory; |
| 659 | stdcxx::shared_ptr<TServerSocket> serverSocket; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 660 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 661 | if (ssl) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 662 | sslSocketFactory = stdcxx::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); |
Nobuaki Sukegawa | c874408 | 2016-03-09 19:55:56 +0900 | [diff] [blame] | 663 | sslSocketFactory->loadCertificate(certPath.c_str()); |
| 664 | sslSocketFactory->loadPrivateKey(keyPath.c_str()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 665 | sslSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 666 | serverSocket = stdcxx::shared_ptr<TServerSocket>(new TSSLServerSocket(port, sslSocketFactory)); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 667 | } else { |
Roger Meier | c94b293 | 2014-02-22 20:07:33 +0100 | [diff] [blame] | 668 | if (domain_socket != "") { |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 669 | if (abstract_namespace) { |
| 670 | std::string abstract_socket("\0", 1); |
| 671 | abstract_socket += domain_socket; |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 672 | serverSocket = stdcxx::shared_ptr<TServerSocket>(new TServerSocket(abstract_socket)); |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 673 | } else { |
| 674 | unlink(domain_socket.c_str()); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 675 | serverSocket = stdcxx::shared_ptr<TServerSocket>(new TServerSocket(domain_socket)); |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 676 | } |
Roger Meier | c94b293 | 2014-02-22 20:07:33 +0100 | [diff] [blame] | 677 | port = 0; |
| 678 | } else { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 679 | serverSocket = stdcxx::shared_ptr<TServerSocket>(new TServerSocket(port)); |
Roger Meier | c94b293 | 2014-02-22 20:07:33 +0100 | [diff] [blame] | 680 | } |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 681 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 682 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 683 | // Factory |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 684 | stdcxx::shared_ptr<TTransportFactory> transportFactory; |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 685 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 686 | if (transport_type == "http" && server_type != "nonblocking") { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 687 | stdcxx::shared_ptr<TTransportFactory> httpTransportFactory(new THttpServerTransportFactory()); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 688 | transportFactory = httpTransportFactory; |
| 689 | } else if (transport_type == "framed") { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 690 | stdcxx::shared_ptr<TTransportFactory> framedTransportFactory(new TFramedTransportFactory()); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 691 | transportFactory = framedTransportFactory; |
| 692 | } else { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 693 | stdcxx::shared_ptr<TTransportFactory> bufferedTransportFactory(new TBufferedTransportFactory()); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 694 | transportFactory = bufferedTransportFactory; |
| 695 | } |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 696 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 697 | // Server Info |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 698 | cout << "Starting \"" << server_type << "\" server (" << transport_type << "/" << protocol_type |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 699 | << ") listen on: "; |
| 700 | if (abstract_namespace) { |
| 701 | cout << '@'; |
| 702 | } |
| 703 | cout << domain_socket; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 704 | if (port != 0) { |
| 705 | cout << port; |
| 706 | } |
| 707 | cout << endl; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 708 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 709 | // Server |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 710 | stdcxx::shared_ptr<apache::thrift::server::TServer> server; |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 711 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 712 | if (server_type == "simple") { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 713 | server.reset(new TSimpleServer(testProcessor, serverSocket, transportFactory, protocolFactory)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 714 | } else if (server_type == "thread-pool") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 715 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 716 | stdcxx::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workers); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 717 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 718 | stdcxx::shared_ptr<PlatformThreadFactory> threadFactory |
| 719 | = stdcxx::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory()); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 720 | |
| 721 | threadManager->threadFactory(threadFactory); |
| 722 | |
| 723 | threadManager->start(); |
| 724 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 725 | server.reset(new TThreadPoolServer(testProcessor, |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 726 | serverSocket, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 727 | transportFactory, |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 728 | protocolFactory, |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 729 | threadManager)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 730 | } else if (server_type == "threaded") { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 731 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 732 | server.reset( |
| 733 | new TThreadedServer(testProcessor, serverSocket, transportFactory, protocolFactory)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 734 | } else if (server_type == "nonblocking") { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 735 | if (transport_type == "http") { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 736 | stdcxx::shared_ptr<TestHandlerAsync> testHandlerAsync(new TestHandlerAsync(testHandler)); |
| 737 | stdcxx::shared_ptr<TAsyncProcessor> testProcessorAsync( |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 738 | new ThriftTestAsyncProcessor(testHandlerAsync)); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 739 | stdcxx::shared_ptr<TAsyncBufferProcessor> testBufferProcessor( |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 740 | new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory)); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 741 | |
| 742 | // not loading nonblockingServer into "server" because |
| 743 | // TEvhttpServer doesn't inherit from TServer, and doesn't |
| 744 | // provide a stop method. |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 745 | TEvhttpServer nonblockingServer(testBufferProcessor, port); |
| 746 | nonblockingServer.serve(); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 747 | } else { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 748 | stdcxx::shared_ptr<transport::TNonblockingServerSocket> nbSocket; |
Divya Thaluru | 808d143 | 2017-08-06 16:36:36 -0700 | [diff] [blame] | 749 | nbSocket.reset(new transport::TNonblockingServerSocket(port)); |
| 750 | server.reset(new TNonblockingServer(testProcessor, protocolFactory, nbSocket)); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 751 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 754 | if (server.get() != NULL) { |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 755 | if (protocol_type == "header") { |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 756 | // Tell the server to use the same protocol for input / output |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 757 | // if using header |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 758 | server->setOutputProtocolFactory(stdcxx::shared_ptr<TProtocolFactory>()); |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 759 | } |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 760 | apache::thrift::concurrency::PlatformThreadFactory factory; |
| 761 | factory.setDetached(false); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame^] | 762 | stdcxx::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server); |
| 763 | stdcxx::shared_ptr<apache::thrift::concurrency::Thread> thread |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 764 | = factory.newThread(serverThreadRunner); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 765 | thread->start(); |
| 766 | |
Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 767 | // HACK: cross language test suite is unable to handle cin properly |
| 768 | // that's why we stay in a endless loop here |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 769 | while (1) { |
| 770 | } |
Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 771 | // FIXME: find another way to stop the server (e.g. a signal) |
| 772 | // cout<<"Press enter to stop the server."<<endl; |
| 773 | // cin.ignore(); //wait until a key is pressed |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 774 | |
| 775 | server->stop(); |
| 776 | thread->join(); |
| 777 | server.reset(); |
| 778 | } |
| 779 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 780 | cout << "done." << endl; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 781 | return 0; |
| 782 | } |