mqttclient version 1.0.2 released...

This commit is contained in:
jiejieTop
2020-04-25 19:11:29 +08:00
parent 8e38e24711
commit d58ef4e996
3 changed files with 25 additions and 18 deletions

View File

@@ -2,7 +2,7 @@
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-15 00:42:16
* @LastEditTime: 2020-03-21 16:49:07
* @LastEditTime: 2020-04-25 18:59:08
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#ifndef _ERROR_H_
@@ -10,12 +10,12 @@
typedef enum mqtt_error {
MQTT_SSL_CERT_ERROR = -0x001C, /* cetr parse failed */
MQTT_SOCKET_FAILED = -0x001B, /* socket fd failed */
MQTT_SOCKET_UNKNOWN_HOST = -0x001A, /* socket unknown host ip or domain */
MQTT_SET_PUBLISH_DUP_FAILED = -0x0019, /* mqtt publish packet set udp bit failed */
MQTT_SOCKET_FAILED_ERROR = -0x001B, /* socket fd failed */
MQTT_SOCKET_UNKNOWN_HOST_ERROR = -0x001A, /* socket unknown host ip or domain */
MQTT_SET_PUBLISH_DUP_FAILED_ERROR = -0x0019, /* mqtt publish packet set udp bit failed */
MQTT_CLEAN_SESSION_ERROR = -0x0018, /* mqtt clean session error */
MQTT_ACK_NODE_IS_EXIST = -0x0017, /* mqtt ack list is exist ack node */
MQTT_ACK_HANDLER_NUM_TOO_MUCH = -0x0016, /* mqtt ack handler number is too much */
MQTT_ACK_NODE_IS_EXIST_ERROR = -0x0017, /* mqtt ack list is exist ack node */
MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR = -0x0016, /* mqtt ack handler number is too much */
MQTT_RESUBSCRIBE_ERROR = -0x0015, /* mqtt resubscribe error */
MQTT_SUBSCRIBE_ERROR = -0x0014, /* mqtt subscribe error */
MQTT_SEND_PACKET_ERROR = -0x0013, /* mqtt send a packet */

View File

@@ -2,7 +2,7 @@
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-09 21:31:25
* @LastEditTime: 2020-04-23 15:12:36
* @LastEditTime: 2020-04-25 18:58:14
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "mqttclient.h"
@@ -48,12 +48,12 @@ static int mqtt_set_publish_dup(mqtt_client_t* c, unsigned char dup)
MQTTHeader header = {0};
if (NULL == c->write_buf)
RETURN_ERROR(MQTT_SET_PUBLISH_DUP_FAILED);
RETURN_ERROR(MQTT_SET_PUBLISH_DUP_FAILED_ERROR);
header.byte = readChar(&read_data); /* read header */
if (header.bits.type != PUBLISH)
RETURN_ERROR(MQTT_SET_PUBLISH_DUP_FAILED);
RETURN_ERROR(MQTT_SET_PUBLISH_DUP_FAILED_ERROR);
header.bits.dup = dup;
writeChar(&write_data, header.byte); /* write header */
@@ -382,7 +382,7 @@ static int mqtt_ack_list_record(mqtt_client_t* c, int type, unsigned short packe
/* Determine if the node already exists */
if (mqtt_ack_list_node_is_exist(c, type, packet_id))
RETURN_ERROR(MQTT_ACK_NODE_IS_EXIST);
RETURN_ERROR(MQTT_ACK_NODE_IS_EXIST_ERROR);
/* create a ack handler node */
ack_handler = mqtt_ack_handler_create(c, type, packet_id, payload_len, handler);
@@ -552,7 +552,7 @@ static int mqtt_try_resubscribe(mqtt_client_t* c)
msg_handler = LIST_ENTRY(curr, message_handlers_t, list);
/* resubscribe topic */
if ((rc = mqtt_subscribe(c, msg_handler->topic_filter, msg_handler->qos, msg_handler->handler)) == MQTT_ACK_HANDLER_NUM_TOO_MUCH)
if ((rc = mqtt_subscribe(c, msg_handler->topic_filter, msg_handler->qos, msg_handler->handler)) == MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR)
LOG_W("%s:%d %s()... mqtt ack handler num too much ...", __FILE__, __LINE__, __FUNCTION__);
}
@@ -571,7 +571,7 @@ static int mqtt_try_do_reconnect(mqtt_client_t* c)
rc = mqtt_try_resubscribe(c); /* resubscribe */
}
LOG_I("%s:%d %s()... mqtt try connect result is %#x", __FILE__, __LINE__, __FUNCTION__, rc);
LOG_I("%s:%d %s()... mqtt try connect result is -0x%04x", __FILE__, __LINE__, __FUNCTION__, -rc);
RETURN_ERROR(rc);
}
@@ -751,7 +751,7 @@ static int mqtt_publish_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
mqtt_deliver_message(c, &topic_name, &msg);
else {
/* record the received of a qos2 message and only processes it when the qos2 message is received for the first time */
if ((rc = mqtt_ack_list_record(c, PUBREL, msg.id, len, NULL)) != MQTT_ACK_NODE_IS_EXIST)
if ((rc = mqtt_ack_list_record(c, PUBREL, msg.id, len, NULL)) != MQTT_ACK_NODE_IS_EXIST_ERROR)
mqtt_deliver_message(c, &topic_name, &msg);
}
@@ -1269,9 +1269,9 @@ int mqtt_publish(mqtt_client_t* c, const char* topic_filter, mqtt_message_t* msg
platform_mutex_lock(&c->write_lock);
if (msg->qos != QOS0) {
if (QOS0 != msg->qos) {
if (mqtt_ack_handler_is_maximum(c)) {
rc = MQTT_ACK_HANDLER_NUM_TOO_MUCH; /* the recorded ack handler has reached the maximum */
rc = MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR; /* the recorded ack handler has reached the maximum */
goto exit;
}
msg->id = mqtt_get_next_packet_id(c);
@@ -1302,6 +1302,13 @@ int mqtt_publish(mqtt_client_t* c, const char* topic_filter, mqtt_message_t* msg
exit:
platform_mutex_unlock(&c->write_lock);
if ((MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR == rc) || (MQTT_MEM_NOT_ENOUGH_ERROR == rc)) {
LOG_W("%s:%d %s()... there is not enough memory space to record...", __FILE__, __LINE__, __FUNCTION__);
/* record too much retransmitted data, may be disconnected, need to reconnect */
mqtt_set_client_state(c, CLIENT_STATE_DISCONNECTED);
}
RETURN_ERROR(rc);
}

View File

@@ -2,14 +2,14 @@
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2020-01-10 23:45:59
* @LastEditTime : 2020-01-13 02:48:53
* @LastEditTime: 2020-04-25 18:59:28
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "platform_net_socket.h"
int platform_net_socket_connect(const char *host, const char *port, int proto)
{
int fd, ret = MQTT_SOCKET_UNKNOWN_HOST;
int fd, ret = MQTT_SOCKET_UNKNOWN_HOST_ERROR;
#ifdef MQTT_NETSOCKET_USE_AT
fd = tos_sal_module_connect(host, port, TOS_SAL_PROTO_TCP);
@@ -36,7 +36,7 @@ int platform_net_socket_connect(const char *host, const char *port, int proto)
for (cur = addr_list; cur != NULL; cur = cur->ai_next) {
fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
if (fd < 0) {
ret = MQTT_SOCKET_FAILED;
ret = MQTT_SOCKET_FAILED_ERROR;
continue;
}