Skip to content

Commit 9735cb3

Browse files
M1chacfriedt
authored andcommitted
net: mqtt_sn: handle timestamp being 0
When running just the test mqtt_sn_client::test_mqtt_sn_wait_suback on native_sim, the current timestamp is still 0. That caused the test to fail, because 0 is used as an indicator, that the message has never been sent, thus sending it every time process_work is executed. Instead of adding additional variables and complexity, the code now simply treats now==0 special and waits 1ms until doing anything. Signed-off-by: Michael Zimmermann <[email protected]>
1 parent 3289d83 commit 9735cb3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

subsys/net/lib/mqtt_sn/mqtt_sn.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,9 @@ static int process_pubs(struct mqtt_sn_client *client, int64_t *next_cycle)
664664
"Processing publish for topic");
665665
LOG_HEXDUMP_DBG(pub->pubdata, pub->datalen, "Processing publish data");
666666

667-
if (pub->con.last_attempt == 0) {
667+
if (now == 0) {
668+
next_attempt = 1;
669+
} else if (pub->con.last_attempt == 0) {
668670
next_attempt = 0;
669671
dup = false;
670672
} else {
@@ -749,7 +751,9 @@ static int process_topics(struct mqtt_sn_client *client, int64_t *next_cycle)
749751
SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) {
750752
LOG_HEXDUMP_DBG(topic->name, topic->namelen, "Processing topic");
751753

752-
if (topic->con.last_attempt == 0) {
754+
if (now == 0) {
755+
next_attempt = 1;
756+
} else if (topic->con.last_attempt == 0) {
753757
next_attempt = 0;
754758
dup = false;
755759
} else {

0 commit comments

Comments
 (0)