Skip to content

Commit

Permalink
Only use NIOSSL on macOS and Linux (#101) (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
obriensp authored Feb 15, 2022
1 parent 82f8380 commit ca8af7a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions Sources/MQTTNIO/MQTTClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the MQTTNIO project
//
// Copyright (c) 2020-2021 Adam Fowler
// Copyright (c) 2020-2022 Adam Fowler
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand Down Expand Up @@ -121,7 +121,8 @@ public final class MQTTClient {
case .createNew:
#if canImport(Network)
switch configuration.tlsConfiguration {
#if canImport(NIOSSL)
// This should use canImport(NIOSSL), will change when it works with SwiftUI previews.
#if os(macOS) || os(Linux)
case .niossl:
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
#endif
Expand Down
5 changes: 3 additions & 2 deletions Sources/MQTTNIO/MQTTConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the MQTTNIO project
//
// Copyright (c) 2020-2021 Adam Fowler
// Copyright (c) 2020-2022 Adam Fowler
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand All @@ -28,7 +28,8 @@ extension MQTTClient {
/// It is recommended on iOS you use NIO Transport Services.
public enum TLSConfigurationType {
/// NIOSSL TLS configuration
#if canImport(NIOSSL)
// This should use canImport(NIOSSL), will change when it works with SwiftUI previews.
#if os(macOS) || os(Linux)
case niossl(TLSConfiguration)
#endif
#if canImport(Network)
Expand Down
8 changes: 5 additions & 3 deletions Sources/MQTTNIO/MQTTConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the MQTTNIO project
//
// Copyright (c) 2020-2021 Adam Fowler
// Copyright (c) 2020-2022 Adam Fowler
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand Down Expand Up @@ -96,7 +96,8 @@ final class MQTTConnection {
switch client.configuration.tlsConfiguration {
case .ts(let config):
options = try config.getNWProtocolTLSOptions()
#if canImport(NIOSSL)
// This should use canImport(NIOSSL), will change when it works with SwiftUI previews.
#if os(macOS) || os(Linux)
case .niossl:
throw MQTTError.wrongTLSConfig
#endif
Expand All @@ -112,7 +113,8 @@ final class MQTTConnection {
return bootstrap
}
#endif
#if canImport(NIOSSL) // canImport(Network)
// This should use canImport(NIOSSL), will change when it works with SwiftUI previews.
#if os(macOS) || os(Linux) // canImport(Network)
if let clientBootstrap = ClientBootstrap(validatingGroup: client.eventLoopGroup) {
let tlsConfiguration: TLSConfiguration
switch client.configuration.tlsConfiguration {
Expand Down
5 changes: 3 additions & 2 deletions Sources/MQTTNIO/TSTLSConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the MQTTNIO project
//
// Copyright (c) 2020-2021 Adam Fowler
// Copyright (c) 2020-2022 Adam Fowler
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand Down Expand Up @@ -98,7 +98,8 @@ public struct TSTLSConfiguration {
/// Create certificate array from already loaded SecCertificate array
public static func certificates(_ secCertificates: [SecCertificate]) -> Self { .init(certificates: secCertificates) }

#if canImport(NIOSSL)
// This should use canImport(NIOSSL), will change when it works with SwiftUI previews.
#if os(macOS) || os(Linux)
/// Create certificate array from PEM file
public static func pem(_ filename: String) throws -> Self {
let certificates = try NIOSSLCertificate.fromPEMFile(filename)
Expand Down

0 comments on commit ca8af7a

Please sign in to comment.