static CAResult_t CATCPInitializeQueueHandles();
-static void CATCPDeinitializeQueueHandles();
+static void CATCPDeinitializeQueueHandles(CAQueueingThread_t *queueHandle);
static void CATCPSendDataThread(void *threadData);
return CA_STATUS_OK;
}
-void CATCPDeinitializeQueueHandles()
+void CATCPDeinitializeQueueHandles(CAQueueingThread_t *queueHandle)
{
- CAQueueingThreadDestroy(g_sendQueueHandle);
- OICFree(g_sendQueueHandle);
- g_sendQueueHandle = NULL;
+ CAQueueingThreadDestroy(queueHandle);
+ OICFree(queueHandle);
}
void CATCPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status)
#ifndef SINGLE_THREAD
// Stop send queue thread.
- if (g_sendQueueHandle && g_sendQueueHandle->threadMutex)
+ if (g_sendQueueHandle != NULL)
{
- CAQueueingThreadStop(g_sendQueueHandle);
+ // g_sendQueueHandle is set to NULL to prevent new requests from being enqueued.
+ CAQueueingThread_t *queueHandle = g_sendQueueHandle;
+ g_sendQueueHandle = NULL;
+
+ if (queueHandle->threadMutex)
+ {
+ CAQueueingThreadStop(queueHandle);
+ }
+ CATCPDeinitializeQueueHandles(queueHandle);
}
- CATCPDeinitializeQueueHandles();
#endif
// Close TCP servers and established connections.