keeplive 那个本身的是检测不到心跳包才 断开连接的 可设置 一般是1min之内检测到,很慢 所以这个在keeplive之上的 检测到发送失败就断开连接
if(c->lcc_flag==1)
{
c->lcc_flag = 0;
KAWAII_MQTT_LOG_W(" send err and close socketrn");
/*must realse the socket file descriptor zhaoshimin 20200629*/
network_release(c->mqtt_network);
mqtt_set_client_state(c, CLIENT_STATE_DISCONNECTED);
rc = KAWAII_MQTT_NOT_CONNECT_ERROR; /* PINGRESP not received in keepalive interval */
}
else if (platform_timer_is_expired(&c->mqtt_last_sent) || platform_timer_is_expired(&c->mqtt_last_received))
{
if (c->mqtt_ping_outstanding)
{
KAWAII_MQTT_LOG_W("%s:%d %s()... ping outstanding", __FILE__, __LINE__, __FUNCTION__);
/*must realse the socket file descriptor zhaoshimin 20200629*/
network_release(c->mqtt_network);
mqtt_set_client_state(c, CLIENT_STATE_DISCONNECTED);
rc = KAWAII_MQTT_NOT_CONNECT_ERROR; /* PINGRESP not received in keepalive interval */
}
else
{
platform_timer_t timer;
timer.time =10000;
rt_kprintf("send keeplive datan");
// rt_thread_mdelay(3000);
/*add mutex sem protect zhaoshimin 20200630*/
platform_mutex_lock(&c->mqtt_write_lock);
int len = MQTTSerialize_pingreq(c->mqtt_write_buf, c->mqtt_write_buf_size);
if (len > 0) // send the ping packet
{
/*when the socket error, mqtt_ping_outstanding counter must add one*/
rc = mqtt_send_packet(c, len, &timer);
c->mqtt_ping_outstanding++;
}
platform_mutex_unlock(&c->mqtt_write_lock);
}
}
第二个问题 发送完就可以释放了 我的代码就是在发送完释放的
msg.qos = QOS0;
msg.payload = mqtt_modbus_data;
mqtt_mark = mqtt_publish(client_fd,g_run_GW_parament.mqtt_setparament.pub_topic, &msg);
rt_kprintf("nmqtt data:%dnn",mqtt_mark);
cJSON_free(mqtt_modbus_data);
if(mqtt_mark !=0)
{
client_fd->lcc_flag = 1;
}
keeplive 那个本身的是检测不到心跳包才 断开连接的 可设置 一般是1min之内检测到,很慢 所以这个在keeplive之上的 检测到发送失败就断开连接
if(c->lcc_flag==1)
{
c->lcc_flag = 0;
KAWAII_MQTT_LOG_W(" send err and close socketrn");
/*must realse the socket file descriptor zhaoshimin 20200629*/
network_release(c->mqtt_network);
mqtt_set_client_state(c, CLIENT_STATE_DISCONNECTED);
rc = KAWAII_MQTT_NOT_CONNECT_ERROR; /* PINGRESP not received in keepalive interval */
}
else if (platform_timer_is_expired(&c->mqtt_last_sent) || platform_timer_is_expired(&c->mqtt_last_received))
{
if (c->mqtt_ping_outstanding)
{
KAWAII_MQTT_LOG_W("%s:%d %s()... ping outstanding", __FILE__, __LINE__, __FUNCTION__);
/*must realse the socket file descriptor zhaoshimin 20200629*/
network_release(c->mqtt_network);
mqtt_set_client_state(c, CLIENT_STATE_DISCONNECTED);
rc = KAWAII_MQTT_NOT_CONNECT_ERROR; /* PINGRESP not received in keepalive interval */
}
else
{
platform_timer_t timer;
timer.time =10000;
rt_kprintf("send keeplive datan");
// rt_thread_mdelay(3000);
/*add mutex sem protect zhaoshimin 20200630*/
platform_mutex_lock(&c->mqtt_write_lock);
int len = MQTTSerialize_pingreq(c->mqtt_write_buf, c->mqtt_write_buf_size);
if (len > 0) // send the ping packet
{
/*when the socket error, mqtt_ping_outstanding counter must add one*/
rc = mqtt_send_packet(c, len, &timer);
c->mqtt_ping_outstanding++;
}
platform_mutex_unlock(&c->mqtt_write_lock);
}
}
第二个问题 发送完就可以释放了 我的代码就是在发送完释放的
msg.qos = QOS0;
msg.payload = mqtt_modbus_data;
mqtt_mark = mqtt_publish(client_fd,g_run_GW_parament.mqtt_setparament.pub_topic, &msg);
rt_kprintf("nmqtt data:%dnn",mqtt_mark);
cJSON_free(mqtt_modbus_data);
if(mqtt_mark !=0)
{
client_fd->lcc_flag = 1;
}
举报