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

Start packet id counter from 1 instead of 0 #207

Closed
wants to merge 1 commit into from
Closed

Start packet id counter from 1 instead of 0 #207

wants to merge 1 commit into from

Conversation

Mollayo
Copy link

@Mollayo Mollayo commented Jan 26, 2022

@brentru : this is a pull request to address this issue: #203

Packets whose index is 0 are considered as malformed packets by the MQTT broker. If such thing happens, the client is disconnected by the broker. The value of the packet_id_counter variable is now calculated in a way that it is always different from 0 to avoid unwanted disconnections.

Packets whose index is 0 are considered as malformed packets by the MQTT broker. If such thing happens, the client is disconnected by the broker. The value of the packet_id_counter variable is now calculated in a way that it is always different from 0 to avoid unwanted disconnections.
@mikedoug
Copy link

I agree with this patch too -- it was causing a malformed packet when subscribing immediately after a connection; which is a pretty common thing to do.

@mikedoug
Copy link

Though a more compact way to do this might just be:

packet_id_counter = packet_id_counter == 0xffff ? 1 : packet_id_counter + 1;

Also, in publish, in the qos if block:

packnum = packnum == 0xffff ? 1 : packnum + 1;

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants