Hi Toby, mosquitto_publish() will attempt to carry out the network write immediately (unless it is called inside a callback), but will only write as much data as is currently possible. For small messages this means in practice it will probably be sent immediately. In this case, if the write failed an error code would be returned immediately and could be one of MOSQ_ERR_NO_CONN, MOSQ_ERR_CONN_LOST or MOSQ_ERR_ERRNO (consult errno) in addition to the non-network related errors such as MOSQ_ERR_NOMEM and MOSQ_ERR_PAYLOAD_SIZE.
If the message is not sent immediately, the network writes will occur on a later call to mosquitto_loop() which will return the same errors in the case of a failure. They're more on the lines of general network errors than publish failures though. on_publish is very much a "your message has been sent successfully" report, particularly for the higher QoS levels where it indicates that the handshake with the broker has completed successfully, not just that the message has been written to the network. In the case of a network dropout, partially sent messages should be retried when you reconnect but I'll have to check that actually happens. There's a whole load of tests waiting to be written around that sort of scenario. If you've got any suggestions for improvements I'd be happy to consider them. 0.16 is already an incompatible ABI/API so other changes that bring big improvements would be great. I have thought about passing a mosquitto_message struct to on_publish instead of just the mid but haven't implemented it yet. Cheers, Roger On Thu, Jun 7, 2012 at 1:02 AM, <[email protected]> wrote: > Hi, > > With libmosquitto, how does the caller find out if a request to publish has > failed? > mosquitto_publish() returns an error code immediately, but I assume that > publishing is asynchronous as mosquitto_publish_callback_set() exists. > > The callback passed to mosquitto_publish_callback_set() only gets fed the > context, mid and userdata. > > Is there a way to discover that an asynchronous request to publish has > failed? > Or is it that libmosquitto will always publish or fail immediately? > > Thanks. > > -- > > _______________________________________________ > Mailing list: https://launchpad.net/~mqtt-users > Post to : [email protected] > Unsubscribe : https://launchpad.net/~mqtt-users > More help : https://help.launchpad.net/ListHelp _______________________________________________ Mailing list: https://launchpad.net/~mqtt-users Post to : [email protected] Unsubscribe : https://launchpad.net/~mqtt-users More help : https://help.launchpad.net/ListHelp

