Kino Roy | a9da9eb | 2022-10-07 23:13:01 -0700 | [diff] [blame] | 1 | // Licensed to the Apache Software Foundation (ASF) under one |
| 2 | // or more contributor license agreements. See the NOTICE file |
| 3 | // distributed with this work for additional information |
| 4 | // regarding copyright ownership. The ASF licenses this file |
| 5 | // to you under the Apache License, Version 2.0 (the |
| 6 | // "License"); you may not use this file except in compliance |
| 7 | // with the License. You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, |
| 12 | // software distributed under the License is distributed on an |
| 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | // KIND, either express or implied. See the License for the |
| 15 | // specific language governing permissions and limitations |
| 16 | // under the License. |
| 17 | |
| 18 | import Foundation |
| 19 | import Thrift |
| 20 | import Common |
| 21 | |
| 22 | class TestServer { |
| 23 | var server: Any? |
| 24 | |
| 25 | func run() throws { |
| 26 | let parameters = try TestServerParameters(arguments: CommandLine.arguments) |
| 27 | |
| 28 | if parameters.showHelp { |
| 29 | parameters.printHelp() |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | let service = ThriftTestImpl() |
| 34 | let processor = ThriftTestProcessor(service: service) |
| 35 | |
| 36 | |
Kino Roy | 29d8773 | 2023-02-20 22:32:43 -0800 | [diff] [blame^] | 37 | switch (parameters.proto, parameters.transport, parameters.domainSocket) { |
| 38 | case (.binary, .buffered, .none): |
Kino Roy | a9da9eb | 2022-10-07 23:13:01 -0700 | [diff] [blame] | 39 | let proto = TBinaryProtocol.self |
| 40 | server = try TSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor) |
Kino Roy | 29d8773 | 2023-02-20 22:32:43 -0800 | [diff] [blame^] | 41 | case (.binary, .framed, .none): |
Kino Roy | a9da9eb | 2022-10-07 23:13:01 -0700 | [diff] [blame] | 42 | let proto = TBinaryProtocol.self |
| 43 | server = try TFramedSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor) |
Kino Roy | 29d8773 | 2023-02-20 22:32:43 -0800 | [diff] [blame^] | 44 | case (.compact, .buffered, .none): |
Kino Roy | a9da9eb | 2022-10-07 23:13:01 -0700 | [diff] [blame] | 45 | let proto = TCompactProtocol.self |
| 46 | server = try TSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor) |
Kino Roy | 29d8773 | 2023-02-20 22:32:43 -0800 | [diff] [blame^] | 47 | case (.compact, .framed, .none): |
Kino Roy | a9da9eb | 2022-10-07 23:13:01 -0700 | [diff] [blame] | 48 | let proto = TCompactProtocol.self |
| 49 | server = try TFramedSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor) |
Kino Roy | 29d8773 | 2023-02-20 22:32:43 -0800 | [diff] [blame^] | 50 | case (.binary, .buffered, .some(let domainSocket)): |
| 51 | let proto = TBinaryProtocol.self |
| 52 | server = try TSocketServer(path: domainSocket, inProtocol: proto, outProtocol: proto, processor: processor) |
| 53 | case (.binary, .framed, .some(let domainSocket)): |
| 54 | let proto = TBinaryProtocol.self |
| 55 | server = try TFramedSocketServer(path: domainSocket, inProtocol: proto, outProtocol: proto, processor: processor) |
| 56 | case (.compact, .buffered, .some(let domainSocket)): |
| 57 | let proto = TCompactProtocol.self |
| 58 | server = try TSocketServer(path: domainSocket, inProtocol: proto, outProtocol: proto, processor: processor) |
| 59 | case (.compact, .framed, .some(let domainSocket)): |
| 60 | let proto = TCompactProtocol.self |
| 61 | server = try TFramedSocketServer(path: domainSocket, inProtocol: proto, outProtocol: proto, processor: processor) |
Kino Roy | a9da9eb | 2022-10-07 23:13:01 -0700 | [diff] [blame] | 62 | default: |
| 63 | throw ParserError.unsupportedOption |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | let server = TestServer() |
| 69 | try server.run() |
| 70 | |
| 71 | RunLoop.main.run() |