blob: 433bde7021e4c6ea4c07e7a4430b95db265d2ead [file] [log] [blame]
Kino Roya9da9eb2022-10-07 23:13:01 -07001// 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
18import Foundation
19import Thrift
20import Common
21
22class 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 Roy29d87732023-02-20 22:32:43 -080037 switch (parameters.proto, parameters.transport, parameters.domainSocket) {
38 case (.binary, .buffered, .none):
Kino Roya9da9eb2022-10-07 23:13:01 -070039 let proto = TBinaryProtocol.self
40 server = try TSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor)
Kino Roy29d87732023-02-20 22:32:43 -080041 case (.binary, .framed, .none):
Kino Roya9da9eb2022-10-07 23:13:01 -070042 let proto = TBinaryProtocol.self
43 server = try TFramedSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor)
Kino Roy29d87732023-02-20 22:32:43 -080044 case (.compact, .buffered, .none):
Kino Roya9da9eb2022-10-07 23:13:01 -070045 let proto = TCompactProtocol.self
46 server = try TSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor)
Kino Roy29d87732023-02-20 22:32:43 -080047 case (.compact, .framed, .none):
Kino Roya9da9eb2022-10-07 23:13:01 -070048 let proto = TCompactProtocol.self
49 server = try TFramedSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor)
Kino Roy29d87732023-02-20 22:32:43 -080050 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 Roya9da9eb2022-10-07 23:13:01 -070062 default:
63 throw ParserError.unsupportedOption
64 }
65 }
66}
67
68let server = TestServer()
69try server.run()
70
71RunLoop.main.run()