mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 23:49:44 +08:00
Add mqtt last will
PUBLISHED_FROM=fb856714ead67390dfd7ce9d208ae5ae19ce7c6d
This commit is contained in:
parent
cbd5835112
commit
57f964a139
15
mongoose.c
15
mongoose.c
@ -9691,6 +9691,11 @@ void mg_send_mqtt_handshake_opt(struct mg_connection *nc, const char *client_id,
|
||||
opts.flags |= MG_MQTT_HAS_PASSWORD;
|
||||
rem_len += (uint8_t) strlen(opts.password) + 2;
|
||||
}
|
||||
if (opts.will_topic != NULL && opts.will_message != NULL) {
|
||||
opts.flags |= MG_MQTT_HAS_WILL;
|
||||
rem_len += (uint8_t) strlen(opts.will_topic) + 2;
|
||||
rem_len += (uint8_t) strlen(opts.will_message) + 2;
|
||||
}
|
||||
|
||||
mg_send(nc, &header, 1);
|
||||
mg_send(nc, &rem_len, 1);
|
||||
@ -9708,6 +9713,16 @@ void mg_send_mqtt_handshake_opt(struct mg_connection *nc, const char *client_id,
|
||||
mg_send(nc, &len, 2);
|
||||
mg_send(nc, client_id, strlen(client_id));
|
||||
|
||||
if (opts.flags & MG_MQTT_HAS_WILL) {
|
||||
len = htons((uint16_t) strlen(opts.will_topic));
|
||||
mg_send(nc, &len, 2);
|
||||
mg_send(nc, opts.will_topic, strlen(opts.will_topic));
|
||||
|
||||
len = htons((uint16_t) strlen(opts.will_message));
|
||||
mg_send(nc, &len, 2);
|
||||
mg_send(nc, opts.will_message, strlen(opts.will_message));
|
||||
}
|
||||
|
||||
if (opts.flags & MG_MQTT_HAS_USER_NAME) {
|
||||
len = htons((uint16_t) strlen(opts.user_name));
|
||||
mg_send(nc, &len, 2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user