[IOT-1602] Remove observer when the tcp connection is disconnected
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Wed, 23 Nov 2016 13:51:58 +0000 (22:51 +0900)
committerZiran Sun <ziran.sun@samsung.com>
Mon, 28 Nov 2016 10:12:19 +0000 (10:12 +0000)
If the client observes one or more resources over a reliable
connection, then the CoAP server (or intermediary in the role of the
CoAP server) MUST remove all entries associated with the client
endpoint from the lists of observers when the connection is either
closed or times out.
Bug: https://jira.iotivity.org/browse/IOT-1602

Change-Id: I31dcf26a3dc731b4479c9d7a7a4755c7afd07ff8
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14683
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-by: Ziran Sun <ziran.sun@samsung.com>
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c
resource/csdk/stack/include/internal/ocobserve.h
resource/csdk/stack/src/ocobserve.c
resource/csdk/stack/src/ocstack.c

index 2d56a1c5569bc7ab50855f22d169b913d8896234..3e2ab585b274ad554eb39547d9603bca1a9438e9 100644 (file)
@@ -382,6 +382,12 @@ static void CAAcceptConnection(CATransportFlags_t flag, CASocket_t *sock)
         ca_mutex_unlock(g_mutexObjectList);
 
         CHECKFD(sockfd);
+
+        // pass the connection information to CA Common Layer.
+        if (g_connectionCallback)
+        {
+            g_connectionCallback(&(svritem->sep.endpoint), true);
+        }
     }
 }
 
index 85ecd4eb96049bdedfd4bd2350db91b824ee026d..284cfbae33f9a0d008fe754257d9c215012ca80d 100644 (file)
@@ -191,6 +191,16 @@ OCStackResult AddObserver (const char         *resUri,
  */
  OCStackResult DeleteObserverUsingToken (CAToken_t token, uint8_t tokenLength);
 
+ /**
+  * Delete observer with device address from list of observers.
+  * Free memory that was allocated for the observer in the list.
+  *
+  * @param devAddr Device's address.
+  *
+  * @return ::OC_STACK_OK on success, some other value upon failure.
+  */
+OCStackResult DeleteObserverUsingDevAddr(const OCDevAddr *devAddr);
+
 /**
  * Search the list of observers for the specified token.
  *
index 6d11070a2368d7415fb02ae39f9fbebff289bc61..f7b2d3c1843344aecfce203200fdafb2c88ea342 100644 (file)
@@ -554,6 +554,32 @@ OCStackResult DeleteObserverUsingToken (CAToken_t token, uint8_t tokenLength)
     return OC_STACK_OK;
 }
 
+OCStackResult DeleteObserverUsingDevAddr(const OCDevAddr *devAddr)
+{
+    if (!devAddr)
+    {
+        return OC_STACK_INVALID_PARAM;
+    }
+
+    ResourceObserver *out = NULL;
+    ResourceObserver *tmp = NULL;
+    LL_FOREACH_SAFE(g_serverObsList, out, tmp)
+    {
+        if (out)
+        {
+            if ((strcmp(out->devAddr.addr, devAddr->addr) == 0)
+                    && out->devAddr.port == devAddr->port)
+            {
+                OIC_LOG_V(INFO, TAG, "deleting observer id  %u with %s:%u",
+                          out->observeId, out->devAddr.addr, out->devAddr.port);
+                OCStackFeedBack(out->token, out->tokenLength, OC_OBSERVER_NOT_INTERESTED);
+            }
+        }
+    }
+
+    return OC_STACK_OK;
+}
+
 void DeleteObserverList()
 {
     ResourceObserver *out = NULL;
index 656544f6e1c815f61f143cf16ca2e53476227986..74b4e7daf2f612c4126fec6fb5e0a59a1cac27e0 100644 (file)
@@ -5042,6 +5042,21 @@ void OCDefaultConnectionStateChangedHandler(const CAEndpoint_t *info, bool isCon
     {
        g_connectionHandler(info, isConnected);
     }
+
+    /*
+     * If the client observes one or more resources over a reliable connection,
+     * then the CoAP server (or intermediary in the role of the CoAP server)
+     * MUST remove all entries associated with the client endpoint from the lists
+     * of observers when the connection is either closed or times out.
+     */
+    if (!isConnected)
+    {
+        OCDevAddr devAddr = { OC_DEFAULT_ADAPTER };
+        CopyEndpointToDevAddr(info, &devAddr);
+
+        // remove observer list with remote device address.
+        DeleteObserverUsingDevAddr(&devAddr);
+    }
 }
 
 void OCSetNetworkMonitorHandler(CAAdapterStateChangedCB adapterHandler,