Skip to content

Commit

Permalink
fix connected property
Browse files Browse the repository at this point in the history
set connected property in on_connect callback based on the return code
value.

fixes #8
  • Loading branch information
jmesnil committed May 14, 2014
1 parent 25ea739 commit dde41f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions MQTTKit/MQTTKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void on_connect(struct mosquitto *mosq, void *obj, int rc)
{
MQTTClient* client = (__bridge MQTTClient*)obj;
LogDebug(@"on_connect rc = %d", rc);
client.connected = YES;
client.connected = (rc == ConnectionAccepted);
if (client.connectionCompletionHandler) {
client.connectionCompletionHandler(rc);
}
Expand Down Expand Up @@ -232,8 +232,6 @@ - (void) connectWithCompletionHandler:(void (^)(MQTTConnectionReturnCode code))c
mosquitto_loop_forever(mosq, 10, 1);
LogDebug(@"end mosquitto loop");
});

self.connected = YES;
}

- (void)connectToHost:(NSString *)host
Expand Down
4 changes: 4 additions & 0 deletions MQTTKitTests/MQTTKitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ - (void)testConnectOnUnknownServer
}];

XCTAssertFalse(gotSignal(connectError, 4));

XCTAssertFalse(client.connected);
}

- (void)testConnectDisconnect
Expand All @@ -105,6 +107,7 @@ - (void)testConnectDisconnect
}];

XCTAssertTrue(gotSignal(connected, 4));
XCTAssertTrue(client.connected);

dispatch_semaphore_t disconnected = dispatch_semaphore_create(0);

Expand All @@ -113,6 +116,7 @@ - (void)testConnectDisconnect
}];

XCTAssertTrue(gotSignal(disconnected, 4));
XCTAssertFalse(client.connected);
}

- (void)testPublish
Expand Down

0 comments on commit dde41f1

Please sign in to comment.