mqtt_outbox: fix to store timestamps in long-long format

closes https://github.com/espressif/esp-mqtt/issues/144
closes IDFGH-2491
This commit is contained in:
David Cermak
2020-01-09 09:45:16 +01:00
parent 8ab095b5bb
commit 6e08f6a04f
3 changed files with 14 additions and 11 deletions

View File

@ -16,6 +16,7 @@ struct outbox_item;
typedef struct outbox_list_t *outbox_handle_t; typedef struct outbox_list_t *outbox_handle_t;
typedef struct outbox_item *outbox_item_handle_t; typedef struct outbox_item *outbox_item_handle_t;
typedef struct outbox_message *outbox_message_handle_t; typedef struct outbox_message *outbox_message_handle_t;
typedef long long outbox_tick_t;
typedef struct outbox_message { typedef struct outbox_message {
uint8_t *data; uint8_t *data;
@ -35,17 +36,17 @@ typedef enum pending_state {
} pending_state_t; } pending_state_t;
outbox_handle_t outbox_init(void); outbox_handle_t outbox_init(void);
outbox_item_handle_t outbox_enqueue(outbox_handle_t outbox, outbox_message_handle_t message, int tick); outbox_item_handle_t outbox_enqueue(outbox_handle_t outbox, outbox_message_handle_t message, outbox_tick_t tick);
outbox_item_handle_t outbox_dequeue(outbox_handle_t outbox, pending_state_t pending, int *tick); outbox_item_handle_t outbox_dequeue(outbox_handle_t outbox, pending_state_t pending, outbox_tick_t *tick);
outbox_item_handle_t outbox_get(outbox_handle_t outbox, int msg_id); outbox_item_handle_t outbox_get(outbox_handle_t outbox, int msg_id);
uint8_t *outbox_item_get_data(outbox_item_handle_t item, size_t *len, uint16_t *msg_id, int *msg_type, int *qos); uint8_t *outbox_item_get_data(outbox_item_handle_t item, size_t *len, uint16_t *msg_id, int *msg_type, int *qos);
esp_err_t outbox_delete(outbox_handle_t outbox, int msg_id, int msg_type); esp_err_t outbox_delete(outbox_handle_t outbox, int msg_id, int msg_type);
esp_err_t outbox_delete_msgid(outbox_handle_t outbox, int msg_id); esp_err_t outbox_delete_msgid(outbox_handle_t outbox, int msg_id);
esp_err_t outbox_delete_msgtype(outbox_handle_t outbox, int msg_type); esp_err_t outbox_delete_msgtype(outbox_handle_t outbox, int msg_type);
int outbox_delete_expired(outbox_handle_t outbox, int current_tick, int timeout); int outbox_delete_expired(outbox_handle_t outbox, outbox_tick_t current_tick, outbox_tick_t timeout);
esp_err_t outbox_set_pending(outbox_handle_t outbox, int msg_id, pending_state_t pending); esp_err_t outbox_set_pending(outbox_handle_t outbox, int msg_id, pending_state_t pending);
esp_err_t outbox_set_tick(outbox_handle_t outbox, int msg_id, int tick); esp_err_t outbox_set_tick(outbox_handle_t outbox, int msg_id, outbox_tick_t tick);
int outbox_get_size(outbox_handle_t outbox); int outbox_get_size(outbox_handle_t outbox);
esp_err_t outbox_cleanup(outbox_handle_t outbox, int max_size); esp_err_t outbox_cleanup(outbox_handle_t outbox, int max_size);
void outbox_destroy(outbox_handle_t outbox); void outbox_destroy(outbox_handle_t outbox);

View File

@ -15,7 +15,7 @@ typedef struct outbox_item {
int msg_id; int msg_id;
int msg_type; int msg_type;
int msg_qos; int msg_qos;
int tick; outbox_tick_t tick;
int retry_count; int retry_count;
pending_state_t pending; pending_state_t pending;
STAILQ_ENTRY(outbox_item) next; STAILQ_ENTRY(outbox_item) next;
@ -32,7 +32,7 @@ outbox_handle_t outbox_init(void)
return outbox; return outbox;
} }
outbox_item_handle_t outbox_enqueue(outbox_handle_t outbox, outbox_message_handle_t message, int tick) outbox_item_handle_t outbox_enqueue(outbox_handle_t outbox, outbox_message_handle_t message, outbox_tick_t tick)
{ {
outbox_item_handle_t item = calloc(1, sizeof(outbox_item_t)); outbox_item_handle_t item = calloc(1, sizeof(outbox_item_t));
ESP_MEM_CHECK(TAG, item, return NULL); ESP_MEM_CHECK(TAG, item, return NULL);
@ -67,7 +67,7 @@ outbox_item_handle_t outbox_get(outbox_handle_t outbox, int msg_id)
return NULL; return NULL;
} }
outbox_item_handle_t outbox_dequeue(outbox_handle_t outbox, pending_state_t pending, int *tick) outbox_item_handle_t outbox_dequeue(outbox_handle_t outbox, pending_state_t pending, outbox_tick_t *tick)
{ {
outbox_item_handle_t item; outbox_item_handle_t item;
STAILQ_FOREACH(item, outbox, next) { STAILQ_FOREACH(item, outbox, next) {
@ -131,7 +131,7 @@ esp_err_t outbox_set_pending(outbox_handle_t outbox, int msg_id, pending_state_t
return ESP_FAIL; return ESP_FAIL;
} }
esp_err_t outbox_set_tick(outbox_handle_t outbox, int msg_id, int tick) esp_err_t outbox_set_tick(outbox_handle_t outbox, int msg_id, outbox_tick_t tick)
{ {
outbox_item_handle_t item = outbox_get(outbox, msg_id); outbox_item_handle_t item = outbox_get(outbox, msg_id);
if (item) { if (item) {
@ -155,7 +155,7 @@ esp_err_t outbox_delete_msgtype(outbox_handle_t outbox, int msg_type)
return ESP_OK; return ESP_OK;
} }
int outbox_delete_expired(outbox_handle_t outbox, int current_tick, int timeout) int outbox_delete_expired(outbox_handle_t outbox, outbox_tick_t current_tick, outbox_tick_t timeout)
{ {
int deleted_items = 0; int deleted_items = 0;
outbox_item_handle_t item, tmp; outbox_item_handle_t item, tmp;

View File

@ -34,6 +34,8 @@
{ if (key) { setfn(ssl, key, strlen(key)); } } { if (key) { setfn(ssl, key, strlen(key)); } }
#endif #endif
_Static_assert(sizeof(uint64_t) == sizeof(outbox_tick_t), "mqtt-client tick type size different from outbox tick type");
static const char *TAG = "MQTT_CLIENT"; static const char *TAG = "MQTT_CLIENT";
#ifdef MQTT_SUPPORTED_FEATURE_EVENT_LOOP #ifdef MQTT_SUPPORTED_FEATURE_EVENT_LOOP
@ -1100,8 +1102,8 @@ static esp_err_t mqtt_resend_queued(esp_mqtt_client_handle_t client, outbox_item
static void esp_mqtt_task(void *pv) static void esp_mqtt_task(void *pv)
{ {
esp_mqtt_client_handle_t client = (esp_mqtt_client_handle_t) pv; esp_mqtt_client_handle_t client = (esp_mqtt_client_handle_t) pv;
uint32_t last_retransmit = 0; uint64_t last_retransmit = 0;
int32_t msg_tick = 0; outbox_tick_t msg_tick = 0;
client->run = true; client->run = true;
//get transport by scheme //get transport by scheme