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 | |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 20 | // Distributed under the Thrift Software License |
| 21 | // |
| 22 | // See accompanying file LICENSE or visit the Thrift site at: |
| 23 | // http://developers.facebook.com/thrift/ |
| 24 | using System; |
| 25 | using System.Collections.Generic; |
Jens Geyer | c1d7943 | 2014-04-22 22:52:43 +0200 | [diff] [blame] | 26 | using System.Security.Cryptography.X509Certificates; |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 27 | using Thrift.Collections; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 28 | using Thrift.Test; //generated code |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 29 | using Thrift.Transport; |
| 30 | using Thrift.Protocol; |
| 31 | using Thrift.Server; |
| 32 | |
| 33 | namespace Test |
| 34 | { |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 35 | public class TestServer |
| 36 | { |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 37 | public class TradeServerEventHandler : TServerEventHandler |
| 38 | { |
| 39 | public int callCount = 0; |
| 40 | public void preServe() |
| 41 | { |
| 42 | callCount++; |
| 43 | } |
| 44 | public Object createContext(Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output) |
| 45 | { |
| 46 | callCount++; |
| 47 | return null; |
| 48 | } |
| 49 | public void deleteContext(Object serverContext, Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output) |
| 50 | { |
| 51 | callCount++; |
| 52 | } |
| 53 | public void processContext(Object serverContext, Thrift.Transport.TTransport transport) |
| 54 | { |
| 55 | callCount++; |
| 56 | } |
| 57 | }; |
| 58 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 59 | public class TestHandler : ThriftTest.Iface |
| 60 | { |
| 61 | public TServer server; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 62 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 63 | public TestHandler() { } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 64 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 65 | public void testVoid() |
| 66 | { |
| 67 | Console.WriteLine("testVoid()"); |
| 68 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 69 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 70 | public string testString(string thing) |
| 71 | { |
| 72 | Console.WriteLine("teststring(\"" + thing + "\")"); |
| 73 | return thing; |
| 74 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 75 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 76 | public sbyte testByte(sbyte thing) |
| 77 | { |
| 78 | Console.WriteLine("testByte(" + thing + ")"); |
| 79 | return thing; |
| 80 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 81 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 82 | public int testI32(int thing) |
| 83 | { |
| 84 | Console.WriteLine("testI32(" + thing + ")"); |
| 85 | return thing; |
| 86 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 87 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 88 | public long testI64(long thing) |
| 89 | { |
| 90 | Console.WriteLine("testI64(" + thing + ")"); |
| 91 | return thing; |
| 92 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 93 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 94 | public double testDouble(double thing) |
| 95 | { |
| 96 | Console.WriteLine("testDouble(" + thing + ")"); |
| 97 | return thing; |
| 98 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 99 | |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 100 | public byte[] testBinary(byte[] thing) |
| 101 | { |
| 102 | string hex = BitConverter.ToString(thing).Replace("-", string.Empty); |
| 103 | Console.WriteLine("testBinary(" + hex + ")"); |
| 104 | return thing; |
| 105 | } |
| 106 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 107 | public Xtruct testStruct(Xtruct thing) |
| 108 | { |
| 109 | Console.WriteLine("testStruct({" + |
| 110 | "\"" + thing.String_thing + "\", " + |
| 111 | thing.Byte_thing + ", " + |
| 112 | thing.I32_thing + ", " + |
| 113 | thing.I64_thing + "})"); |
| 114 | return thing; |
| 115 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 116 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 117 | public Xtruct2 testNest(Xtruct2 nest) |
| 118 | { |
| 119 | Xtruct thing = nest.Struct_thing; |
| 120 | Console.WriteLine("testNest({" + |
| 121 | nest.Byte_thing + ", {" + |
| 122 | "\"" + thing.String_thing + "\", " + |
| 123 | thing.Byte_thing + ", " + |
| 124 | thing.I32_thing + ", " + |
| 125 | thing.I64_thing + "}, " + |
| 126 | nest.I32_thing + "})"); |
| 127 | return nest; |
| 128 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 129 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 130 | public Dictionary<int, int> testMap(Dictionary<int, int> thing) |
| 131 | { |
| 132 | Console.WriteLine("testMap({"); |
| 133 | bool first = true; |
| 134 | foreach (int key in thing.Keys) |
| 135 | { |
| 136 | if (first) |
| 137 | { |
| 138 | first = false; |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | Console.WriteLine(", "); |
| 143 | } |
| 144 | Console.WriteLine(key + " => " + thing[key]); |
| 145 | } |
| 146 | Console.WriteLine("})"); |
| 147 | return thing; |
| 148 | } |
Jens Geyer | 1c99e70 | 2014-03-17 22:50:39 +0200 | [diff] [blame] | 149 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 150 | public Dictionary<string, string> testStringMap(Dictionary<string, string> thing) |
| 151 | { |
| 152 | Console.WriteLine("testStringMap({"); |
| 153 | bool first = true; |
| 154 | foreach (string key in thing.Keys) |
| 155 | { |
| 156 | if (first) |
| 157 | { |
| 158 | first = false; |
| 159 | } |
| 160 | else |
| 161 | { |
| 162 | Console.WriteLine(", "); |
| 163 | } |
| 164 | Console.WriteLine(key + " => " + thing[key]); |
| 165 | } |
| 166 | Console.WriteLine("})"); |
| 167 | return thing; |
| 168 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 169 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 170 | public THashSet<int> testSet(THashSet<int> thing) |
| 171 | { |
| 172 | Console.WriteLine("testSet({"); |
| 173 | bool first = true; |
| 174 | foreach (int elem in thing) |
| 175 | { |
| 176 | if (first) |
| 177 | { |
| 178 | first = false; |
| 179 | } |
| 180 | else |
| 181 | { |
| 182 | Console.WriteLine(", "); |
| 183 | } |
| 184 | Console.WriteLine(elem); |
| 185 | } |
| 186 | Console.WriteLine("})"); |
| 187 | return thing; |
| 188 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 189 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 190 | public List<int> testList(List<int> thing) |
| 191 | { |
| 192 | Console.WriteLine("testList({"); |
| 193 | bool first = true; |
| 194 | foreach (int elem in thing) |
| 195 | { |
| 196 | if (first) |
| 197 | { |
| 198 | first = false; |
| 199 | } |
| 200 | else |
| 201 | { |
| 202 | Console.WriteLine(", "); |
| 203 | } |
| 204 | Console.WriteLine(elem); |
| 205 | } |
| 206 | Console.WriteLine("})"); |
| 207 | return thing; |
| 208 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 209 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 210 | public Numberz testEnum(Numberz thing) |
| 211 | { |
| 212 | Console.WriteLine("testEnum(" + thing + ")"); |
| 213 | return thing; |
| 214 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 215 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 216 | public long testTypedef(long thing) |
| 217 | { |
| 218 | Console.WriteLine("testTypedef(" + thing + ")"); |
| 219 | return thing; |
| 220 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 221 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 222 | public Dictionary<int, Dictionary<int, int>> testMapMap(int hello) |
| 223 | { |
| 224 | Console.WriteLine("testMapMap(" + hello + ")"); |
| 225 | Dictionary<int, Dictionary<int, int>> mapmap = |
| 226 | new Dictionary<int, Dictionary<int, int>>(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 227 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 228 | Dictionary<int, int> pos = new Dictionary<int, int>(); |
| 229 | Dictionary<int, int> neg = new Dictionary<int, int>(); |
| 230 | for (int i = 1; i < 5; i++) |
| 231 | { |
| 232 | pos[i] = i; |
| 233 | neg[-i] = -i; |
| 234 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 235 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 236 | mapmap[4] = pos; |
| 237 | mapmap[-4] = neg; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 238 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 239 | return mapmap; |
| 240 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 241 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 242 | public Dictionary<long, Dictionary<Numberz, Insanity>> testInsanity(Insanity argument) |
| 243 | { |
| 244 | Console.WriteLine("testInsanity()"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 245 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 246 | Xtruct hello = new Xtruct(); |
| 247 | hello.String_thing = "Hello2"; |
| 248 | hello.Byte_thing = 2; |
| 249 | hello.I32_thing = 2; |
| 250 | hello.I64_thing = 2; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 251 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 252 | Xtruct goodbye = new Xtruct(); |
| 253 | goodbye.String_thing = "Goodbye4"; |
| 254 | goodbye.Byte_thing = (sbyte)4; |
| 255 | goodbye.I32_thing = 4; |
| 256 | goodbye.I64_thing = (long)4; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 257 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 258 | Insanity crazy = new Insanity(); |
| 259 | crazy.UserMap = new Dictionary<Numberz, long>(); |
| 260 | crazy.UserMap[Numberz.EIGHT] = (long)8; |
| 261 | crazy.Xtructs = new List<Xtruct>(); |
| 262 | crazy.Xtructs.Add(goodbye); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 263 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 264 | Insanity looney = new Insanity(); |
| 265 | crazy.UserMap[Numberz.FIVE] = (long)5; |
| 266 | crazy.Xtructs.Add(hello); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 267 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 268 | Dictionary<Numberz, Insanity> first_map = new Dictionary<Numberz, Insanity>(); |
| 269 | Dictionary<Numberz, Insanity> second_map = new Dictionary<Numberz, Insanity>(); ; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 270 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 271 | first_map[Numberz.TWO] = crazy; |
| 272 | first_map[Numberz.THREE] = crazy; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 273 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 274 | second_map[Numberz.SIX] = looney; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 275 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 276 | Dictionary<long, Dictionary<Numberz, Insanity>> insane = |
| 277 | new Dictionary<long, Dictionary<Numberz, Insanity>>(); |
| 278 | insane[(long)1] = first_map; |
| 279 | insane[(long)2] = second_map; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 280 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 281 | return insane; |
| 282 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 283 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 284 | public Xtruct testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5) |
| 285 | { |
| 286 | Console.WriteLine("testMulti()"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 287 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 288 | Xtruct hello = new Xtruct(); ; |
| 289 | hello.String_thing = "Hello2"; |
| 290 | hello.Byte_thing = arg0; |
| 291 | hello.I32_thing = arg1; |
| 292 | hello.I64_thing = arg2; |
| 293 | return hello; |
| 294 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 295 | |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 296 | /** |
| 297 | * Print 'testException(%s)' with arg as '%s' |
| 298 | * @param string arg - a string indication what type of exception to throw |
| 299 | * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg |
| 300 | * elsen if arg == "TException" throw TException |
| 301 | * else do not throw anything |
| 302 | */ |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 303 | public void testException(string arg) |
| 304 | { |
| 305 | Console.WriteLine("testException(" + arg + ")"); |
| 306 | if (arg == "Xception") |
| 307 | { |
| 308 | Xception x = new Xception(); |
| 309 | x.ErrorCode = 1001; |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 310 | x.Message = arg; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 311 | throw x; |
| 312 | } |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 313 | if (arg == "TException") |
| 314 | { |
| 315 | throw new Thrift.TException(); |
| 316 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 317 | return; |
| 318 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 319 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 320 | public Xtruct testMultiException(string arg0, string arg1) |
| 321 | { |
| 322 | Console.WriteLine("testMultiException(" + arg0 + ", " + arg1 + ")"); |
| 323 | if (arg0 == "Xception") |
| 324 | { |
| 325 | Xception x = new Xception(); |
| 326 | x.ErrorCode = 1001; |
| 327 | x.Message = "This is an Xception"; |
| 328 | throw x; |
| 329 | } |
| 330 | else if (arg0 == "Xception2") |
| 331 | { |
| 332 | Xception2 x = new Xception2(); |
| 333 | x.ErrorCode = 2002; |
| 334 | x.Struct_thing = new Xtruct(); |
| 335 | x.Struct_thing.String_thing = "This is an Xception2"; |
| 336 | throw x; |
| 337 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 338 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 339 | Xtruct result = new Xtruct(); |
| 340 | result.String_thing = arg1; |
| 341 | return result; |
| 342 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 343 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 344 | public void testStop() |
| 345 | { |
| 346 | if (server != null) |
| 347 | { |
| 348 | server.Stop(); |
| 349 | } |
| 350 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 351 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 352 | public void testOneway(int arg) |
| 353 | { |
| 354 | Console.WriteLine("testOneway(" + arg + "), sleeping..."); |
| 355 | System.Threading.Thread.Sleep(arg * 1000); |
| 356 | Console.WriteLine("testOneway finished"); |
| 357 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 358 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 359 | } // class TestHandler |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 360 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 361 | public static bool Execute(string[] args) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 362 | { |
| 363 | try |
| 364 | { |
| 365 | bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false; |
| 366 | int port = 9090; |
| 367 | string pipe = null; |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 368 | string certPath = "../../../../../keys/server.pem"; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 369 | for (int i = 0; i < args.Length; i++) |
| 370 | { |
| 371 | if (args[i] == "-pipe") // -pipe name |
| 372 | { |
| 373 | pipe = args[++i]; |
| 374 | } |
| 375 | else if (args[i].Contains("--port=")) |
| 376 | { |
| 377 | port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1)); |
| 378 | } |
| 379 | else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") |
| 380 | { |
| 381 | useBufferedSockets = true; |
| 382 | } |
| 383 | else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") |
| 384 | { |
| 385 | useFramed = true; |
| 386 | } |
| 387 | else if (args[i] == "--compact" || args[i] == "--protocol=compact") |
| 388 | { |
| 389 | compact = true; |
| 390 | } |
| 391 | else if (args[i] == "--json" || args[i] == "--protocol=json") |
| 392 | { |
| 393 | json = true; |
| 394 | } |
| 395 | else if (args[i] == "--ssl") |
| 396 | { |
| 397 | useEncryption = true; |
| 398 | } |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 399 | else if (args[i].StartsWith("--cert=")) |
| 400 | { |
| 401 | certPath = args[i].Substring("--cert=".Length); |
| 402 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 403 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 404 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 405 | // Processor |
| 406 | TestHandler testHandler = new TestHandler(); |
| 407 | ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 408 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 409 | // Transport |
| 410 | TServerTransport trans; |
| 411 | if( pipe != null) |
| 412 | { |
| 413 | trans = new TNamedPipeServerTransport(pipe); |
| 414 | } |
| 415 | else |
| 416 | { |
| 417 | if (useEncryption) |
| 418 | { |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 419 | trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath)); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 420 | } |
| 421 | else |
| 422 | { |
| 423 | trans = new TServerSocket(port, 0, useBufferedSockets); |
| 424 | } |
| 425 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 426 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 427 | TProtocolFactory proto; |
| 428 | if ( compact ) |
| 429 | proto = new TCompactProtocol.Factory(); |
| 430 | else if ( json ) |
| 431 | proto = new TJSONProtocol.Factory(); |
| 432 | else |
| 433 | proto = new TBinaryProtocol.Factory(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 434 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 435 | // Simple Server |
| 436 | TServer serverEngine; |
| 437 | if ( useFramed ) |
| 438 | serverEngine = new TSimpleServer(testProcessor, trans, new TFramedTransport.Factory(), proto); |
| 439 | else |
| 440 | serverEngine = new TSimpleServer(testProcessor, trans, new TTransportFactory(), proto); |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 441 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 442 | // ThreadPool Server |
| 443 | // serverEngine = new TThreadPoolServer(testProcessor, tServerSocket); |
| 444 | |
| 445 | // Threaded Server |
| 446 | // serverEngine = new TThreadedServer(testProcessor, tServerSocket); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 447 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 448 | //Server event handler |
| 449 | TradeServerEventHandler serverEvents = new TradeServerEventHandler(); |
| 450 | serverEngine.setEventHandler(serverEvents); |
| 451 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 452 | testHandler.server = serverEngine; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 453 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 454 | // Run it |
| 455 | string where = ( pipe != null ? "on pipe "+pipe : "on port " + port); |
| 456 | Console.WriteLine("Starting the server " + where + |
| 457 | (useBufferedSockets ? " with buffered socket" : "") + |
| 458 | (useFramed ? " with framed transport" : "") + |
| 459 | (useEncryption ? " with encryption" : "") + |
| 460 | (compact ? " with compact protocol" : "") + |
| 461 | (json ? " with json protocol" : "") + |
| 462 | "..."); |
| 463 | serverEngine.Serve(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 464 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 465 | } |
| 466 | catch (Exception x) |
| 467 | { |
| 468 | Console.Error.Write(x); |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 469 | return false; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 470 | } |
| 471 | Console.WriteLine("done."); |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 472 | return true; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 473 | } |
| 474 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 475 | } |