Update snapshot(2018-01-04)
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / tcp_adapter / catcpserver.c
index 7741e68..7136fe0 100644 (file)
 static ca_thread_pool_t g_threadPool = NULL;
 
 /**
- * An unique identifier of receive thread.
- */
-static uint32_t g_recvThreadId = 0;
-
-/**
  * Mutex to synchronize device object list.
  */
 static oc_mutex g_mutexObjectList = NULL;
@@ -980,14 +975,13 @@ CAResult_t CATCPStartServer(const ca_thread_pool_t threadPool)
 
     CAResult_t res = CA_STATUS_OK;
 #ifndef __TIZENRT__
-    res = ca_thread_pool_add_task(g_threadPool, CAReceiveHandler, NULL, &g_recvThreadId);
+    res = ca_thread_pool_add_task(g_threadPool, CAReceiveHandler, NULL, NULL);
 #else
-    res = ca_thread_pool_add_task(g_threadPool, CAReceiveHandler, NULL, &g_recvThreadId,
+    res = ca_thread_pool_add_task(g_threadPool, CAReceiveHandler, NULL, NULL,
                                  "IoT_TCPReceive", CONFIG_IOTIVITY_TCPRECEIVE_PTHREAD_STACKSIZE);
 #endif
     if (CA_STATUS_OK != res)
     {
-        g_recvThreadId = 0;
         oc_mutex_unlock(g_mutexObjectList);
         OIC_LOG(ERROR, TAG, "thread_pool_add_task failed");
         CATCPStopServer();
@@ -1014,6 +1008,14 @@ void CATCPStopServer()
     // set terminate flag.
     caglobals.tcp.terminate = true;
 
+#ifdef __TIZENRT__
+    if (caglobals.tcp.started)
+    {
+        oc_cond_wait(g_condObjectList, g_mutexObjectList);
+        caglobals.tcp.started = false;
+    }
+#endif
+
     // close accept socket.
 #ifndef __WITH_TLS__
     CLOSE_SOCKET(ipv4);
@@ -1034,25 +1036,17 @@ void CATCPStopServer()
         caglobals.tcp.shutdownFds[1] = OC_INVALID_SOCKET;
         // receive thread will stop immediately
     }
-#endif
     if (caglobals.tcp.started)
     {
         oc_cond_wait(g_condObjectList, g_mutexObjectList);
         caglobals.tcp.started = false;
     }
-#ifndef __TIZENRT__
     if (caglobals.tcp.shutdownFds[0] != OC_INVALID_SOCKET)
     {
         close(caglobals.tcp.shutdownFds[0]);
         caglobals.tcp.shutdownFds[0] = OC_INVALID_SOCKET;
     }
 #endif
-    CAResult_t res = ca_thread_pool_remove_task(g_threadPool, g_recvThreadId);
-    if (CA_STATUS_OK != res)
-    {
-        OIC_LOG(ERROR, TAG, "ca_thread_pool_remove_task failed");
-    }
-    g_recvThreadId = 0;
     oc_mutex_unlock(g_mutexObjectList);
 
     CATCPDisconnectAll();