Jelajahi Sumber

fix #383: reset ping_cnt=0 after reconnection

ithewei 2 tahun lalu
induk
melakukan
53d3ba07ae
1 mengubah file dengan 2 tambahan dan 1 penghapusan
  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) {
 static void mqtt_send_ping(hio_t* io) {
     mqtt_client_t* cli = (mqtt_client_t*)hevent_userdata(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!");
         hloge("mqtt no pong!");
         hio_close(io);
         hio_close(io);
         return;
         return;
@@ -215,6 +215,7 @@ static void on_packet(hio_t* io, void* buf, int len) {
         }
         }
         cli->connected = 1;
         cli->connected = 1;
         if (cli->keepalive) {
         if (cli->keepalive) {
+            cli->ping_cnt = 0;
             hio_set_heartbeat(io, cli->keepalive * 1000, mqtt_send_ping);
             hio_set_heartbeat(io, cli->keepalive * 1000, mqtt_send_ping);
         }
         }
     }
     }