jiejieTop / mqttclient

A high-performance, high-stability, cross-platform MQTT client, developed based on the socket API, can be used on embedded devices (FreeRTOS / LiteOS / RT-Thread / TencentOS tiny), Linux, Windows, Mac, with a very concise The API interface realizes the quality of service of QOS2 with very few resources, and seamlessly connects the mbedtls encryption library.
Apache License 2.0
696 stars 256 forks source link

客户端工作期间,线路断线后再恢复无法自动恢复运行的问题 #35

Open gausstop opened 3 years ago

gausstop commented 3 years ago

调试发现,mqtt_publish 返回的是MQTT_SEND_PACKET_ERROR.

但是查看 mqtt_yield_thread 函数

rc = mqtt_yield(c, c->mqtt_cmd_timeout); if (MQTT_CLEAN_SESSION_ERROR == rc) { MQTT_LOG_W("%s:%d %s()..., mqtt clean session....", __FILE__, __LINE__, __FUNCTION__); network_disconnect(c->mqtt_network); mqtt_clean_session(c); goto exit; } else if (MQTT_RECONNECT_TIMEOUT_ERROR == rc) { MQTT_LOG_W("%s:%d %s()..., mqtt reconnect timeout....", __FILE__, __LINE__, __FUNCTION__); }

没看到有对应的错误处理部分.

对这种情况请大虾指导一下,系统有对应的处理部分么?

如果没有,能否建议一下如何能达到自动恢复发送的流程.

谢谢

gausstop commented 3 years ago

1.是lwip要开启LWIP_SO_SNDTIMEO

gausstop commented 3 years ago
  1. 在mqtt_publish()里增加MQTT_SEND_PACKET_ERROR处理部分

exit: msg->payloadlen = 0; // clear

platform_mutex_unlock(&c->mqtt_write_lock);

switch(rc) {
    case MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR:
    case MQTT_MEM_NOT_ENOUGH_ERROR:
    case MQTT_SEND_PACKET_ERROR:
        MQTT_LOG_W("%s:%d %s()... there is not enough memory space to record...\n", __FILE__, __LINE__, __FUNCTION__);
        /*must realse the socket file descriptor zhaoshimin 20200629*/
        network_release(c->mqtt_network);
        /* record too much retransmitted data, may be disconnected, need to reconnect */
        mqtt_set_client_state(c, CLIENT_STATE_DISCONNECTED);
        break;
    default:
        break;
}

RETURN_ERROR(rc);     
gausstop commented 3 years ago

请大牛看看,这样调整是否合适.谢谢