Skip to content

Commit

Permalink
add comments for close()
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed May 13, 2024
1 parent 7a0d900 commit 74f0444
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Source/AwsCommonRuntimeKit/mqtt/Mqtt5Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ public class Mqtt5Client {
internal let rwlock = ReadWriteLock()
internal var callbackFlag = true

/// Creates a Mqtt5Client instance using the provided Mqtt5ClientOptions. Once the Mqtt5Client is created,
/// changing the settings will not cause a change in already created Mqtt5Client's.
/// Once created, it is MANDATORY to call `close()` to clean up the Mqtt5Client resource
///
/// - Parameters:
/// clientOptions: The MqttClientOptions class to use to configure the new Mqtt5Client.
///
/// - Throws: CommonRuntimeError.crtError If the system is unable to allocate space for a native MQTT5 client structure
init(clientOptions options: MqttClientOptions) throws {

try options.validateConversionToNative()
Expand All @@ -164,10 +172,11 @@ public class Mqtt5Client {
self.rawValue = rawValue
}

deinit {
print("[MQTT5 CLIENT TEST] DEINIT")
}

/// Notifies the Mqtt5Client that you want it maintain connectivity to the configured endpoint.
/// The client will attempt to stay connected using the properties of the reconnect-related parameters
/// in the Mqtt5Client configuration on client creation.
///
/// - Throws: CommonRuntimeError.crtError
public func start() throws {
try self.rwlock.read {
// validate the client in case close() is called.
Expand All @@ -183,6 +192,14 @@ public class Mqtt5Client {
}
}

/// Notifies the Mqtt5Client that you want it to end connectivity to the configured endpoint, disconnecting any
/// existing connection and halting any reconnect attempts. No DISCONNECT packets will be sent.
///
/// - Parameters:
/// - disconnectPacket: (optional) Properties of a DISCONNECT packet to send as part of the shutdown
/// process. When disconnectPacket is null, no DISCONNECT packets will be sent.
///
/// - Throws: CommonRuntimeError.crtError
public func stop(disconnectPacket: DisconnectPacket? = nil) throws {
try self.rwlock.read {
// validate the client in case close() is called.
Expand Down Expand Up @@ -312,6 +329,7 @@ public class Mqtt5Client {
}
}

/// Discard all operations and cleanup the client. It is MANDATORY function to call to release the client.
public func close() {
self.rwlock.write {
self.callbackFlag = false
Expand Down

0 comments on commit 74f0444

Please sign in to comment.