MQTT API Reference
MQTT 3.1.1 client library
IotMqtt_SerializeDisconnect

Generate a DISCONNECT packet.

size_t bufferSize );
Parameters
[in,out]pBufferUser provide buffer where the DISCONNECT packet is written.
[in]bufferSizeSize of the buffer pointed to by pBuffer.
Returns
returns IOT_MQTT_SUCCESS or IOT_MQTT_BAD_PARAMETER
Note
This call is part of serializer API used for implementing light-weight MQTT client.

Example

// Example below shows how IotMqtt_SerializeDisconnect() should be used.
#define mqttexampleSHARED_BUFFER_SIZE 100
static ucSharedBuffer[mqttexampleSHARED_BUFFER_SIZE];
void sendDisconnectRequest( int xMQTTSocket )
{
size_t xSentBytes = 0;
// Disconnect is fixed length packet, therefore there is no need to calculate the size,
// just makes sure static buffer can accommodate disconnect request.
IotMqtt_Assert( MQTT_PACKET_DISCONNECT_SIZE <= mqttexampleSHARED_BUFFER_SIZE );
// Serialize Disconnect packet into static buffer (dynamically allocated buffer can be used as well)
// xMQTTSocket here is posix socket created and connected to MQTT broker outside of this function.
xSentByte = send( xMQTTSocket, ( void * ) ucSharedBuffer, MQTT_PACKET_DISCONNECT_SIZE, 0 );
}
IotMqttError_t
IotMqttError_t
Return codes of MQTT functions.
Definition: iot_mqtt_types.h:103
IOT_MQTT_SUCCESS
MQTT operation completed successfully.
Definition: iot_mqtt_types.h:119
IotMqtt_SerializeDisconnect
IotMqttError_t IotMqtt_SerializeDisconnect(uint8_t *pBuffer, size_t bufferSize)
Generate a DISCONNECT packet.
Definition: iot_mqtt_serialize.c:2439
MQTT_PACKET_DISCONNECT_SIZE
#define MQTT_PACKET_DISCONNECT_SIZE
A DISCONNECT packet is always 2 bytes in size.
Definition: iot_mqtt_serialize.c:148
IotMqtt_Assert
#define IotMqtt_Assert(expression)
Assertion macro for the MQTT library.
Definition: iot_mqtt_internal.h:62