Update snapshot(2018-02-07)
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / tcp_adapter / catcpadapter.c
index 45c8ab9..9eb0c76 100644 (file)
@@ -374,6 +374,21 @@ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
         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
@@ -467,21 +482,19 @@ static bool CAClearQueueEndpointDataContext(void *data, uint32_t size, void *ctx
 
 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
 
@@ -491,14 +504,6 @@ CAResult_t CATCPDisconnectSession(const CAEndpoint_t *endpoint)
         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;
 }
 
@@ -635,6 +640,9 @@ void CATerminateTCP()
 
     CATCPDestroyMutex();
     CATCPDestroyCond();
+
+    CATCPDestroySendMutex();
+    CATCPDestroySendCond();
 }
 
 void CATCPSendDataThread(void *threadData)