MQTT C Client Libraries Internals
MQTT Client Library Internals

In the beginning there was one MQTT C client library, MQTTClient, as implemented in MQTTClient.c This library was designed to be easy to use for applications which didn't mind if some of the calls blocked for a while. For instance, the MQTTClient_connect call will block until a successful connection has completed, or a connection has failed, which could be as long as the "connection timeout" interval, whose default is 30 seconds.

However in mobile devices and other windowing environments, blocking on the GUI thread is a bad thing as it causes the user interface to freeze. Hence a new API, MQTTAsync, implemented in MQTTAsync.c, was devised. There are no blocking calls in this library, so it is well suited to GUI and mobile environments, at the expense of some extra complexity.

Both libraries are designed to be sparing in the use of threads. So multiple client objects are handled by one or two threads, with a select call in Socket_getReadySocket(), used to determine when a socket has incoming data. This API is thread safe: functions may be called by multiple application threads, with the exception of MQTTClient_yield and MQTTClient_receive, which are intended for single threaded environments only.