From 3398c2ff69d1884c80d45c2cfc1697a53f2e86cf Mon Sep 17 00:00:00 2001 From: hxy7yx <1595670487@qq.com> Date: Tue, 20 Aug 2024 14:25:35 +0800 Subject: [PATCH] chore(mqtt): add reason for connection & disconnection --- src/connection/mqtt_client.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/connection/mqtt_client.c b/src/connection/mqtt_client.c index 93518edd..fb8619f4 100644 --- a/src/connection/mqtt_client.c +++ b/src/connection/mqtt_client.c @@ -542,8 +542,10 @@ static void connect_cb(nng_pipe p, nng_pipe_ev ev, void *arg) neu_mqtt_client_t * client = arg; neu_mqtt_client_connection_cb_t cb = NULL; void * data = NULL; + int reason = 0; - log(notice, "mqtt client connected"); + nng_pipe_get_int(p, NNG_OPT_MQTT_CONNECT_REASON, &reason); + log(notice, "mqtt client connected, reason: %d", reason); nng_mtx_lock(client->mtx); // start receiving @@ -568,8 +570,11 @@ static void disconnect_cb(nng_pipe p, nng_pipe_ev ev, void *arg) subscription_t * sub = NULL; neu_mqtt_client_connection_cb_t cb = NULL; void * data = NULL; + int reason = 0; + + nng_pipe_get_int(p, NNG_OPT_MQTT_DISCONNECT_REASON, &reason); + log(notice, "mqtt client disconnected, reason: %d", reason); - log(notice, "mqtt client disconnected"); nng_mtx_lock(client->mtx); client->connected = false; cb = client->disconnect_cb;