Classes | Macros | Typedefs | Enumerations | Functions | Variables
MQTTAsync.c File Reference

Asynchronous API implementation. More...

#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "MQTTPersistence.h"
#include "MQTTAsync.h"
#include "utf-8.h"
#include "MQTTProtocol.h"
#include "MQTTProtocolOut.h"
#include "Thread.h"
#include "SocketBuffer.h"
#include "StackTrace.h"
#include "Heap.h"
#include "OsWrapper.h"
#include "WebSocket.h"
#include "VersionInfo.h"
Include dependency graph for MQTTAsync.c:

Go to the source code of this file.

Classes

struct  keyloc
 
struct  MQTTAsync_command
 
struct  MQTTAsync_queuedCommand
 
struct  MQTTAsync_struct
 
struct  qEntry
 

Macros

#define MAX_INFO_STRINGS   8
 
#define min(a, b)   (((a) < (b)) ? (a) : (b))
 
#define URI_TCP   "tcp://"
 
#define URI_WS   "ws://"
 
#define URI_WSS   "wss://"
 
#define WINAPI
 

Typedefs

typedef struct MQTTAsync_struct MQTTAsyncs
 

Enumerations

enum  MQTTAsync_threadStates { STOPPED, STARTING, RUNNING, STOPPING }
 

Functions

static int clientCompareConnectCommand (void *a, void *b)
 
static int clientSockCompare (void *a, void *b)
 
static int clientStructCompare (void *a, void *b)
 
static int cmdMessageIDCompare (void *a, void *b)
 
static int cmpkeys (const void *p1, const void *p2)
 
static int MQTTAsync_addCommand (MQTTAsync_queuedCommand *command, int command_size)
 
static int MQTTAsync_assignMsgId (MQTTAsyncs *m)
 
static int MQTTAsync_checkConn (MQTTAsync_command *command, MQTTAsyncs *client)
 
static void MQTTAsync_checkDisconnect (MQTTAsync handle, MQTTAsync_command *command)
 
static void MQTTAsync_checkTimeouts (void)
 
static int MQTTAsync_cleanSession (Clients *client)
 
static void MQTTAsync_closeOnly (Clients *client, enum MQTTReasonCodes reasonCode, MQTTProperties *props)
 
static void MQTTAsync_closeSession (Clients *client, enum MQTTReasonCodes reasonCode, MQTTProperties *props)
 
static int MQTTAsync_completeConnection (MQTTAsyncs *m, Connack *connack)
 
int MQTTAsync_connect (MQTTAsync handle, const MQTTAsync_connectOptions *options)
 
static int MQTTAsync_connecting (MQTTAsyncs *m)
 
int MQTTAsync_create (MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context)
 
int MQTTAsync_createWithOptions (MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context, MQTTAsync_createOptions *options)
 
static MQTTPacketMQTTAsync_cycle (int *sock, unsigned long timeout, int *rc)
 
static int MQTTAsync_deliverMessage (MQTTAsyncs *m, char *topicName, size_t topicLen, MQTTAsync_message *mm)
 
void MQTTAsync_destroy (MQTTAsync *handle)
 
int MQTTAsync_disconnect (MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
 
static int MQTTAsync_disconnect1 (MQTTAsync handle, const MQTTAsync_disconnectOptions *options, int internal)
 
static int MQTTAsync_disconnect_internal (MQTTAsync handle, int timeout)
 
static void MQTTAsync_emptyMessageQueue (Clients *client)
 
void MQTTAsync_free (void *memory)
 
static void MQTTAsync_freeCommand (MQTTAsync_queuedCommand *command)
 
static void MQTTAsync_freeCommand1 (MQTTAsync_queuedCommand *command)
 
static void MQTTAsync_freeCommands (MQTTAsyncs *m)
 
void MQTTAsync_freeMessage (MQTTAsync_message **message)
 
static void MQTTAsync_freeResponses (MQTTAsyncs *m)
 
static void MQTTAsync_freeServerURIs (MQTTAsyncs *m)
 
static int MQTTAsync_getNoBufferedMessages (MQTTAsyncs *m)
 
int MQTTAsync_getPendingTokens (MQTTAsync handle, MQTTAsync_token **tokens)
 
MQTTAsync_nameValueMQTTAsync_getVersionInfo (void)
 
void MQTTAsync_global_init (MQTTAsync_init_options *inits)
 
int MQTTAsync_init (void)
 
void MQTTAsync_init_rand (void)
 
static void MQTTAsync_insertInOrder (List *list, void *content, int size, struct keyloc *keyloc_array, int array_size)
 
int MQTTAsync_isComplete (MQTTAsync handle, MQTTAsync_token dt)
 
int MQTTAsync_isConnected (MQTTAsync handle)
 
static void MQTTAsync_lock_mutex (mutex_type amutex)
 
void * MQTTAsync_malloc (size_t size)
 
static int MQTTAsync_persistCommand (MQTTAsync_queuedCommand *qcmd)
 
static int MQTTAsync_processCommand (void)
 
int MQTTAsync_randomJitter (int currentIntervalBase, int minInterval, int maxInterval)
 
static thread_return_type WINAPI MQTTAsync_receiveThread (void *n)
 
int MQTTAsync_reconnect (MQTTAsync handle)
 
static MQTTAsync_queuedCommandMQTTAsync_restoreCommand (char *buffer, int buflen, int MQTTVersion, MQTTAsync_queuedCommand *)
 
static int MQTTAsync_restoreCommands (MQTTAsyncs *client)
 
static void MQTTAsync_retry (void)
 
int MQTTAsync_send (MQTTAsync handle, const char *destinationName, int payloadlen, const void *payload, int qos, int retained, MQTTAsync_responseOptions *response)
 
int MQTTAsync_sendMessage (MQTTAsync handle, const char *destinationName, const MQTTAsync_message *message, MQTTAsync_responseOptions *response)
 
static thread_return_type WINAPI MQTTAsync_sendThread (void *n)
 
int MQTTAsync_setAfterPersistenceRead (MQTTAsync handle, void *context, MQTTPersistence_afterRead *co)
 
int MQTTAsync_setBeforePersistenceWrite (MQTTAsync handle, void *context, MQTTPersistence_beforeWrite *co)
 
int MQTTAsync_setCallbacks (MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
 
int MQTTAsync_setConnected (MQTTAsync handle, void *context, MQTTAsync_connected *connected)
 
int MQTTAsync_setConnectionLostCallback (MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl)
 
int MQTTAsync_setDeliveryCompleteCallback (MQTTAsync handle, void *context, MQTTAsync_deliveryComplete *dc)
 
int MQTTAsync_setDisconnected (MQTTAsync handle, void *context, MQTTAsync_disconnected *disconnected)
 
int MQTTAsync_setMessageArrivedCallback (MQTTAsync handle, void *context, MQTTAsync_messageArrived *ma)
 
void MQTTAsync_setTraceCallback (MQTTAsync_traceCallback *callback)
 
void MQTTAsync_setTraceLevel (enum MQTTASYNC_TRACE_LEVELS level)
 
int MQTTAsync_setUpdateConnectOptions (MQTTAsync handle, void *context, MQTTAsync_updateConnectOptions *updateOptions)
 
void MQTTAsync_sleep (long milliseconds)
 
static int MQTTAsync_Socket_noPendingWrites (int socket)
 
static void MQTTAsync_startConnectRetry (MQTTAsyncs *m)
 
static void MQTTAsync_stop (void)
 
const char * MQTTAsync_strerror (int code)
 
int MQTTAsync_subscribe (MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
 
int MQTTAsync_subscribeMany (MQTTAsync handle, int count, char *const *topic, int *qos, MQTTAsync_responseOptions *response)
 
static void MQTTAsync_terminate (void)
 
static void MQTTAsync_unlock_mutex (mutex_type amutex)
 
static int MQTTAsync_unpersistCommand (MQTTAsync_queuedCommand *qcmd)
 
static int MQTTAsync_unpersistCommandsAndMessages (Clients *c)
 
static int MQTTAsync_unpersistInflightMessages (Clients *c)
 
int MQTTAsync_unsubscribe (MQTTAsync handle, const char *topic, MQTTAsync_responseOptions *response)
 
int MQTTAsync_unsubscribeMany (MQTTAsync handle, int count, char *const *topic, MQTTAsync_responseOptions *response)
 
int MQTTAsync_waitForCompletion (MQTTAsync handle, MQTTAsync_token dt, unsigned long timeout)
 
static void MQTTAsync_writeComplete (int socket, int rc)
 
static void MQTTProtocol_checkPendingWrites (void)
 
void MQTTProtocol_closeSession (Clients *c, int sendwill)
 
static void nextOrClose (MQTTAsyncs *m, int rc, char *message)
 
void Protocol_processPublication (Publish *publish, Clients *client, int allocatePayload)
 
static void setRetryLoopInterval (int keepalive)
 

Variables

ClientStatesbstate = &ClientState
 
const char * client_timestamp_eye = "MQTTAsyncV3_Timestamp " BUILD_TIMESTAMP
 
const char * client_version_eye = "MQTTAsyncV3_Version " CLIENT_VERSION
 
static ClientStates ClientState
 
static Listcommands = NULL
 
static volatile int global_initialized = 0
 
static Listhandles = NULL
 
static mutex_type mqttasync_mutex = &mqttasync_mutex_store
 
static pthread_mutex_t mqttasync_mutex_store = PTHREAD_MUTEX_INITIALIZER
 
static mutex_type mqttcommand_mutex = &mqttcommand_mutex_store
 
static pthread_mutex_t mqttcommand_mutex_store = PTHREAD_MUTEX_INITIALIZER
 
static thread_id_type receiveThread_id = 0
 
enum MQTTAsync_threadStates receiveThread_state = STOPPED
 
static int retryLoopInterval = 5
 
static cond_type send_cond = &send_cond_store
 
static cond_type_struct send_cond_store = { PTHREAD_COND_INITIALIZER, PTHREAD_MUTEX_INITIALIZER }
 
static thread_id_type sendThread_id = 0
 
enum MQTTAsync_threadStates sendThread_state = STOPPED
 
static mutex_type socket_mutex = &socket_mutex_store
 
static pthread_mutex_t socket_mutex_store = PTHREAD_MUTEX_INITIALIZER
 
MQTTProtocol state
 
static int tostop = 0
 

Detailed Description

Asynchronous API implementation.

Definition in file MQTTAsync.c.

Macro Definition Documentation

#define MAX_INFO_STRINGS   8
#define min (   a,
 
)    (((a) < (b)) ? (a) : (b))

Definition at line 88 of file MQTTAsync.c.

#define URI_TCP   "tcp://"

Definition at line 67 of file MQTTAsync.c.

#define URI_WS   "ws://"

Definition at line 68 of file MQTTAsync.c.

#define URI_WSS   "wss://"

Definition at line 69 of file MQTTAsync.c.

#define WINAPI

Definition at line 298 of file MQTTAsync.c.

Typedef Documentation

typedef struct MQTTAsync_struct MQTTAsyncs

Enumeration Type Documentation

Enumerator
STOPPED 
STARTING 
RUNNING 
STOPPING 

Definition at line 121 of file MQTTAsync.c.

Function Documentation

static int clientCompareConnectCommand ( void *  a,
void *  b 
)
static

List callback function for comparing client handles and command types being CONNECT or DISCONNECT

Parameters
afirst MQTTAsync_queuedCommand pointer
bsecond MQTTAsync_queuedCommand pointer
Returns
boolean indicating whether a and b are equal

Definition at line 1403 of file MQTTAsync.c.

static int clientSockCompare ( void *  a,
void *  b 
)
static

List callback function for comparing clients by socket

Parameters
afirst integer value
bsecond integer value
Returns
boolean indicating whether a and b are equal

Definition at line 536 of file MQTTAsync.c.

static int clientStructCompare ( void *  a,
void *  b 
)
static

List callback function for comparing clients by client structure

Parameters
aAsync structure
bClient structure
Returns
boolean indicating whether a and b are equal

Definition at line 3315 of file MQTTAsync.c.

static int cmdMessageIDCompare ( void *  a,
void *  b 
)
static

Definition at line 3947 of file MQTTAsync.c.

static int cmpkeys ( const void *  p1,
const void *  p2 
)
static

Definition at line 1220 of file MQTTAsync.c.

static int MQTTAsync_addCommand ( MQTTAsync_queuedCommand command,
int  command_size 
)
static

Definition at line 1420 of file MQTTAsync.c.

static int MQTTAsync_assignMsgId ( MQTTAsyncs m)
static

Assign a new message id for a client. Make sure it isn't already being used and does not exceed the maximum.

Parameters
ma client structure
Returns
the next message id to use, or 0 if none available

Definition at line 3960 of file MQTTAsync.c.

static int MQTTAsync_checkConn ( MQTTAsync_command command,
MQTTAsyncs client 
)
static

Definition at line 563 of file MQTTAsync.c.

static void MQTTAsync_checkDisconnect ( MQTTAsync  handle,
MQTTAsync_command command 
)
static

Definition at line 1592 of file MQTTAsync.c.

static void MQTTAsync_checkTimeouts ( void  )
static

Definition at line 2294 of file MQTTAsync.c.

static int MQTTAsync_cleanSession ( Clients client)
static

Clean the MQTT session data. This includes the MQTT inflight messages, because that is part of the MQTT state that will be cleared by the MQTT broker too. However, queued up messages, outgoing or incoming, need (should?) not be cleared as they are outside the scope of the MQTT session.

Definition at line 3328 of file MQTTAsync.c.

static void MQTTAsync_closeOnly ( Clients client,
enum MQTTReasonCodes  reasonCode,
MQTTProperties props 
)
static

Definition at line 3266 of file MQTTAsync.c.

static void MQTTAsync_closeSession ( Clients client,
enum MQTTReasonCodes  reasonCode,
MQTTProperties props 
)
static

Definition at line 3296 of file MQTTAsync.c.

static int MQTTAsync_completeConnection ( MQTTAsyncs m,
Connack connack 
)
static

Definition at line 2647 of file MQTTAsync.c.

int MQTTAsync_connect ( MQTTAsync  handle,
const MQTTAsync_connectOptions options 
)

This function attempts to connect a previously-created client (see MQTTAsync_create()) to an MQTT server using the specified options. If you want to enable asynchronous message and status notifications, you must call MQTTAsync_setCallbacks() prior to MQTTAsync_connect().

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
optionsA pointer to a valid MQTTAsync_connectOptions structure.
Returns
MQTTASYNC_SUCCESS if the client connect request was accepted. If the client was unable to connect to the server, an error code is returned via the onFailure callback, if set. Error codes greater than 0 are returned by the MQTT protocol:

1: Connection refused: Unacceptable protocol version
2: Connection refused: Identifier rejected
3: Connection refused: Server unavailable
4: Connection refused: Bad user name or password
5: Connection refused: Not authorized
6-255: Reserved for future use

Definition at line 3480 of file MQTTAsync.c.

static int MQTTAsync_connecting ( MQTTAsyncs m)
static

Definition at line 4377 of file MQTTAsync.c.

int MQTTAsync_create ( MQTTAsync handle,
const char *  serverURI,
const char *  clientId,
int  persistence_type,
void *  persistence_context 
)

This function creates an MQTT client ready for connection to the specified server and using the specified persistent storage (see MQTTAsync_persistence). See also MQTTAsync_destroy().

Parameters
handleA pointer to an MQTTAsync handle. The handle is populated with a valid client reference following a successful return from this function.
serverURIA null-terminated string specifying the server to which the client will connect. It takes the form protocol://host:port. protocol must be tcp, ssl, ws or wss. The TLS enabled prefixes (ssl, wss) are only valid if a TLS version of the library is linked with. For host, you can specify either an IP address or a host name. For instance, to connect to a server running on the local machines with the default MQTT port, specify tcp://localhost:1883.
clientIdThe client identifier passed to the server when the client connects to it. It is a null-terminated UTF-8 encoded string.
persistence_typeThe type of persistence to be used by the client:
MQTTCLIENT_PERSISTENCE_NONE: Use in-memory persistence. If the device or system on which the client is running fails or is switched off, the current state of any in-flight messages is lost and some messages may not be delivered even at QoS1 and QoS2.
MQTTCLIENT_PERSISTENCE_DEFAULT: Use the default (file system-based) persistence mechanism. Status about in-flight messages is held in persistent storage and provides some protection against message loss in the case of unexpected failure.
MQTTCLIENT_PERSISTENCE_USER: Use an application-specific persistence implementation. Using this type of persistence gives control of the persistence mechanism to the application. The application has to implement the MQTTClient_persistence interface.
persistence_contextIf the application uses MQTTCLIENT_PERSISTENCE_NONE persistence, this argument is unused and should be set to NULL. For MQTTCLIENT_PERSISTENCE_DEFAULT persistence, it should be set to the location of the persistence directory (if set to NULL, the persistence directory used is the working directory). Applications that use MQTTCLIENT_PERSISTENCE_USER persistence set this argument to point to a valid MQTTClient_persistence structure.
Returns
MQTTASYNC_SUCCESS if the client is successfully created, otherwise an error code is returned.

Definition at line 737 of file MQTTAsync.c.

int MQTTAsync_createWithOptions ( MQTTAsync handle,
const char *  serverURI,
const char *  clientId,
int  persistence_type,
void *  persistence_context,
MQTTAsync_createOptions options 
)

Definition at line 575 of file MQTTAsync.c.

static MQTTPacket * MQTTAsync_cycle ( int *  sock,
unsigned long  timeout,
int *  rc 
)
static

Definition at line 4569 of file MQTTAsync.c.

static int MQTTAsync_deliverMessage ( MQTTAsyncs m,
char *  topicName,
size_t  topicLen,
MQTTAsync_message mm 
)
static

Definition at line 3381 of file MQTTAsync.c.

void MQTTAsync_destroy ( MQTTAsync handle)

This function frees the memory allocated to an MQTT client (see MQTTAsync_create()). It should be called when the client is no longer required.

Parameters
handleA pointer to the handle referring to the MQTTAsync structure to be freed.

Definition at line 2554 of file MQTTAsync.c.

int MQTTAsync_disconnect ( MQTTAsync  handle,
const MQTTAsync_disconnectOptions options 
)

This function attempts to disconnect the client from the MQTT server. In order to allow the client time to complete handling of messages that are in-flight when this function is called, a timeout period is specified. When the timeout period has expired, the client disconnects even if there are still outstanding message acknowledgements. The next time the client connects to the same server, any QoS 1 or 2 messages which have not completed will be retried depending on the cleansession settings for both the previous and the new connection (see MQTTAsync_connectOptions.cleansession and MQTTAsync_connect()).

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
optionsThe client delays disconnection for up to this time (in milliseconds) in order to allow in-flight message transfers to complete.
Returns
MQTTASYNC_SUCCESS if the client successfully disconnects from the server. An error code is returned if the client was unable to disconnect from the server

Definition at line 3923 of file MQTTAsync.c.

static int MQTTAsync_disconnect1 ( MQTTAsync  handle,
const MQTTAsync_disconnectOptions options,
int  internal 
)
static

Definition at line 3856 of file MQTTAsync.c.

static int MQTTAsync_disconnect_internal ( MQTTAsync  handle,
int  timeout 
)
static

Definition at line 3908 of file MQTTAsync.c.

static void MQTTAsync_emptyMessageQueue ( Clients client)
static

Definition at line 2432 of file MQTTAsync.c.

void MQTTAsync_free ( void *  ptr)

This function frees memory allocated by the MQTT C client library, especially the topic name. This is needed on Windows when the client library and application program have been compiled with different versions of the C compiler. It is thus good policy to always use this function when freeing any MQTT C client- allocated memory.

Parameters
ptrThe pointer to the client library storage to be freed.

Definition at line 2626 of file MQTTAsync.c.

static void MQTTAsync_freeCommand ( MQTTAsync_queuedCommand command)
static

Definition at line 1723 of file MQTTAsync.c.

static void MQTTAsync_freeCommand1 ( MQTTAsync_queuedCommand command)
static

Definition at line 1684 of file MQTTAsync.c.

static void MQTTAsync_freeCommands ( MQTTAsyncs m)
static

Definition at line 2500 of file MQTTAsync.c.

void MQTTAsync_freeMessage ( MQTTAsync_message **  msg)

This function frees memory allocated to an MQTT message, including the additional memory allocated to the message payload. The client application calls this function when the message has been fully processed. Important note: This function does not free the memory allocated to a message topic string. It is the responsibility of the client application to free this memory using the MQTTAsync_free() library function.

Parameters
msgThe address of a pointer to the MQTTAsync_message structure to be freed.

Definition at line 2615 of file MQTTAsync.c.

static void MQTTAsync_freeResponses ( MQTTAsyncs m)
static

Definition at line 2452 of file MQTTAsync.c.

static void MQTTAsync_freeServerURIs ( MQTTAsyncs m)
static

Definition at line 1671 of file MQTTAsync.c.

static int MQTTAsync_getNoBufferedMessages ( MQTTAsyncs m)
static

Definition at line 4219 of file MQTTAsync.c.

int MQTTAsync_getPendingTokens ( MQTTAsync  handle,
MQTTAsync_token **  tokens 
)

This function sets a pointer to an array of tokens for messages that are currently in-flight (pending completion).

Important note: The memory used to hold the array of tokens is malloc()'d in this function. The client application is responsible for freeing this memory when it is no longer required.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
tokensThe address of a pointer to an MQTTAsync_token. When the function returns successfully, the pointer is set to point to an array of tokens representing messages pending completion. The last member of the array is set to -1 to indicate there are no more tokens. If no tokens are pending, the pointer is set to NULL.
Returns
MQTTASYNC_SUCCESS if the function returns successfully. An error code is returned if there was a problem obtaining the list of pending tokens.

Definition at line 4737 of file MQTTAsync.c.

MQTTAsync_nameValue* MQTTAsync_getVersionInfo ( void  )

This function returns version information about the library. no trace information will be returned. The default trace level is MQTTASYNC_TRACE_MINIMUM

Returns
an array of strings describing the library. The last entry is a NULL pointer.

Definition at line 4909 of file MQTTAsync.c.

void MQTTAsync_global_init ( MQTTAsync_init_options inits)

Global init of mqtt library. Call once on program start to set global behaviour. handle_openssl_init - if mqtt library should handle openssl init (1) or rely on the caller to init it before using mqtt (0)

Definition at line 79 of file MQTTAsync.c.

int MQTTAsync_init ( void  )

Definition at line 273 of file MQTTAsync.c.

void MQTTAsync_init_rand ( void  )

Definition at line 104 of file MQTTAsync.c.

static void MQTTAsync_insertInOrder ( List list,
void *  content,
int  size,
struct keyloc keyloc_array,
int  array_size 
)
static

Inserts the specified message into the list, maintaining command sequence no order.

Parameters
listthe list to insert the message into.
contentthe message to add.
sizesize of the message.

Definition at line 1155 of file MQTTAsync.c.

int MQTTAsync_isComplete ( MQTTAsync  handle,
MQTTAsync_token  dt 
)

Definition at line 4803 of file MQTTAsync.c.

int MQTTAsync_isConnected ( MQTTAsync  handle)

This function allows the client application to test whether or not a client is currently connected to the MQTT server.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
Returns
Boolean true if the client is connected, otherwise false.

Definition at line 3932 of file MQTTAsync.c.

static void MQTTAsync_lock_mutex ( mutex_type  amutex)
static

Definition at line 543 of file MQTTAsync.c.

void* MQTTAsync_malloc ( size_t  size)

This function is used to allocate memory to be used or freed by the MQTT C client library, especially the data in the MQTTPersistence_afterRead and MQTTPersistence_beforeWrite callbacks. This is needed on Windows when the client library and application program have been compiled with different versions of the C compiler.

Parameters
sizeThe size of the memory to be allocated.

Definition at line 2634 of file MQTTAsync.c.

static int MQTTAsync_persistCommand ( MQTTAsync_queuedCommand qcmd)
static

Definition at line 789 of file MQTTAsync.c.

static int MQTTAsync_processCommand ( void  )
static

Definition at line 1841 of file MQTTAsync.c.

int MQTTAsync_randomJitter ( int  currentIntervalBase,
int  minInterval,
int  maxInterval 
)

Definition at line 496 of file MQTTAsync.c.

static thread_return_type WINAPI MQTTAsync_receiveThread ( void *  n)
static

Definition at line 2696 of file MQTTAsync.c.

int MQTTAsync_reconnect ( MQTTAsync  handle)

Reconnects a client with the previously used connect options. Connect must have previously been called for this to work.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
Returns
MQTTASYNC_SUCCESS if the callbacks were correctly set, MQTTASYNC_FAILURE if an error occurred.

Definition at line 1545 of file MQTTAsync.c.

static MQTTAsync_queuedCommand * MQTTAsync_restoreCommand ( char *  buffer,
int  buflen,
int  MQTTVersion,
MQTTAsync_queuedCommand qcommand 
)
static

Definition at line 961 of file MQTTAsync.c.

static int MQTTAsync_restoreCommands ( MQTTAsyncs client)
static

Definition at line 1229 of file MQTTAsync.c.

static void MQTTAsync_retry ( void  )
static

Definition at line 4358 of file MQTTAsync.c.

int MQTTAsync_send ( MQTTAsync  handle,
const char *  destinationName,
int  payloadlen,
const void *  payload,
int  qos,
int  retained,
MQTTAsync_responseOptions response 
)

This function attempts to publish a message to a given topic (see also MQTTAsync_sendMessage()). An MQTTAsync_token is issued when this function returns successfully. If the client application needs to test for successful delivery of messages, a callback should be set (see MQTTAsync_onSuccess() and MQTTAsync_deliveryComplete()).

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
destinationNameThe topic associated with this message.
payloadlenThe length of the payload in bytes.
payloadA pointer to the byte array payload of the message.
qosThe qos of the message.
retainedThe retained flag for the message.
responseA pointer to an MQTTAsync_responseOptions structure. Used to set callback functions. This is optional and can be set to NULL.
Returns
MQTTASYNC_SUCCESS if the message is accepted for publication. An error code is returned if there was a problem accepting the message.

Definition at line 4230 of file MQTTAsync.c.

int MQTTAsync_sendMessage ( MQTTAsync  handle,
const char *  destinationName,
const MQTTAsync_message msg,
MQTTAsync_responseOptions response 
)

This function attempts to publish a message to a given topic (see also MQTTAsync_publish()). An MQTTAsync_token is issued when this function returns successfully. If the client application needs to test for successful delivery of messages, a callback should be set (see MQTTAsync_onSuccess() and MQTTAsync_deliveryComplete()).

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
destinationNameThe topic associated with this message.
msgA pointer to a valid MQTTAsync_message structure containing the payload and attributes of the message to be published.
responseA pointer to an MQTTAsync_responseOptions structure. Used to set callback functions.
Returns
MQTTASYNC_SUCCESS if the message is accepted for publication. An error code is returned if there was a problem accepting the message.

Definition at line 4328 of file MQTTAsync.c.

static thread_return_type WINAPI MQTTAsync_sendThread ( void *  n)
static

Definition at line 2393 of file MQTTAsync.c.

int MQTTAsync_setAfterPersistenceRead ( MQTTAsync  handle,
void *  context,
MQTTPersistence_afterRead co 
)

Sets the MQTTPersistence_afterRead() callback function for a client.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
contextA pointer to any application-specific context. The the context pointer is passed to the callback function to provide access to the context information in the callback.
coA pointer to an MQTTPersistence_beforeWrite() callback function. NULL removes the callback setting.

Definition at line 3244 of file MQTTAsync.c.

int MQTTAsync_setBeforePersistenceWrite ( MQTTAsync  handle,
void *  context,
MQTTPersistence_beforeWrite co 
)

Sets the MQTTPersistence_beforeWrite() callback function for a client.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
contextA pointer to any application-specific context. The the context pointer is passed to the callback function to provide access to the context information in the callback.
coA pointer to an MQTTPersistence_beforeWrite() callback function. NULL removes the callback setting.

Definition at line 3222 of file MQTTAsync.c.

int MQTTAsync_setCallbacks ( MQTTAsync  handle,
void *  context,
MQTTAsync_connectionLost cl,
MQTTAsync_messageArrived ma,
MQTTAsync_deliveryComplete dc 
)

This function sets the global callback functions for a specific client. If your client application doesn't use a particular callback, set the relevant parameter to NULL. Any necessary message acknowledgements and status communications are handled in the background without any intervention from the client application. If you do not set a messageArrived callback function, you will not be notified of the receipt of any messages as a result of a subscription.

Note: The MQTT client must be disconnected when this function is called.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
contextA pointer to any application-specific context. The the context pointer is passed to each of the callback functions to provide access to the context information in the callback.
clA pointer to an MQTTAsync_connectionLost() callback function. You can set this to NULL if your application doesn't handle disconnections.
maA pointer to an MQTTAsync_messageArrived() callback function. If this callback is not set, an error will be returned. You must set this callback because otherwise there would be no way to deliver any incoming messages.
dcA pointer to an MQTTAsync_deliveryComplete() callback function. You can set this to NULL if you do not want to check for successful delivery.
Returns
MQTTASYNC_SUCCESS if the callbacks were correctly set, MQTTASYNC_FAILURE if an error occurred.

Definition at line 3062 of file MQTTAsync.c.

int MQTTAsync_setConnected ( MQTTAsync  handle,
void *  context,
MQTTAsync_connected co 
)

Sets the MQTTAsync_connected() callback function for a client.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
contextA pointer to any application-specific context. The the context pointer is passed to each of the callback functions to provide access to the context information in the callback.
coA pointer to an MQTTAsync_connected() callback function. NULL removes the callback setting.
Returns
MQTTASYNC_SUCCESS if the callbacks were correctly set, MQTTASYNC_FAILURE if an error occurred.

Definition at line 3178 of file MQTTAsync.c.

int MQTTAsync_setConnectionLostCallback ( MQTTAsync  handle,
void *  context,
MQTTAsync_connectionLost cl 
)

This function sets the callback function for a connection lost event for a specific client. Any necessary message acknowledgements and status communications are handled in the background without any intervention from the client application.

Note: The MQTT client must be disconnected when this function is called.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
contextA pointer to any application-specific context. The the context pointer is passed the callback functions to provide access to the context information in the callback.
clA pointer to an MQTTAsync_connectionLost() callback function. You can set this to NULL if your application doesn't handle disconnections.
Returns
MQTTASYNC_SUCCESS if the callbacks were correctly set, MQTTASYNC_FAILURE if an error occurred.

Definition at line 3088 of file MQTTAsync.c.

int MQTTAsync_setDeliveryCompleteCallback ( MQTTAsync  handle,
void *  context,
MQTTAsync_deliveryComplete dc 
)

This function sets the callback function for a delivery complete event for a specific client. Any necessary message acknowledgements and status communications are handled in the background without any intervention from the client application.

Note: The MQTT client must be disconnected when this function is called.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
contextA pointer to any application-specific context. The the context pointer is passed to the callback functions to provide access to the context information in the callback.
dcA pointer to an MQTTAsync_deliveryComplete() callback function. You can set this to NULL if you do not want to check for successful delivery.
Returns
MQTTASYNC_SUCCESS if the callbacks were correctly set, MQTTASYNC_FAILURE if an error occurred.

Definition at line 3133 of file MQTTAsync.c.

int MQTTAsync_setDisconnected ( MQTTAsync  handle,
void *  context,
MQTTAsync_disconnected co 
)

Sets the MQTTAsync_disconnected() callback function for a client.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().

Note: Neither MQTTAsync_create() nor MQTTAsync_destroy() should be called within this callback.

Parameters
contextA pointer to any application-specific context. The the context pointer is passed to each of the callback functions to provide access to the context information in the callback.
coA pointer to an MQTTAsync_connected() callback function. NULL removes the callback setting.
Returns
MQTTASYNC_SUCCESS if the callbacks were correctly set, MQTTASYNC_FAILURE if an error occurred.

Definition at line 3156 of file MQTTAsync.c.

int MQTTAsync_setMessageArrivedCallback ( MQTTAsync  handle,
void *  context,
MQTTAsync_messageArrived ma 
)

This function sets the callback function for a message arrived event for a specific client. Any necessary message acknowledgements and status communications are handled in the background without any intervention from the client application. If you do not set a messageArrived callback function, you will not be notified of the receipt of any messages as a result of a subscription.

Note: The MQTT client must be disconnected when this function is called.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
contextA pointer to any application-specific context. The the context pointer is passed to the callback functions to provide access to the context information in the callback.
maA pointer to an MQTTAsync_messageArrived() callback function. You can set this to NULL if your application doesn't handle receipt of messages.
Returns
MQTTASYNC_SUCCESS if the callbacks were correctly set, MQTTASYNC_FAILURE if an error occurred.

Definition at line 3111 of file MQTTAsync.c.

void MQTTAsync_setTraceCallback ( MQTTAsync_traceCallback callback)

This function sets the trace callback if needed. If set to NULL, no trace information will be returned. The default trace level is MQTTASYNC_TRACE_MINIMUM.

Parameters
callbacka pointer to the function which will handle the trace information

Definition at line 4903 of file MQTTAsync.c.

void MQTTAsync_setTraceLevel ( enum MQTTASYNC_TRACE_LEVELS  level)

This function sets the level of trace information which will be returned in the trace callback.

Parameters
levelthe trace level required

Definition at line 4897 of file MQTTAsync.c.

int MQTTAsync_setUpdateConnectOptions ( MQTTAsync  handle,
void *  context,
MQTTAsync_updateConnectOptions co 
)

Sets the MQTTAsync_updateConnectOptions() callback function for a client.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
contextA pointer to any application-specific context. The the context pointer is passed to each of the callback functions to provide access to the context information in the callback.
coA pointer to an MQTTAsync_updateConnectOptions() callback function. NULL removes the callback setting.

Definition at line 3200 of file MQTTAsync.c.

void MQTTAsync_sleep ( long  milliseconds)

Definition at line 480 of file MQTTAsync.c.

static int MQTTAsync_Socket_noPendingWrites ( int  socket)
static

Call Socket_noPendingWrites(int socket) with protection by socket_mutex, see https://github.com/eclipse/paho.mqtt.c/issues/385

Definition at line 1634 of file MQTTAsync.c.

static void MQTTAsync_startConnectRetry ( MQTTAsyncs m)
static

Definition at line 1526 of file MQTTAsync.c.

static void MQTTAsync_stop ( void  )
static

Definition at line 3017 of file MQTTAsync.c.

const char* MQTTAsync_strerror ( int  code)

Returns a pointer to a string representation of the error code, or NULL. Do not free after use. Returns NULL if the error code is unknown.

Parameters
codethe MQTTASYNC_ return code.
Returns
a static string representation of the error code.

Definition at line 4944 of file MQTTAsync.c.

int MQTTAsync_subscribe ( MQTTAsync  handle,
const char *  topic,
int  qos,
MQTTAsync_responseOptions response 
)

This function attempts to subscribe a client to a single topic, which may contain wildcards (see wildcard). This call also specifies the qos requested for the subscription (see also MQTTAsync_subscribeMany()).

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
topicThe subscription topic, which may include wildcards.
qosThe requested quality of service for the subscription.
responseA pointer to a response options structure. Used to set callback functions.
Returns
MQTTASYNC_SUCCESS if the subscription request is successful. An error code is returned if there was a problem registering the subscription.

Definition at line 4121 of file MQTTAsync.c.

int MQTTAsync_subscribeMany ( MQTTAsync  handle,
int  count,
char *const *  topic,
int *  qos,
MQTTAsync_responseOptions response 
)

This function attempts to subscribe a client to a list of topics, which may contain wildcards (see wildcard). This call also specifies the qos requested for each topic (see also MQTTAsync_subscribe()).

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
countThe number of topics for which the client is requesting subscriptions.
topicAn array (of length count) of pointers to topics, each of which may include wildcards.
qosAn array (of length count) of qos values. qos[n] is the requested QoS for topic[n].
responseA pointer to a response options structure. Used to set callback functions.
Returns
MQTTASYNC_SUCCESS if the subscription request is successful. An error code is returned if there was a problem registering the subscriptions.

Definition at line 4004 of file MQTTAsync.c.

static void MQTTAsync_terminate ( void  )
static

Definition at line 747 of file MQTTAsync.c.

static void MQTTAsync_unlock_mutex ( mutex_type  amutex)
static

Definition at line 551 of file MQTTAsync.c.

static int MQTTAsync_unpersistCommand ( MQTTAsync_queuedCommand qcmd)
static

Definition at line 772 of file MQTTAsync.c.

static int MQTTAsync_unpersistCommandsAndMessages ( Clients c)
static

Definition at line 1323 of file MQTTAsync.c.

static int MQTTAsync_unpersistInflightMessages ( Clients c)
static

Definition at line 1359 of file MQTTAsync.c.

int MQTTAsync_unsubscribe ( MQTTAsync  handle,
const char *  topic,
MQTTAsync_responseOptions response 
)

This function attempts to remove an existing subscription made by the specified client.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
topicThe topic for the subscription to be removed, which may include wildcards (see wildcard).
responseA pointer to a response options structure. Used to set callback functions.
Returns
MQTTASYNC_SUCCESS if the subscription is removed. An error code is returned if there was a problem removing the subscription.

Definition at line 4209 of file MQTTAsync.c.

int MQTTAsync_unsubscribeMany ( MQTTAsync  handle,
int  count,
char *const *  topic,
MQTTAsync_responseOptions response 
)

This function attempts to remove existing subscriptions to a list of topics made by the specified client.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
countThe number subscriptions to be removed.
topicAn array (of length count) of pointers to the topics of the subscriptions to be removed, each of which may include wildcards.
responseA pointer to a response options structure. Used to set callback functions.
Returns
MQTTASYNC_SUCCESS if the subscriptions are removed. An error code is returned if there was a problem removing the subscriptions.

Definition at line 4131 of file MQTTAsync.c.

int MQTTAsync_waitForCompletion ( MQTTAsync  handle,
MQTTAsync_token  token,
unsigned long  timeout 
)

Waits for a request corresponding to a token to complete.

Parameters
handleA valid client handle from a successful call to MQTTAsync_create().
tokenAn MQTTAsync_token associated with a request.
timeoutthe maximum time to wait for completion, in milliseconds
Returns
MQTTASYNC_SUCCESS if the request has been completed in the time allocated, MQTTASYNC_FAILURE or MQTTASYNC_DISCONNECTED if not.

Definition at line 4848 of file MQTTAsync.c.

static void MQTTAsync_writeComplete ( int  socket,
int  rc 
)
static

Definition at line 1730 of file MQTTAsync.c.

static void MQTTProtocol_checkPendingWrites ( void  )
static

See if any pending writes have been completed, and cleanup if so. Cleaning up means removing any publication data that was stored because the write did not originally complete.

Definition at line 1648 of file MQTTAsync.c.

void MQTTProtocol_closeSession ( Clients c,
int  sendwill 
)

Definition at line 3917 of file MQTTAsync.c.

static void nextOrClose ( MQTTAsyncs m,
int  rc,
char *  message 
)
static

Definition at line 2235 of file MQTTAsync.c.

void Protocol_processPublication ( Publish publish,
Clients client,
int  allocatePayload 
)

Definition at line 3396 of file MQTTAsync.c.

static void setRetryLoopInterval ( int  keepalive)
static

Definition at line 3467 of file MQTTAsync.c.

Variable Documentation

Definition at line 117 of file MQTTAsync.c.

const char* client_timestamp_eye = "MQTTAsyncV3_Timestamp " BUILD_TIMESTAMP

Definition at line 73 of file MQTTAsync.c.

const char* client_version_eye = "MQTTAsyncV3_Version " CLIENT_VERSION

Definition at line 74 of file MQTTAsync.c.

ClientStates ClientState
static
Initial value:
=
{
CLIENT_VERSION,
NULL
}

Definition at line 111 of file MQTTAsync.c.

List* commands = NULL
static

Definition at line 304 of file MQTTAsync.c.

volatile int global_initialized = 0
static

Definition at line 301 of file MQTTAsync.c.

List* handles = NULL
static

Definition at line 302 of file MQTTAsync.c.

mutex_type mqttasync_mutex = &mqttasync_mutex_store
static

Definition at line 262 of file MQTTAsync.c.

pthread_mutex_t mqttasync_mutex_store = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 261 of file MQTTAsync.c.

mutex_type mqttcommand_mutex = &mqttcommand_mutex_store
static

Definition at line 268 of file MQTTAsync.c.

pthread_mutex_t mqttcommand_mutex_store = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 267 of file MQTTAsync.c.

thread_id_type receiveThread_id = 0
static

Definition at line 129 of file MQTTAsync.c.

enum MQTTAsync_threadStates receiveThread_state = STOPPED

Definition at line 127 of file MQTTAsync.c.

int retryLoopInterval = 5
static

Definition at line 3465 of file MQTTAsync.c.

cond_type send_cond = &send_cond_store
static

Definition at line 271 of file MQTTAsync.c.

cond_type_struct send_cond_store = { PTHREAD_COND_INITIALIZER, PTHREAD_MUTEX_INITIALIZER }
static

Definition at line 270 of file MQTTAsync.c.

thread_id_type sendThread_id = 0
static

Definition at line 128 of file MQTTAsync.c.

enum MQTTAsync_threadStates sendThread_state = STOPPED

Definition at line 126 of file MQTTAsync.c.

mutex_type socket_mutex = &socket_mutex_store
static

Definition at line 265 of file MQTTAsync.c.

pthread_mutex_t socket_mutex_store = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 264 of file MQTTAsync.c.

MQTTProtocol state

global heap state information

Definition at line 119 of file MQTTAsync.c.

int tostop = 0
static

Definition at line 303 of file MQTTAsync.c.



plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:49