From 9faf89be8d58d3903b8a43892e2c6e008d22bd86 Mon Sep 17 00:00:00 2001 From: Roger Light Date: Sun, 14 Mar 2021 19:24:56 +0000 Subject: [PATCH] Set `receive-maximum` to not exceed the `-C` message count. This is for mosquitto_sub and mosquitto_rr, to avoid potentially lost messages. Closes #2134. Thanks to Frantisek Fuka. --- ChangeLog.txt | 8 ++++++++ client/client_shared.c | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 063e29a18a..e112c086ea 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,11 @@ +2.0.10 - 2021-xx-xx +================== + +Clients: +- Set `receive-maximum` to not exceed the `-C` message count in mosquitto_sub + and mosquitto_rr, to avoid potentially lost messages. Closes #2134. + + 2.0.9 - 2021-03-11 ================== diff --git a/client/client_shared.c b/client/client_shared.c index 26755b7b18..68a12b3982 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -1321,6 +1321,13 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg) if(cfg->tcp_nodelay){ mosquitto_int_option(mosq, MOSQ_OPT_TCP_NODELAY, 1); } + + if(cfg->msg_count > 0 && cfg->msg_count < 20){ + /* 20 is the default "receive maximum" + * If we don't set this, then we can receive > msg_count messages + * before we quit.*/ + mosquitto_int_option(mosq, MOSQ_OPT_RECEIVE_MAXIMUM, cfg->msg_count); + } return MOSQ_ERR_SUCCESS; }