From cdad099f0c6375adefa765fe7a9ad545a5de7349 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 75e3fe9b..5fb2ec7b 100644 --- a/src/connection/mqtt_client.c +++ b/src/connection/mqtt_client.c @@ -541,8 +541,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 @@ -567,8 +569,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;