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