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