IOT-2242 Port recent TCP adapter fix to Windows
authorDan Mihai <Daniel.Mihai@microsoft.com>
Fri, 12 May 2017 22:45:08 +0000 (15:45 -0700)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Mon, 15 May 2017 19:00:02 +0000 (19:00 +0000)
Port change be6cd0c7bacf86e45c498d18633f360b55c5a036 to Windows.

Unfortunately, Jenkins ignored the Windows build error for that change.

Change-Id: I059fa2d6b3bdd345f490239ea8a89612dbe8ceb9
Signed-off-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19855
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
Reviewed-by: Way Vadhanasin <wayvad@microsoft.com>
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c

index 13d78e4..5de71a8 100644 (file)
@@ -518,6 +518,8 @@ static void CASocketEventReturned(CASocketFd_t s, long networkEvents)
         return;
     }
 
+    assert(s != OC_INVALID_SOCKET);
+
     if (FD_ACCEPT & networkEvents)
     {
         if ((caglobals.tcp.ipv4.fd != OC_INVALID_SOCKET) && (caglobals.tcp.ipv4.fd == s))
@@ -532,7 +534,31 @@ static void CASocketEventReturned(CASocketFd_t s, long networkEvents)
 
     if (FD_READ & networkEvents)
     {
-        CAReceiveMessage(s);
+        oc_mutex_lock(g_mutexObjectList);
+        CATCPSessionInfo_t *session = NULL;
+        CATCPSessionInfo_t *tmp = NULL;
+        LL_FOREACH_SAFE(g_sessionList, session, tmp)
+        {
+            if (session && (session->fd == s))
+            {
+                CAResult_t res = CAReceiveMessage(session);
+                //disconnect session and clean-up data if any error occurs
+                if (res != CA_STATUS_OK)
+                {
+#ifdef __WITH_TLS__
+                    if (CA_STATUS_OK != CAcloseSslConnection(&session->sep.endpoint))
+                    {
+                        OIC_LOG(ERROR, TAG, "Failed to close TLS session");
+                    }
+#endif
+                    LL_DELETE(g_sessionList, session);
+                    CADisconnectTCPSession(session);
+                    oc_mutex_unlock(g_mutexObjectList);
+                    return;
+                }
+            }
+        }
+        oc_mutex_unlock(g_mutexObjectList);
     }
 }