+static bool CAClearQueueEndpointDataContext(void *data, uint32_t size, void *ctx)
+{
+ if (NULL == data || NULL == ctx)
+ {
+ return false;
+ }
+
+ CATCPData *tcpData = (CATCPData *)data;
+ CAEndpoint_t *endpoint = (CAEndpoint_t *)ctx;
+
+ if (NULL != tcpData && NULL != tcpData->remoteEndpoint)
+ {
+ if (strcmp(tcpData->remoteEndpoint->addr, endpoint->addr) == 0
+ && tcpData->remoteEndpoint->port == endpoint->port)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+CAResult_t CATCPDisconnectSession(const CAEndpoint_t *endpoint)
+{
+ CAResult_t res = CA_STATUS_OK;
+#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
+
+ res = CASearchAndDeleteTCPSession(endpoint);
+ if (CA_STATUS_OK != res)
+ {
+ 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;
+}
+