Update snapshot(2017-12-06)
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / tcp_adapter / catcpadapter.c
index ac6f6d7..45c8ab9 100644 (file)
@@ -444,6 +444,8 @@ CAResult_t CAStartTCP()
 
 static bool CAClearQueueEndpointDataContext(void *data, uint32_t size, void *ctx)
 {
+    (void)size;
+
     if (NULL == data || NULL == ctx)
     {
         return false;
@@ -602,7 +604,15 @@ CAResult_t CAStopTCP()
 {
     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);
@@ -610,9 +620,10 @@ CAResult_t CAStopTCP()
     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;