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();
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
#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;
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)
{
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)
{
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)
CATCPDestroySendMutex();
CATCPDestroySendCond();
+
+ g_skipCloseOnIFDown = false;
+
+ // Free adapter mutex
+ if (g_mutexAdapter)
+ {
+ oc_mutex_free(g_mutexAdapter);
+ g_mutexAdapter = NULL;
+ }
}
void CATCPSendDataThread(void *threadData)
#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");