From: viulian Date: Tue, 27 Mar 2018 21:38:10 +0000 (+0200) Subject: adding mosquitto_loop after mosquitto_publish, otherwise qos=1 messages would not... X-Git-Tag: collectd-5.12.0~44^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40863119b554520dd53d5cea010f56bd653be9ed;p=thirdparty%2Fcollectd.git adding mosquitto_loop after mosquitto_publish, otherwise qos=1 messages would not be considered acknowledged by the broker --- diff --git a/src/mqtt.c b/src/mqtt.c index d134c381b..09060dfa7 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -445,6 +445,26 @@ static int publish(mqtt_client_conf_t *conf, char const *topic, return -1; } + // -1 means default timeout, 1000ms + // second argument is unused, set to 1 for future compatibility + status = mosquitto_loop(conf->mosq, -1, 1); + + if (status != MOSQ_ERR_SUCCESS) { + c_complain(LOG_ERR, &conf->complaint_cantpublish, + "mqtt plugin: mosquitto_loop failed: %s", + (status == MOSQ_ERR_ERRNO) + ? STRERRNO + : mosquitto_strerror(status)); + /* Mark our connection "down" regardless of the error as a safety + * measure; we will try to reconnect the next time we have to publish a + * message */ + conf->connected = 0; + mosquitto_disconnect(conf->mosq); + + pthread_mutex_unlock(&conf->lock); + return -1; + } + pthread_mutex_unlock(&conf->lock); return 0; } /* int publish */