diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2023-12-19 13:13:46 -0700 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2023-12-19 13:13:46 -0700 |
commit | 6a21acca8a294df4bf113d7c11863733ff84336c (patch) | |
tree | 99f7b76d7805372ef74ead0779fb5c5c40d8cf06 /Sources/swiftGopherClient | |
parent | 5ec43b20006a21e011af28c08ad4b3c15b17111a (diff) |
Platform check for linux1.1.1
Diffstat (limited to 'Sources/swiftGopherClient')
-rw-r--r-- | Sources/swiftGopherClient/gopherClient.swift | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/Sources/swiftGopherClient/gopherClient.swift b/Sources/swiftGopherClient/gopherClient.swift index e44bfcf..802d646 100644 --- a/Sources/swiftGopherClient/gopherClient.swift +++ b/Sources/swiftGopherClient/gopherClient.swift @@ -20,11 +20,15 @@ public class GopherClient { /// /// It automatically chooses the appropriate `EventLoopGroup` based on the running platform. public init() { - if #available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, visionOS 1.0, *) { - self.group = NIOTSEventLoopGroup() - } else { + #if os(Linux) self.group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount) - } + #else + if #available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, visionOS 1.0, *) { + self.group = NIOTSEventLoopGroup() + } else { + self.group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount) + } + #endif } deinit { @@ -44,8 +48,8 @@ public class GopherClient { to host: String, port: Int = 70, message: String, completion: @escaping (Result<[gopherItem], Error>) -> Void ) { - if #available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, visionOS 1.0, *) { - let bootstrap = NIOTSConnectionBootstrap(group: group) + #if os(Linux) + let bootstrap = ClientBootstrap(group: group) .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) .channelInitializer { channel in channel.pipeline.addHandler( @@ -61,24 +65,44 @@ public class GopherClient { completion(.failure(error)) } } - } else { - let bootstrap = ClientBootstrap(group: group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .channelInitializer { channel in - channel.pipeline.addHandler( - GopherRequestResponseHandler(message: message, completion: completion)) + #else + + if #available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, visionOS 1.0, *) { + let bootstrap = NIOTSConnectionBootstrap(group: group) + .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelInitializer { channel in + channel.pipeline.addHandler( + GopherRequestResponseHandler(message: message, completion: completion)) + } + bootstrap.connect(host: host, port: port).whenComplete { result in + switch result { + case .success(let channel): + channel.closeFuture.whenComplete { _ in + print("Connection closed") + } + case .failure(let error): + completion(.failure(error)) + } } - bootstrap.connect(host: host, port: port).whenComplete { result in - switch result { - case .success(let channel): - channel.closeFuture.whenComplete { _ in - print("Connection closed") + } else { + let bootstrap = ClientBootstrap(group: group) + .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelInitializer { channel in + channel.pipeline.addHandler( + GopherRequestResponseHandler(message: message, completion: completion)) + } + bootstrap.connect(host: host, port: port).whenComplete { result in + switch result { + case .success(let channel): + channel.closeFuture.whenComplete { _ in + print("Connection closed") + } + case .failure(let error): + completion(.failure(error)) } - case .failure(let error): - completion(.failure(error)) } } - } + #endif } |