MqttClient - fix local disconnect after pulish + ka
This commit is contained in:
@@ -51,6 +51,7 @@ MqttClient::MqttClient(MqttBroker* local_broker, const std::string& id)
|
||||
: local_broker(local_broker), clientId(id)
|
||||
{
|
||||
alive = 0;
|
||||
keep_alive = 0;
|
||||
|
||||
if (local_broker) local_broker->addClient(this);
|
||||
}
|
||||
@@ -256,7 +257,7 @@ void MqttClient::clientAlive()
|
||||
|
||||
void MqttClient::loop()
|
||||
{
|
||||
if (alive && (millis() >= alive))
|
||||
if (keep_alive && (millis() >= alive))
|
||||
{
|
||||
if (local_broker)
|
||||
{
|
||||
|
||||
@@ -76,6 +76,34 @@ test(local_wildcard_subscribe)
|
||||
assertEqual(published.size(), (size_t)1); // client has received something
|
||||
}
|
||||
|
||||
test(local_client_do_not_disconnect_after_publishing)
|
||||
{
|
||||
set_millis(0);
|
||||
MqttBroker broker(1883);
|
||||
MqttClient client(&broker, "client");
|
||||
MqttClient sender(&broker, "sender");
|
||||
broker.loop();
|
||||
|
||||
client.subscribe("#");
|
||||
client.subscribe("test");
|
||||
client.setCallback(onPublish);
|
||||
assertEqual(broker.localClientsCount(), (size_t)2);
|
||||
|
||||
sender.publish("test", "value");
|
||||
broker.loop();
|
||||
|
||||
add_seconds(60);
|
||||
client.loop();
|
||||
sender.loop();
|
||||
broker.loop();
|
||||
|
||||
assertEqual(broker.localClientsCount(), (size_t)2);
|
||||
assertEqual(sender.connected(), true);
|
||||
assertEqual(client.connected(), true);
|
||||
|
||||
assertEqual(published.size(), (size_t)1); // client has received something
|
||||
}
|
||||
|
||||
#if 0
|
||||
test(local_publish_should_be_dispatched_to_local_clients)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user