From 9f9e00a62dcfcdcde857bb2c9bc495930904f1cf Mon Sep 17 00:00:00 2001 From: PK Chan Date: Tue, 10 Mar 2020 18:03:51 +0800 Subject: [PATCH] net: mqtt: Added event for MQTT ping response. There are scenarios where there is a NAT firewall in between MQTT client and server. In such case, the NAT TCP timeout may be shorter than MQTT keepalive timeout and TCP timeout. The the MQTT ping request message is dropped by the NAT firewall, so that it cannot be received by the server, resulting in void MQTT ping response message. There is no TCP FIN or RST at all. The application looks hang-up until TCP timeout happens on the client side, which may take too long. Therefore, the event MQTT_EVT_PINGRESP is added to inform the application that the route between client and server is still valid. Signed-off-by: PK Chan --- include/net/mqtt.h | 5 ++++- subsys/net/lib/mqtt/mqtt_rx.c | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/net/mqtt.h b/include/net/mqtt.h index 9f234fa85f1..dd295ef2eae 100644 --- a/include/net/mqtt.h +++ b/include/net/mqtt.h @@ -75,7 +75,10 @@ enum mqtt_evt_type { MQTT_EVT_SUBACK, /** Acknowledgment to a unsubscribe request. */ - MQTT_EVT_UNSUBACK + MQTT_EVT_UNSUBACK, + + /** Ping Response from server. */ + MQTT_EVT_PINGRESP, }; /** @brief MQTT version protocol level. */ diff --git a/subsys/net/lib/mqtt/mqtt_rx.c b/subsys/net/lib/mqtt/mqtt_rx.c index 84801ce789d..b7e7219f905 100644 --- a/subsys/net/lib/mqtt/mqtt_rx.c +++ b/subsys/net/lib/mqtt/mqtt_rx.c @@ -127,8 +127,7 @@ static int mqtt_handle_packet(struct mqtt_client *client, client->unacked_ping--; } - /* No notification of Ping response to application. */ - notify_event = false; + evt.type = MQTT_EVT_PINGRESP; break; default: