return res;
}
+ res = CATCPCreateSendMutex();
+ if (CA_STATUS_OK == res)
+ {
+ res = CATCPCreateSendCond();
+ }
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "failed to create send data mutex/cond");
+ CATCPDestroyMutex();
+ CATCPDestroyCond();
+ CATCPDestroySendMutex();
+ CATCPDestroySendCond();
+ return res;
+ }
+
#ifndef SINGLE_THREAD
caglobals.tcp.threadpool = handle;
#endif
static bool CAClearQueueEndpointDataContext(void *data, uint32_t size, void *ctx)
{
+ (void)size;
+
if (NULL == data || NULL == ctx)
{
return false;
CAResult_t CATCPDisconnectSession(const CAEndpoint_t *endpoint)
{
- CAResult_t res = CA_STATUS_OK;
+ CAResult_t res = CAQueueingThreadClearContextData(g_sendQueueHandle,
+ CAClearQueueEndpointDataContext,
+ endpoint);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "failed to clear context data");
+ }
+
#ifdef __WITH_TLS__
res = CAcloseSslConnection(endpoint);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "failed to close TLS session");
- res = CAQueueingThreadClearContextData(g_sendQueueHandle,
- CAClearQueueEndpointDataContext,
- endpoint);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "failed to clear context data");
- }
-
- return res;
}
#endif
OIC_LOG(ERROR, TAG, "failed to close TCP session");
}
- res = CAQueueingThreadClearContextData(g_sendQueueHandle,
- CAClearQueueEndpointDataContext,
- endpoint);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "failed to clear context data");
- }
-
return res;
}
{
CAIPStopNetworkMonitor(CA_ADAPTER_TCP);
+ /* Some times send queue thread fails to terminate as it's worker
+ thread gets blocked at TCP session's socket connect operation.
+ So closing sockets which are in connect operation at the time
+ of termination of adapter would save send queue thread from
+ getting blocked. */
+ CATCPCloseInProgressConnections();
+
#ifndef SINGLE_THREAD
+ // Stop send queue thread.
if (g_sendQueueHandle && g_sendQueueHandle->threadMutex)
{
CAQueueingThreadStop(g_sendQueueHandle);
CATCPDeinitializeQueueHandles();
#endif
+ // Close TCP servers and established connections.
CATCPStopServer();
- //Re-initializing the Globals to start them again
+ // Re-initializing the Globals to start them again.
CAInitializeTCPGlobals();
return CA_STATUS_OK;
CATCPDestroyMutex();
CATCPDestroyCond();
+
+ CATCPDestroySendMutex();
+ CATCPDestroySendCond();
}
void CATCPSendDataThread(void *threadData)