瀏覽代碼

fix #383: reset ping_cnt=0 after reconnection

ithewei 2 年之前
父節點
當前提交
53d3ba07ae
共有 1 個文件被更改,包括 2 次插入1 次删除
  1. 2 1
      mqtt/mqtt_client.c

+ 2 - 1
mqtt/mqtt_client.c

@@ -47,7 +47,7 @@ static int mqtt_send_head_with_mid(hio_t* io, int type, unsigned short mid) {
 
 static void mqtt_send_ping(hio_t* io) {
     mqtt_client_t* cli = (mqtt_client_t*)hevent_userdata(io);
-    if (++cli->ping_cnt > 3) {
+    if (cli->ping_cnt++ == 3) {
         hloge("mqtt no pong!");
         hio_close(io);
         return;
@@ -215,6 +215,7 @@ static void on_packet(hio_t* io, void* buf, int len) {
         }
         cli->connected = 1;
         if (cli->keepalive) {
+            cli->ping_cnt = 0;
             hio_set_heartbeat(io, cli->keepalive * 1000, mqtt_send_ping);
         }
     }