mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 15:40:23 +08:00
Send suback
This commit is contained in:
parent
a7afea0963
commit
2b48e8b03a
@ -42,8 +42,9 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|||||||
case MQTT_CMD_SUBSCRIBE: {
|
case MQTT_CMD_SUBSCRIBE: {
|
||||||
// Client subscribes
|
// Client subscribes
|
||||||
size_t pos = 4; // Initial topic offset, where ID ends
|
size_t pos = 4; // Initial topic offset, where ID ends
|
||||||
uint8_t qos;
|
uint8_t qos, resp[256];
|
||||||
struct mg_str topic;
|
struct mg_str topic;
|
||||||
|
int num_topics = 0;
|
||||||
while ((pos = mg_mqtt_next_sub(mm, &topic, &qos, pos)) > 0) {
|
while ((pos = mg_mqtt_next_sub(mm, &topic, &qos, pos)) > 0) {
|
||||||
struct sub *sub = calloc(1, sizeof(*sub));
|
struct sub *sub = calloc(1, sizeof(*sub));
|
||||||
sub->c = c;
|
sub->c = c;
|
||||||
@ -52,7 +53,12 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|||||||
LIST_ADD_HEAD(struct sub, &s_subs, sub);
|
LIST_ADD_HEAD(struct sub, &s_subs, sub);
|
||||||
LOG(LL_INFO,
|
LOG(LL_INFO,
|
||||||
("SUB %p [%.*s]", c->fd, (int) sub->topic.len, sub->topic.ptr));
|
("SUB %p [%.*s]", c->fd, (int) sub->topic.len, sub->topic.ptr));
|
||||||
|
resp[num_topics++] = qos;
|
||||||
}
|
}
|
||||||
|
mg_mqtt_send_header(c, MQTT_CMD_SUBACK, 0, num_topics + 2);
|
||||||
|
uint16_t id = mg_htons(mm->id);
|
||||||
|
mg_send(c, &id, 2);
|
||||||
|
mg_send(c, resp, num_topics);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MQTT_CMD_PUBLISH: {
|
case MQTT_CMD_PUBLISH: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user