mqttclient icon indicating copy to clipboard operation
mqttclient copied to clipboard

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

Open gausstop opened this issue 4 years ago • 3 comments

调试发现,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 avatar Feb 12 '21 15:02 gausstop

1.是lwip要开启LWIP_SO_SNDTIMEO

gausstop avatar Feb 13 '21 19:02 gausstop

  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 avatar Feb 14 '21 04:02 gausstop

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

gausstop avatar Feb 14 '21 04:02 gausstop