]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
adding mosquitto_loop after mosquitto_publish, otherwise qos=1 messages would not...
authorviulian <viulian@gmail.com>
Tue, 27 Mar 2018 21:38:10 +0000 (23:38 +0200)
committerviulian <viulian@gmail.com>
Tue, 27 Mar 2018 21:38:10 +0000 (23:38 +0200)
src/mqtt.c

index d134c381b2ecfa875d7ecd31dd8dc25cf45e20d3..09060dfa7df4d6cc7c8cc211ee947ceb9597aa9e 100644 (file)
@@ -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 */