$SYS/broker/clients/disconnected should never be negative.

Closes #287. Thanks to Lovisa Johansson.

Bug: https://github.com/eclipse/mosquitto/issues/287
pull/1029/head
Roger A. Light 7 years ago
parent 0368a8c01d
commit 9f7577aab6

@ -6,6 +6,7 @@ Broker:
a client that send a PUBLISH then DISCONNECT quickly, then disconnects will
have its DISCONNECT message processed properly and so no Will will be sent.
Closes #7.
- $SYS/broker/clients/disconnected should never be negative. Closes #287.
Library:
- Fix memory leak that occurred if mosquitto_reconnect() was used when TLS
@ -15,6 +16,7 @@ Build:
- Fix clients not being compiled with threading support when using CMake.
Closes #983.
1.5.3 - 20180925
================

@ -60,8 +60,8 @@ static void sys_tree__update_clients(struct mosquitto_db *db, char *buf)
static unsigned int client_count = -1;
static int clients_expired = -1;
static unsigned int client_max = 0;
static unsigned int disconnected_count = -1;
static unsigned int connected_count = -1;
static int disconnected_count = -1;
static int connected_count = -1;
unsigned int count_total, count_by_sock;
@ -82,6 +82,13 @@ static void sys_tree__update_clients(struct mosquitto_db *db, char *buf)
if(disconnected_count != count_total-count_by_sock){
disconnected_count = count_total-count_by_sock;
if(disconnected_count < 0){
/* If a client has connected but not sent a CONNECT at this point,
* then it is possible that count_by_sock will be bigger than
* count_total, causing a negative number. This situation should
* not last for long, so just cap at zero and ignore. */
disconnected_count = 0;
}
snprintf(buf, BUFLEN, "%d", disconnected_count);
db__messages_easy_queue(db, NULL, "$SYS/broker/clients/inactive", SYS_TREE_QOS, strlen(buf), buf, 1);
db__messages_easy_queue(db, NULL, "$SYS/broker/clients/disconnected", SYS_TREE_QOS, strlen(buf), buf, 1);

Loading…
Cancel
Save