in source/coreMQTT/sockets_wrapper.c [755:811]
void Sockets_Disconnect( Socket_t xSocket )
{
int32_t retClose = SOCKETS_ERROR_NONE;
cellularSocketWrapper_t * pCellularSocketContext = ( cellularSocketWrapper_t * ) xSocket;
CellularSocketHandle_t cellularSocketHandle = NULL;
uint32_t recvLength = 0;
uint8_t buf[ 128 ] = { 0 };
CellularError_t cellularSocketStatus = CELLULAR_SUCCESS;
/* xSocket need to be check against SOCKET_INVALID_SOCKET. */
/* coverity[misra_c_2012_rule_11_4_violation] */
if( ( pCellularSocketContext == NULL ) || ( xSocket == SOCKETS_INVALID_SOCKET ) )
{
IotLogError( "Invalid xSocket %p", pCellularSocketContext );
retClose = SOCKETS_EINVAL;
}
else
{
cellularSocketHandle = pCellularSocketContext->cellularSocketHandle;
}
if( retClose == SOCKETS_ERROR_NONE )
{
if( cellularSocketHandle != NULL )
{
/* Receive all the data before socket close. */
do
{
recvLength = 0;
cellularSocketStatus = Cellular_SocketRecv( CellularHandle, cellularSocketHandle, buf, 128, &recvLength );
IotLogDebug( "%u bytes received in close", recvLength );
} while( ( recvLength != 0 ) && ( cellularSocketStatus == CELLULAR_SUCCESS ) );
/* Close sockets. */
if( Cellular_SocketClose( CellularHandle, cellularSocketHandle ) != CELLULAR_SUCCESS )
{
IotLogWarn( "Failed to destroy connection." );
retClose = SOCKETS_SOCKET_ERROR;
}
( void ) Cellular_SocketRegisterDataReadyCallback( CellularHandle, cellularSocketHandle, NULL, NULL );
( void ) Cellular_SocketRegisterSocketOpenCallback( CellularHandle, cellularSocketHandle, NULL, NULL );
( void ) Cellular_SocketRegisterClosedCallback( CellularHandle, cellularSocketHandle, NULL, NULL );
pCellularSocketContext->cellularSocketHandle = NULL;
}
if( pCellularSocketContext->socketEventGroupHandle != NULL )
{
vEventGroupDelete( pCellularSocketContext->socketEventGroupHandle );
pCellularSocketContext->socketEventGroupHandle = NULL;
}
vPortFree( pCellularSocketContext );
}
IotLogDebug( "Sockets close exit with code %d", retClose );
}