Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change static timer in keepalive func to regular timer #45

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 11 additions & 6 deletions paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class Client
{

public:

typedef void (*messageHandler)(MessageData&);

/** Construct the client
Expand Down Expand Up @@ -234,10 +233,9 @@ class Client
{
return isconnected;
}

private:

void closeSession();

private:
void cleanSession();
int cycle(Timer& timer);
int waitfor(int packet_type, Timer& timer);
Expand All @@ -256,7 +254,9 @@ class Client
unsigned char sendbuf[MAX_MQTT_PACKET_SIZE];
unsigned char readbuf[MAX_MQTT_PACKET_SIZE];

Timer last_sent, last_received;
Timer last_sent;
Timer last_received;
Timer ping_sent;
unsigned int keepAliveInterval;
bool ping_outstanding;
bool cleansession;
Expand Down Expand Up @@ -318,6 +318,9 @@ void MQTT::Client<Network, Timer, a, MAX_MESSAGE_HANDLERS>::cleanSession()
template<class Network, class Timer, int a, int MAX_MESSAGE_HANDLERS>
void MQTT::Client<Network, Timer, a, MAX_MESSAGE_HANDLERS>::closeSession()
{
last_sent.stop();
last_received.stop();
ping_sent.stop();
ping_outstanding = false;
isconnected = false;
if (cleansession)
Expand Down Expand Up @@ -700,7 +703,6 @@ template<class Network, class Timer, int MAX_MQTT_PACKET_SIZE, int b>
int MQTT::Client<Network, Timer, MAX_MQTT_PACKET_SIZE, b>::keepalive()
{
int rc = SUCCESS;
static Timer ping_sent;

if (keepAliveInterval == 0)
goto exit;
Expand Down Expand Up @@ -1066,6 +1068,9 @@ int MQTT::Client<Network, Timer, MAX_MQTT_PACKET_SIZE, b>::disconnect()
if (len > 0)
rc = sendPacket(len, timer); // send the disconnect packet
closeSession();
last_sent.stop();
last_received.stop();
ping_sent.stop();
return rc;
}

Expand Down
8 changes: 7 additions & 1 deletion paho_mqtt_embedded_c/MQTTClient/src/mbed/MQTTmbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Countdown

bool expired()
{
return t.read_ms() >= interval_end_ms;
return (unsigned long)t.read_ms() >= interval_end_ms;
}

void countdown_ms(unsigned long ms)
Expand All @@ -57,6 +57,12 @@ class Countdown
return interval_end_ms - t.read_ms();
}

void stop()
{
t.stop();
t.reset();
}

private:
Timer t;
unsigned long interval_end_ms;
Expand Down
5 changes: 5 additions & 0 deletions src/MQTTClientMbedOs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,8 @@ void MQTTClient::init(Socket *sock)
client = NULL;
clientSN = NULL;
}

void MQTTClient::mqttClientCloseSession()
{
client->closeSession();
}
4 changes: 3 additions & 1 deletion src/MQTTClientMbedOs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <TLSSocket.h>
#include <DTLSSocket.h>
#include <UDPSocket.h>
#include "unity/unity.h"
// #include "unity/unity.h"

#include "FP.h"
#include <MQTTPacket.h>
Expand Down Expand Up @@ -234,6 +234,8 @@ class MQTTClient {
*/
nsapi_error_t setMessageHandler(const char *topicFilter, messageHandler mh);

void mqttClientCloseSession();

private:
/**
* @brief Helper function to initialize member variables.
Expand Down