Windows: Avoid using NULL event handle 05/22905/2
authorDan Mihai <Daniel.Mihai@microsoft.com>
Wed, 18 Oct 2017 15:36:50 +0000 (08:36 -0700)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Thu, 19 Oct 2017 14:24:23 +0000 (14:24 +0000)
Avoid using NULL event handle during catests.

Change-Id: I7e7d2ef95e8141082f7694735f20a77d773b42b4
Signed-off-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c

index 28f42ab..6a067f5 100644 (file)
@@ -1157,10 +1157,14 @@ void CATCPStopServer()
         caglobals.tcp.connectionFds[1] = OC_INVALID_SOCKET;
     }
 #else
-    // receive thread will stop immediately.
-    if (!WSASetEvent(caglobals.tcp.updateEvent))
+    // unit tests sometimes stop the TCP Server after starting just the UDP Server.
+    if (caglobals.tcp.updateEvent != NULL)
     {
-        OIC_LOG_V(DEBUG, TAG, "set shutdown event failed: %u", GetLastError());
+        // receive thread will stop immediately.
+        if (!WSASetEvent(caglobals.tcp.updateEvent))
+        {
+            OIC_LOG_V(DEBUG, TAG, "set shutdown event failed: %u", GetLastError());
+        }
     }
 #endif