Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Sources/MQTTNIO/AsyncAwaitSupport/Sendable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the MQTTNIO project
//
// Copyright (c) 2020-2021 Adam Fowler
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.6)
public typealias _MQTTSendable = Sendable
#else
public typealias _MQTTSendable = Any
#endif
6 changes: 6 additions & 0 deletions Sources/MQTTNIO/MQTTClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,9 @@ extension Logger {
return logger
}
}

#if compiler(>=5.6)
// All public members of the class are immutable and the class manages access to the
// internal mutable state via Locks
extension MQTTClient: @unchecked Sendable {}
#endif
18 changes: 11 additions & 7 deletions Sources/MQTTNIO/MQTTCoreTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
//
//===----------------------------------------------------------------------===//

import NIO
#if compiler(>=5.6)
@preconcurrency import NIOCore
#else
import NIOCore
#endif

public enum MQTTQoS: UInt8 {
public enum MQTTQoS: UInt8, _MQTTSendable {
/// fire and forget
case atMostOnce = 0
/// wait for PUBACK, if you don't receive it after a period of time retry sending
Expand All @@ -22,7 +26,7 @@ public enum MQTTQoS: UInt8 {
case exactlyOnce = 2
}

public enum MQTTPacketType: UInt8 {
public enum MQTTPacketType: UInt8, _MQTTSendable {
case CONNECT = 0x10
case CONNACK = 0x20
case PUBLISH = 0x30
Expand All @@ -41,7 +45,7 @@ public enum MQTTPacketType: UInt8 {
}

/// MQTT PUBLISH packet parameters.
public struct MQTTPublishInfo {
public struct MQTTPublishInfo: _MQTTSendable {
/// Quality of Service for message.
public let qos: MQTTQoS

Expand Down Expand Up @@ -73,7 +77,7 @@ public struct MQTTPublishInfo {
}

/// MQTT SUBSCRIBE packet parameters.
public struct MQTTSubscribeInfo {
public struct MQTTSubscribeInfo: _MQTTSendable {
/// Topic filter to subscribe to.
public let topicFilter: String

Expand All @@ -89,8 +93,8 @@ public struct MQTTSubscribeInfo {
/// MQTT Sub ACK
///
/// Contains data returned in subscribe ack packets
public struct MQTTSuback {
public enum ReturnCode: UInt8 {
public struct MQTTSuback: _MQTTSendable {
public enum ReturnCode: UInt8, _MQTTSendable {
case grantedQoS0 = 0
case grantedQoS1 = 1
case grantedQoS2 = 2
Expand Down
14 changes: 6 additions & 8 deletions Sources/MQTTNIO/MQTTCoreTypesV5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
//
//===----------------------------------------------------------------------===//

import NIO

/// MQTT V5 Connack
public struct MQTTConnackV5 {
public struct MQTTConnackV5: _MQTTSendable {
/// is using session state from previous session
public let sessionPresent: Bool
/// connect reason code
Expand All @@ -24,7 +22,7 @@ public struct MQTTConnackV5 {
}

/// MQTT V5 ACK information. Returned with PUBACK, PUBREL
public struct MQTTAckV5 {
public struct MQTTAckV5: _MQTTSendable {
/// MQTT v5 reason code
public let reason: MQTTReasonCode
/// MQTT v5 properties
Expand All @@ -37,9 +35,9 @@ public struct MQTTAckV5 {
}

/// MQTT SUBSCRIBE packet parameters.
public struct MQTTSubscribeInfoV5 {
public struct MQTTSubscribeInfoV5: _MQTTSendable {
/// Retain handling options
public enum RetainHandling: UInt8 {
public enum RetainHandling: UInt8, _MQTTSendable {
/// always send retain message
case sendAlways = 0
/// send retain if new
Expand Down Expand Up @@ -81,7 +79,7 @@ public struct MQTTSubscribeInfoV5 {
/// MQTT V5 Sub ACK
///
/// Contains data returned in subscribe/unsubscribe ack packets
public struct MQTTSubackV5 {
public struct MQTTSubackV5: _MQTTSendable {
/// MQTT v5 subscription reason code
public let reasons: [MQTTReasonCode]
/// MQTT v5 properties
Expand All @@ -96,7 +94,7 @@ public struct MQTTSubackV5 {
/// MQTT V5 Sub ACK
///
/// Contains data returned in subscribe/unsubscribe ack packets
public struct MQTTAuthV5 {
public struct MQTTAuthV5: _MQTTSendable {
/// MQTT v5 authentication reason code
public let reason: MQTTReasonCode
/// MQTT v5 properties
Expand Down
2 changes: 1 addition & 1 deletion Sources/MQTTNIO/MQTTError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// MQTTClient errors
public enum MQTTError: Error {
/// Value returned in connection error
public enum ConnectionReturnValue: UInt8 {
public enum ConnectionReturnValue: UInt8, _MQTTSendable {
/// connection was accepted
case accepted = 0
/// The Server does not support the version of the MQTT protocol requested by the Client.
Expand Down
8 changes: 6 additions & 2 deletions Sources/MQTTNIO/MQTTPacket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
//
//===----------------------------------------------------------------------===//

import NIO
#if compiler(>=5.6)
@preconcurrency import NIOCore
#else
import NIOCore
#endif

internal enum InternalError: Swift.Error {
case incompletePacket
case notImplemented
}

/// Protocol for all MQTT packet types
protocol MQTTPacket: CustomStringConvertible {
protocol MQTTPacket: CustomStringConvertible, _MQTTSendable {
/// packet type
var type: MQTTPacketType { get }
/// packet id (default to zero if not used)
Expand Down
10 changes: 7 additions & 3 deletions Sources/MQTTNIO/MQTTProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
//
//===----------------------------------------------------------------------===//

import NIO
#if compiler(>=5.6)
@preconcurrency import NIOCore
#else
import NIOCore
#endif

/// MQTT v5.0 properties. A property consists of a identifier and a value
public struct MQTTProperties {
public struct MQTTProperties: _MQTTSendable {
/// MQTT Property
public enum Property: Equatable {
public enum Property: Equatable, _MQTTSendable {
/// Payload format: 0 = bytes, 1 = UTF8 string (available for PUBLISH)
case payloadFormat(UInt8)
/// Message expiry indicates the lifetime of the message (available for PUBLISH)
Expand Down
2 changes: 1 addition & 1 deletion Sources/MQTTNIO/MQTTReason.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// Reason codes less than 128 are considered successful. Codes greater than or equal to 128 are considered
/// a failure. These are returned by CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, DISCONNECT and
/// AUTH packets
public enum MQTTReasonCode: UInt8 {
public enum MQTTReasonCode: UInt8, _MQTTSendable {
/// Success (available for all). For SUBACK mean QoS0 is available
case success = 0
/// The subscription is accepted and the maximum QoS sent will be QoS 1. This might be a lower QoS than was requested.
Expand Down
1 change: 0 additions & 1 deletion Tests/MQTTNIOTests/MQTTNIOTests+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#if compiler(>=5.5) && canImport(_Concurrency)

import Foundation
import Logging
import NIO
import NIOConcurrencyHelpers
Expand Down