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 | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 100 | public Xtruct testStruct(Xtruct thing) |
| 101 | { |
| 102 | Console.WriteLine("testStruct({" + |
| 103 | "\"" + thing.String_thing + "\", " + |
| 104 | thing.Byte_thing + ", " + |
| 105 | thing.I32_thing + ", " + |
| 106 | thing.I64_thing + "})"); |
| 107 | return thing; |
| 108 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 109 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 110 | public Xtruct2 testNest(Xtruct2 nest) |
| 111 | { |
| 112 | Xtruct thing = nest.Struct_thing; |
| 113 | Console.WriteLine("testNest({" + |
| 114 | nest.Byte_thing + ", {" + |
| 115 | "\"" + thing.String_thing + "\", " + |
| 116 | thing.Byte_thing + ", " + |
| 117 | thing.I32_thing + ", " + |
| 118 | thing.I64_thing + "}, " + |
| 119 | nest.I32_thing + "})"); |
| 120 | return nest; |
| 121 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 122 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 123 | public Dictionary<int, int> testMap(Dictionary<int, int> thing) |
| 124 | { |
| 125 | Console.WriteLine("testMap({"); |
| 126 | bool first = true; |
| 127 | foreach (int key in thing.Keys) |
| 128 | { |
| 129 | if (first) |
| 130 | { |
| 131 | first = false; |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | Console.WriteLine(", "); |
| 136 | } |
| 137 | Console.WriteLine(key + " => " + thing[key]); |
| 138 | } |
| 139 | Console.WriteLine("})"); |
| 140 | return thing; |
| 141 | } |
Jens Geyer | 1c99e70 | 2014-03-17 22:50:39 +0200 | [diff] [blame] | 142 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 143 | public Dictionary<string, string> testStringMap(Dictionary<string, string> thing) |
| 144 | { |
| 145 | Console.WriteLine("testStringMap({"); |
| 146 | bool first = true; |
| 147 | foreach (string key in thing.Keys) |
| 148 | { |
| 149 | if (first) |
| 150 | { |
| 151 | first = false; |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | Console.WriteLine(", "); |
| 156 | } |
| 157 | Console.WriteLine(key + " => " + thing[key]); |
| 158 | } |
| 159 | Console.WriteLine("})"); |
| 160 | return thing; |
| 161 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 162 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 163 | public THashSet<int> testSet(THashSet<int> thing) |
| 164 | { |
| 165 | Console.WriteLine("testSet({"); |
| 166 | bool first = true; |
| 167 | foreach (int elem in thing) |
| 168 | { |
| 169 | if (first) |
| 170 | { |
| 171 | first = false; |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | Console.WriteLine(", "); |
| 176 | } |
| 177 | Console.WriteLine(elem); |
| 178 | } |
| 179 | Console.WriteLine("})"); |
| 180 | return thing; |
| 181 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 182 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 183 | public List<int> testList(List<int> thing) |
| 184 | { |
| 185 | Console.WriteLine("testList({"); |
| 186 | bool first = true; |
| 187 | foreach (int elem in thing) |
| 188 | { |
| 189 | if (first) |
| 190 | { |
| 191 | first = false; |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | Console.WriteLine(", "); |
| 196 | } |
| 197 | Console.WriteLine(elem); |
| 198 | } |
| 199 | Console.WriteLine("})"); |
| 200 | return thing; |
| 201 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 202 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 203 | public Numberz testEnum(Numberz thing) |
| 204 | { |
| 205 | Console.WriteLine("testEnum(" + thing + ")"); |
| 206 | return thing; |
| 207 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 208 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 209 | public long testTypedef(long thing) |
| 210 | { |
| 211 | Console.WriteLine("testTypedef(" + thing + ")"); |
| 212 | return thing; |
| 213 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 214 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 215 | public Dictionary<int, Dictionary<int, int>> testMapMap(int hello) |
| 216 | { |
| 217 | Console.WriteLine("testMapMap(" + hello + ")"); |
| 218 | Dictionary<int, Dictionary<int, int>> mapmap = |
| 219 | new Dictionary<int, Dictionary<int, int>>(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 220 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 221 | Dictionary<int, int> pos = new Dictionary<int, int>(); |
| 222 | Dictionary<int, int> neg = new Dictionary<int, int>(); |
| 223 | for (int i = 1; i < 5; i++) |
| 224 | { |
| 225 | pos[i] = i; |
| 226 | neg[-i] = -i; |
| 227 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 228 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 229 | mapmap[4] = pos; |
| 230 | mapmap[-4] = neg; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 231 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 232 | return mapmap; |
| 233 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 234 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 235 | public Dictionary<long, Dictionary<Numberz, Insanity>> testInsanity(Insanity argument) |
| 236 | { |
| 237 | Console.WriteLine("testInsanity()"); |
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 | Xtruct hello = new Xtruct(); |
| 240 | hello.String_thing = "Hello2"; |
| 241 | hello.Byte_thing = 2; |
| 242 | hello.I32_thing = 2; |
| 243 | hello.I64_thing = 2; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 244 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 245 | Xtruct goodbye = new Xtruct(); |
| 246 | goodbye.String_thing = "Goodbye4"; |
| 247 | goodbye.Byte_thing = (sbyte)4; |
| 248 | goodbye.I32_thing = 4; |
| 249 | goodbye.I64_thing = (long)4; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 250 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 251 | Insanity crazy = new Insanity(); |
| 252 | crazy.UserMap = new Dictionary<Numberz, long>(); |
| 253 | crazy.UserMap[Numberz.EIGHT] = (long)8; |
| 254 | crazy.Xtructs = new List<Xtruct>(); |
| 255 | crazy.Xtructs.Add(goodbye); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 256 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 257 | Insanity looney = new Insanity(); |
| 258 | crazy.UserMap[Numberz.FIVE] = (long)5; |
| 259 | crazy.Xtructs.Add(hello); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 260 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 261 | Dictionary<Numberz, Insanity> first_map = new Dictionary<Numberz, Insanity>(); |
| 262 | Dictionary<Numberz, Insanity> second_map = new Dictionary<Numberz, Insanity>(); ; |
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 | first_map[Numberz.TWO] = crazy; |
| 265 | first_map[Numberz.THREE] = crazy; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 266 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 267 | second_map[Numberz.SIX] = looney; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 268 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 269 | Dictionary<long, Dictionary<Numberz, Insanity>> insane = |
| 270 | new Dictionary<long, Dictionary<Numberz, Insanity>>(); |
| 271 | insane[(long)1] = first_map; |
| 272 | insane[(long)2] = second_map; |
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 | return insane; |
| 275 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 276 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 277 | public Xtruct testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5) |
| 278 | { |
| 279 | Console.WriteLine("testMulti()"); |
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 | Xtruct hello = new Xtruct(); ; |
| 282 | hello.String_thing = "Hello2"; |
| 283 | hello.Byte_thing = arg0; |
| 284 | hello.I32_thing = arg1; |
| 285 | hello.I64_thing = arg2; |
| 286 | return hello; |
| 287 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 288 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 289 | public void testException(string arg) |
| 290 | { |
| 291 | Console.WriteLine("testException(" + arg + ")"); |
| 292 | if (arg == "Xception") |
| 293 | { |
| 294 | Xception x = new Xception(); |
| 295 | x.ErrorCode = 1001; |
| 296 | x.Message = "This is an Xception"; |
| 297 | throw x; |
| 298 | } |
| 299 | return; |
| 300 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 301 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 302 | public Xtruct testMultiException(string arg0, string arg1) |
| 303 | { |
| 304 | Console.WriteLine("testMultiException(" + arg0 + ", " + arg1 + ")"); |
| 305 | if (arg0 == "Xception") |
| 306 | { |
| 307 | Xception x = new Xception(); |
| 308 | x.ErrorCode = 1001; |
| 309 | x.Message = "This is an Xception"; |
| 310 | throw x; |
| 311 | } |
| 312 | else if (arg0 == "Xception2") |
| 313 | { |
| 314 | Xception2 x = new Xception2(); |
| 315 | x.ErrorCode = 2002; |
| 316 | x.Struct_thing = new Xtruct(); |
| 317 | x.Struct_thing.String_thing = "This is an Xception2"; |
| 318 | throw x; |
| 319 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 320 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 321 | Xtruct result = new Xtruct(); |
| 322 | result.String_thing = arg1; |
| 323 | return result; |
| 324 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 325 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 326 | public void testStop() |
| 327 | { |
| 328 | if (server != null) |
| 329 | { |
| 330 | server.Stop(); |
| 331 | } |
| 332 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 333 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 334 | public void testOneway(int arg) |
| 335 | { |
| 336 | Console.WriteLine("testOneway(" + arg + "), sleeping..."); |
| 337 | System.Threading.Thread.Sleep(arg * 1000); |
| 338 | Console.WriteLine("testOneway finished"); |
| 339 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 340 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 341 | } // class TestHandler |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 342 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 343 | public static void Execute(string[] args) |
| 344 | { |
| 345 | try |
| 346 | { |
| 347 | bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false; |
| 348 | int port = 9090; |
| 349 | string pipe = null; |
| 350 | for (int i = 0; i < args.Length; i++) |
| 351 | { |
| 352 | if (args[i] == "-pipe") // -pipe name |
| 353 | { |
| 354 | pipe = args[++i]; |
| 355 | } |
| 356 | else if (args[i].Contains("--port=")) |
| 357 | { |
| 358 | port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1)); |
| 359 | } |
| 360 | else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") |
| 361 | { |
| 362 | useBufferedSockets = true; |
| 363 | } |
| 364 | else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") |
| 365 | { |
| 366 | useFramed = true; |
| 367 | } |
| 368 | else if (args[i] == "--compact" || args[i] == "--protocol=compact") |
| 369 | { |
| 370 | compact = true; |
| 371 | } |
| 372 | else if (args[i] == "--json" || args[i] == "--protocol=json") |
| 373 | { |
| 374 | json = true; |
| 375 | } |
| 376 | else if (args[i] == "--ssl") |
| 377 | { |
| 378 | useEncryption = true; |
| 379 | } |
| 380 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 381 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 382 | // Processor |
| 383 | TestHandler testHandler = new TestHandler(); |
| 384 | ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 385 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 386 | // Transport |
| 387 | TServerTransport trans; |
| 388 | if( pipe != null) |
| 389 | { |
| 390 | trans = new TNamedPipeServerTransport(pipe); |
| 391 | } |
| 392 | else |
| 393 | { |
| 394 | if (useEncryption) |
| 395 | { |
| 396 | trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2("../../../../../keys/server.pem")); |
| 397 | } |
| 398 | else |
| 399 | { |
| 400 | trans = new TServerSocket(port, 0, useBufferedSockets); |
| 401 | } |
| 402 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 403 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 404 | TProtocolFactory proto; |
| 405 | if ( compact ) |
| 406 | proto = new TCompactProtocol.Factory(); |
| 407 | else if ( json ) |
| 408 | proto = new TJSONProtocol.Factory(); |
| 409 | else |
| 410 | proto = new TBinaryProtocol.Factory(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 411 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 412 | // Simple Server |
| 413 | TServer serverEngine; |
| 414 | if ( useFramed ) |
| 415 | serverEngine = new TSimpleServer(testProcessor, trans, new TFramedTransport.Factory(), proto); |
| 416 | else |
| 417 | serverEngine = new TSimpleServer(testProcessor, trans, new TTransportFactory(), proto); |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 418 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 419 | // ThreadPool Server |
| 420 | // serverEngine = new TThreadPoolServer(testProcessor, tServerSocket); |
| 421 | |
| 422 | // Threaded Server |
| 423 | // serverEngine = new TThreadedServer(testProcessor, tServerSocket); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 424 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 425 | //Server event handler |
| 426 | TradeServerEventHandler serverEvents = new TradeServerEventHandler(); |
| 427 | serverEngine.setEventHandler(serverEvents); |
| 428 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 429 | testHandler.server = serverEngine; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 430 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 431 | // Run it |
| 432 | string where = ( pipe != null ? "on pipe "+pipe : "on port " + port); |
| 433 | Console.WriteLine("Starting the server " + where + |
| 434 | (useBufferedSockets ? " with buffered socket" : "") + |
| 435 | (useFramed ? " with framed transport" : "") + |
| 436 | (useEncryption ? " with encryption" : "") + |
| 437 | (compact ? " with compact protocol" : "") + |
| 438 | (json ? " with json protocol" : "") + |
| 439 | "..."); |
| 440 | serverEngine.Serve(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 441 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 442 | } |
| 443 | catch (Exception x) |
| 444 | { |
| 445 | Console.Error.Write(x); |
| 446 | } |
| 447 | Console.WriteLine("done."); |
| 448 | } |
| 449 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 450 | } |