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

Fetch clients messageid in locked state to prevent using same msgid for different messages (Issue #867) #868

Merged
Merged
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
8 changes: 6 additions & 2 deletions src/MQTTAsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -3451,8 +3451,8 @@ static int cmdMessageIDCompare(void* a, void* b)
*/
static int MQTTAsync_assignMsgId(MQTTAsyncs* m)
{
int start_msgid = m->c->msgID;
int msgid = start_msgid;
int start_msgid;
int msgid;
thread_id_type thread_id = 0;
int locked = 0;

Expand All @@ -3466,6 +3466,10 @@ static int MQTTAsync_assignMsgId(MQTTAsyncs* m)
locked = 1;
}

/* Fetch last message ID in locked state */
start_msgid = m->c->msgID;
msgid = start_msgid;

msgid = (msgid == MAX_MSG_ID) ? 1 : msgid + 1;
while (ListFindItem(commands, &msgid, cmdMessageIDCompare) ||
ListFindItem(m->responses, &msgid, cmdMessageIDCompare))
Expand Down