-
Notifications
You must be signed in to change notification settings - Fork 51
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
Only one retained message received #10
Comments
I tried to fix the problem, but I was very confused about the construction of the deliver_publish function.
It works for me now, except if the messages are getting larger than the buffer size. But as I use only small messages, this is not a problem for me. I'm not sure if the function now works as intended, perhaps someone can have a look at it. |
I think this is due to a fundamental misunderstanding of TCP in the design. The code treats the TCP connection as a packet source, making an assumption that each "read" will return one and only one message. However in reality TCP is a stream and there may be multiple packets waiting, including fragmented ones. My own testing found that this library often drops messages in both directions, especially when many are sent at once (e.g. reconnection followed by receipt of retained messages), because only the first message is processed. The rest are thrown away. I spent some time looking over the code and I think it can be fixed, I just don't have the time or motivation at the moment to do so myself, unfortunately. |
When the client subscribes to multiple topics with a wild card and receives multiple retained messages, the callback is only called once. The data is somehow in the data buffer, but I expect that the callback function is called for every message.
I think the problem is in line 376 in mqtt.c:
if (client->mqtt_state.message_length_read >= client->mqtt_state.message_length)
this if statement is probably always true and so the loop stops after one run even when there are more messages left in the buffer
The text was updated successfully, but these errors were encountered: