AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
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 );
}