I need to properly de-initialize the client, ideally ensuring that client, before disconnecting and destroying, will attempt to send all pending publish messages. If there’s no such explicit function like flush, maybe there’s more complicated way to query how many inflight messages are there, and probably implement some timeout function (e.g. if number of messages do not decrease within 10 seconds - forcefully terminate otherwise wait)?
Edit: I put
mosquitto_loop(mosq, 5000, 1); but after careful consideration do not think it is the right command to perform the task.