Skip to content

Commit

Permalink
Call all handlers matching an MQTT message
Browse files Browse the repository at this point in the history
Rather than only the one registered the most recently, as previously.
  • Loading branch information
QRPp committed Jun 2, 2021
1 parent 7bb18c4 commit 21528df
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/mgos_mqtt_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,20 @@ static void mgos_mqtt_conn_queue_remove(struct mgos_mqtt_conn *c,

static bool call_topic_handler(struct mgos_mqtt_conn *c, int ev,
void *ev_data) {
bool handled = false;
struct mg_mqtt_message *msg = (struct mg_mqtt_message *) ev_data;
struct mgos_mqtt_subscription *s;
SLIST_FOREACH(s, &c->subscriptions, next) {
if ((ev == MG_EV_MQTT_SUBACK && s->sub_id == msg->message_id) ||
mg_mqtt_match_topic_expression(s->topic, msg->topic)) {
if (ev == MG_EV_MQTT_PUBLISH && msg->qos > 0) {
if (!handled && ev == MG_EV_MQTT_PUBLISH && msg->qos > 0) {
mg_mqtt_puback(c->nc, msg->message_id);
}
s->handler(c->nc, ev, ev_data, s->user_data);
return true;
handled = true;
}
}
return false;
return handled;
}

static void call_conn_handlers(struct mgos_mqtt_conn *c, int ev,
Expand Down

0 comments on commit 21528df

Please sign in to comment.