static JavaVM *g_jvm;
+/**
+ * when Both Mode(server and client) in App is set,
+ * startDiscoveryServer and startListenningServer is calling.
+ * and then both accept thread and receive thread is running redundantly.
+ */
+static bool g_isStartServer = false;
+
/**
* Maximum CoAP over TCP header length
* to know the total data length.
*/
static ca_mutex g_mutexObjectList = NULL;
+/**
+ * Mutex to synchronize start server state.
+ */
+static ca_mutex g_mutexStartServerState = NULL;
+
/**
* Thread context information for unicast, multicast and secured unicast server.
*/
return CA_STATUS_NOT_INITIALIZED;
}
+ ca_mutex_lock(g_mutexStartServerState);
+ if (g_isStartServer)
+ {
+ OIC_LOG(DEBUG, TAG, "server already started");
+ ca_mutex_unlock(g_mutexStartServerState);
+ return CA_STATUS_OK;
+ }
+ ca_mutex_unlock(g_mutexStartServerState);
+
CAResult_t res = CAEDRServerStartAcceptThread();
if (CA_STATUS_OK == res)
{
CAEDRServerStop();
return CA_STATUS_FAILED;
}
+ ca_mutex_lock(g_mutexStartServerState);
+ g_isStartServer = true;
+ ca_mutex_unlock(g_mutexStartServerState);
}
return res;
}
CAEDRNatvieCloseServerTask(env);
+ ca_mutex_lock(g_mutexStartServerState);
+ g_isStartServer = false;
+ ca_mutex_unlock(g_mutexStartServerState);
if (isAttached)
{
ca_mutex_free(g_mutexObjectList);
g_mutexObjectList = NULL;
}
+
+ if (g_mutexStartServerState)
+ {
+ ca_mutex_free(g_mutexStartServerState);
+ g_mutexStartServerState = NULL;
+ }
}
static CAResult_t CAEDRServerCreateMutex()
return CA_STATUS_FAILED;
}
+ g_mutexStartServerState = ca_mutex_new();
+ if (!g_mutexStartServerState)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to created mutex!");
+
+ CAEDRServerDestroyMutex();
+ return CA_STATUS_FAILED;
+ }
+
return CA_STATUS_OK;
}