Skip to content

Commit

Permalink
MQTT-Client-Framework 0.8.8
Browse files Browse the repository at this point in the history
> Release date 2017-04-03

[FIX] Connection Retry after Closed-by-Broker Errors #297
[NEW] Configurable maxConnectionRetryInterval for MQTTSessionMananger #297
[FIX] Don't publish QoS 1 or 2 messages immediately if queued messages exists #295
  • Loading branch information
Christoph Krey committed Apr 3, 2017
1 parent 749a5e1 commit e255874
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 22 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
MQTT-Client-Framework iOS/OSX/tvOS Release Notes
================================================

## MQTT-Client-Framework 0.8.8
> Release date 2017-04-03
[FIX] Connection Retry after Closed-by-Broker Errors #297
[NEW] Configurable maxConnectionRetryInterval for MQTTSessionMananger #297
[FIX] Don't publish QoS 1 or 2 messages immediately if queued messages exists #295


## MQTT-Client-Framework 0.8.6/7
> Release date 2017-01-04
Expand Down
4 changes: 2 additions & 2 deletions MQTTClient.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |mqttc|
mqttc.name = "MQTTClient"
mqttc.version = "0.8.7"
mqttc.version = "0.8.8"
mqttc.summary = "iOS, OSX and tvOS native ObjectiveC MQTT Client Framework"
mqttc.homepage = "https://github.com/ckrey/MQTT-Client-Framework"
mqttc.license = { :type => "EPLv1", :file => "LICENSE" }
mqttc.author = { "Christoph Krey" => "[email protected]" }
mqttc.source = {
:git => "https://github.com/ckrey/MQTT-Client-Framework.git",
:tag => "0.8.7",
:tag => "0.8.8",
:submodules => true
}

Expand Down
19 changes: 17 additions & 2 deletions MQTTClient/MQTTClient/MQTTSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ typedef NS_ENUM(int, MQTTSessionManagerState) {
* @param maxSize (a positive number of bytes, default is 64 MB) to limit the size of the persistence file. Messages published after the limit is reached are dropped.
* @param maxMessages (a positive number, default is 1024) to limit the number of messages stored. Additional messages published are dropped.
* @param maxRetryInterval The duration at which the connection-retry timer should be capped. When MQTTSessionManager receives a ClosedByBroker or an Error
event, it will attempt to reconnect to the broker. The time in between connection attempts is doubled each time, until it remains at maxRetryInterval.
Defaults to 64 seconds.
event, it will attempt to reconnect to the broker. The time in between connection attempts is doubled each time, until it remains at maxRetryInterval.
Defaults to 64 seconds.
* @param connectInForeground Whether or not to connect the MQTTSession when the app enters the foreground, and disconnect when it becomes inactive. When NO, the caller is responsible for calling -connectTo: and -disconnect. Defaults to YES.
* @return the initialized MQTTSessionManager object
*/
Expand All @@ -130,6 +130,21 @@ typedef NS_ENUM(int, MQTTSessionManagerState) {
maxConnectionRetryInterval:(NSTimeInterval)maxRetryInterval
connectInForeground:(BOOL)connectInForeground;

/** initWithPersistence sets the MQTTPersistence properties other than default
* @param persistent YES or NO (default) to establish file or in memory persistence.
* @param maxWindowSize (a positive number, default is 16) to control the number of messages sent before waiting for acknowledgement in Qos 1 or 2. Additional messages are stored and transmitted later.
* @param maxSize (a positive number of bytes, default is 64 MB) to limit the size of the persistence file. Messages published after the limit is reached are dropped.
* @param maxMessages (a positive number, default is 1024) to limit the number of messages stored. Additional messages published are dropped.
* @param connectInForeground Whether or not to connect the MQTTSession when the app enters the foreground, and disconnect when it becomes inactive. When NO, the caller is responsible for calling -connectTo: and -disconnect. Defaults to YES.
* @return the initialized MQTTSessionManager object
*/

- (MQTTSessionManager *)initWithPersistence:(BOOL)persistent
maxWindowSize:(NSUInteger)maxWindowSize
maxMessages:(NSUInteger)maxMessages
maxSize:(NSUInteger)maxSize
connectInForeground:(BOOL)connectInForeground;

/** initWithPersistence sets the MQTTPersistence properties other than default
* @param persistent YES or NO (default) to establish file or in memory persistence.
* @param maxWindowSize (a positive number, default is 16) to control the number of messages sent before waiting for acknowledgement in Qos 1 or 2. Additional messages are stored and transmitted later.
Expand Down
52 changes: 34 additions & 18 deletions MQTTClient/MQTTClient/MQTTSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ @implementation MQTTSessionManager
- (void)dealloc {
#if TARGET_OS_IPHONE == 1

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[defaultCenter removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
[defaultCenter removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[defaultCenter removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
[defaultCenter removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];

#endif
}
Expand All @@ -81,8 +81,8 @@ - (id)init {
[self updateState:MQTTSessionManagerStateStarting];
self.internalSubscriptions = [[NSMutableDictionary alloc] init];
self.effectiveSubscriptions = [[NSMutableDictionary alloc] init];
//Use the default value

//Use the default value
self.persistent = MQTT_PERSISTENT;
self.maxSize = MQTT_MAX_SIZE;
self.maxMessages = MQTT_MAX_MESSAGES;
Expand Down Expand Up @@ -130,6 +130,20 @@ - (MQTTSessionManager *)initWithPersistence:(BOOL)persistent
return self;
}

- (MQTTSessionManager *)initWithPersistence:(BOOL)persistent
maxWindowSize:(NSUInteger)maxWindowSize
maxMessages:(NSUInteger)maxMessages
maxSize:(NSUInteger)maxSize
connectInForeground:(BOOL)connectInForeground {
self = [self initWithPersistence:persistent
maxWindowSize:maxWindowSize
maxMessages:maxMessages
maxSize:maxSize
maxConnectionRetryInterval:RECONNECT_TIMER_MAX_DEFAULT
connectInForeground:connectInForeground];
return self;
}

- (MQTTSessionManager *)initWithPersistence:(BOOL)persistent
maxWindowSize:(NSUInteger)maxWindowSize
maxMessages:(NSUInteger)maxMessages
Expand Down Expand Up @@ -183,7 +197,7 @@ - (void)connectTo:(NSString *)host
willQos:(MQTTQosLevel)willQos
willRetainFlag:(BOOL)willRetainFlag
withClientId:(NSString *)clientId {
[self connectTo:host
[self connectTo:host
port:port
tls:tls
keepalive:keepalive
Expand Down Expand Up @@ -384,7 +398,7 @@ - (void)disconnect
- (void)updateState:(MQTTSessionManagerState)newState
{
self.state = newState;

if ([self.delegate respondsToSelector:@selector(sessionManager:didChangeState:)]) {
[self.delegate sessionManager:self didChangeState:newState];
}
Expand All @@ -406,13 +420,13 @@ - (void)handleEvent:(MQTTSession *)session event:(MQTTSessionEvent)eventCode err
{
#ifdef DEBUG
__unused const NSDictionary *events = @{
@(MQTTSessionEventConnected): @"connected",
@(MQTTSessionEventConnectionRefused): @"connection refused",
@(MQTTSessionEventConnectionClosed): @"connection closed",
@(MQTTSessionEventConnectionError): @"connection error",
@(MQTTSessionEventProtocolError): @"protocoll error",
@(MQTTSessionEventConnectionClosedByBroker): @"connection closed by broker"
};
@(MQTTSessionEventConnected): @"connected",
@(MQTTSessionEventConnectionRefused): @"connection refused",
@(MQTTSessionEventConnectionClosed): @"connection closed",
@(MQTTSessionEventConnectionError): @"connection error",
@(MQTTSessionEventProtocolError): @"protocoll error",
@(MQTTSessionEventConnectionClosedByBroker): @"connection closed by broker"
};
DDLogVerbose(@"[MQTTSessionManager] eventCode: %@ (%ld) %@", events[@(eventCode)], (long)eventCode, error);
#endif
[self.reconnectTimer invalidate];
Expand All @@ -432,8 +446,10 @@ - (void)handleEvent:(MQTTSession *)session event:(MQTTSessionEvent)eventCode err
case MQTTSessionEventConnectionClosedByBroker:
[self updateState:MQTTSessionManagerStateClosed];
[self endBackgroundTask];
if (self.state != MQTTSessionManagerStateClosing) {
[self triggerDelayedReconnect];
}
[self updateState:MQTTSessionManagerStateStarting];
[self triggerDelayedReconnect];
break;

case MQTTSessionEventProtocolError:
Expand Down Expand Up @@ -541,7 +557,7 @@ - (void)setSubscriptions:(NSDictionary<NSString *, NSNumber *> *)newSubscription
{
if (self.state == MQTTSessionManagerStateConnected) {
NSDictionary *currentSubscriptions = [self.effectiveSubscriptions copy];

for (NSString *topicFilter in currentSubscriptions) {
if (![newSubscriptions objectForKey:topicFilter]) {
[self.session unsubscribeTopic:topicFilter unsubscribeHandler:^(NSError *error) {
Expand All @@ -555,7 +571,7 @@ - (void)setSubscriptions:(NSDictionary<NSString *, NSNumber *> *)newSubscription
}];
}
}

for (NSString *topicFilter in newSubscriptions) {
if (![currentSubscriptions objectForKey:topicFilter]) {
NSNumber *number = newSubscriptions[topicFilter];
Expand Down

0 comments on commit e255874

Please sign in to comment.