Option to skip close TCP on IF down. 80/197180/1
authorHarish Kumara M <h.marappa@samsung.com>
Fri, 4 Jan 2019 14:22:45 +0000 (19:52 +0530)
committerAmit KS <amit.s12@samsung.com>
Thu, 10 Jan 2019 07:02:38 +0000 (12:32 +0530)
This is VD specific requirement, not to close TCP
servers when interface down event is received.
New API "CAUtilSkipTCPCloseOnInterfaceDown" is
defined using which application can enable/disable
skip TCP server feature.

Signed-off-by: Harish Kumara M <h.marappa@samsung.com>
fix: save build error

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/388
(cherry picked from commit 725041caab8e0c1f14c6333cd066ea61a845893d)

Change-Id: Ifaf37379955d0d5615f08d43824148b6cbe075d3
Signed-off-by: Harish Kumara M <h.marappa@samsung.com>
Signed-off-by: Amit KS <amit.s12@samsung.com>
resource/csdk/connectivity/api/cautilinterface.h
resource/csdk/connectivity/inc/catcpadapter.h
resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c
resource/csdk/connectivity/util/src/cautilinterface.c

index 324ce53..341fdbb 100644 (file)
@@ -330,6 +330,15 @@ CAResult_t CAUtilTCPDisconnectSession(const char *address,
                                       uint16_t port,
                                       CATransportFlags_t flags);
 
+/**
+ * Enable or disable skip closing TCP servers
+ * when network interface is down.
+ *
+ * @param[in]   state    true to skip closing TCP servers,
+ *                       otherwise false.
+ */
+void CAUtilSkipTCPCloseOnInterfaceDown(bool state);
+
 CAResult_t CAUtilStartGattServer();
 CAResult_t CAUtilStopGattServer();
 
index d1e7d20..00f1cf3 100644 (file)
@@ -113,6 +113,15 @@ CAResult_t CAStartTCP();
 CAResult_t CATCPDisconnectSession(const CAEndpoint_t *endpoint);
 
 /**
+ * Enable or disable skip closing TCP servers
+ * when network interface is down.
+ *
+ * @param[in]   state    true to skip closing TCP servers,
+ *                       otherwise false.
+ */
+void CATCPSkipCloseOnInterfaceDown(bool state);
+
+/**
  * Start listening server for receiving connect requests.
  * Transport Specific Behavior:
  * TCP Starts Listening Server on a particular interface and prefixed port
index 5fc9828..0e33b46 100644 (file)
@@ -64,6 +64,16 @@ typedef struct
 #define CA_TCP_SELECT_TIMEOUT 10
 
 /**
+ * Mutex to synchronize TCP adapter access.
+ */
+static oc_mutex g_mutexAdapter = NULL;
+
+/**
+ * State to control closing of TCP servers on interface down event.
+ */
+static bool g_skipCloseOnIFDown;
+
+/**
  * Queue handle for Send Data.
  */
 static CAQueueingThread_t *g_sendQueueHandle = NULL;
@@ -290,7 +300,16 @@ void CATCPAdapterHandler(CATransportAdapter_t adapter, CANetworkStatus_t status)
             OIC_LOG_V(ERROR, TAG, "CAQueueingThreadClearData failed[%d]", res);
         }
 
-        CATCPStopServer();
+        oc_mutex_lock(g_mutexAdapter);
+        if (!g_skipCloseOnIFDown)
+        {
+            CATCPStopServer();
+        }
+        else
+        {
+            OIC_LOG(INFO, TAG, "Skip closing servers!");
+        }
+        oc_mutex_unlock(g_mutexAdapter);
     }
     else if (CA_INTERFACE_UP == status)
     {
@@ -364,6 +383,19 @@ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
 
     CAInitializeTCPGlobals();
 
+    // Create Mutex for synchronize access at adapter level
+    if (!g_mutexAdapter)
+    {
+        g_mutexAdapter = oc_mutex_new();
+        if (!g_mutexAdapter)
+        {
+            OIC_LOG(ERROR, TAG, "Failed to create mutex!");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    g_skipCloseOnIFDown = false;
+
     CAResult_t res = CATCPCreateMutex();
     if (CA_STATUS_OK == res)
     {
@@ -510,6 +542,13 @@ CAResult_t CATCPDisconnectSession(const CAEndpoint_t *endpoint)
     return res;
 }
 
+void CATCPSkipCloseOnInterfaceDown(bool state)
+{
+    oc_mutex_lock(g_mutexAdapter);
+    g_skipCloseOnIFDown = state;
+    oc_mutex_unlock(g_mutexAdapter);
+}
+
 CAResult_t CAStartTCPListeningServer()
 {
 #if !defined(SINGLE_THREAD) && !defined(DISABLE_TCP_SERVER)
@@ -651,6 +690,15 @@ void CATerminateTCP()
 
     CATCPDestroySendMutex();
     CATCPDestroySendCond();
+
+    g_skipCloseOnIFDown = false;
+
+    // Free adapter mutex
+    if (g_mutexAdapter)
+    {
+        oc_mutex_free(g_mutexAdapter);
+        g_mutexAdapter = NULL;
+    }
 }
 
 void CATCPSendDataThread(void *threadData)
index 806b5b1..4724dfc 100644 (file)
@@ -464,6 +464,16 @@ CAResult_t CAUtilTCPDisconnectSession(const char *address, uint16_t port, CATran
 #endif
 }
 
+void CAUtilSkipTCPCloseOnInterfaceDown(bool state)
+{
+#ifdef TCP_ADAPTER
+    CATCPSkipCloseOnInterfaceDown(state);
+#else
+    (void) state;
+    OIC_LOG(DEBUG, TAG, "Not supported!");
+#endif
+}
+
 CAResult_t CAUtilStartGattServer()
 {
        OIC_LOG(DEBUG, TAG, "CAUtilStartGattServer");