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 oc_mutex g_mutexObjectList = NULL;
/**
+ * Mutex to synchronize start server state.
+ */
+static oc_mutex g_mutexStartServerState = NULL;
+
+/**
* Thread context information for unicast, multicast and secured unicast server.
*/
typedef struct
static void CAReceiveHandler(void *data)
{
- OIC_LOG(DEBUG, TAG, "IN - CAReceiveHandler..");
+ OIC_LOG(DEBUG, TAG, "IN - CAReceiveHandler");
// Input validation
VERIFY_NON_NULL_VOID(data, TAG, "Invalid thread context");
return CA_STATUS_NOT_INITIALIZED;
}
+ oc_mutex_lock(g_mutexStartServerState);
+ if (g_isStartServer)
+ {
+ OIC_LOG(DEBUG, TAG, "server already started");
+ oc_mutex_unlock(g_mutexStartServerState);
+ return CA_STATUS_OK;
+ }
+ oc_mutex_unlock(g_mutexStartServerState);
+
CAResult_t res = CAEDRServerStartAcceptThread();
if (CA_STATUS_OK == res)
{
CAEDRServerStop();
return CA_STATUS_FAILED;
}
+ oc_mutex_lock(g_mutexStartServerState);
+ g_isStartServer = true;
+ oc_mutex_unlock(g_mutexStartServerState);
}
return res;
}
CAEDRNatvieCloseServerTask(env);
+ oc_mutex_lock(g_mutexStartServerState);
+ g_isStartServer = false;
+ oc_mutex_unlock(g_mutexStartServerState);
if (isAttached)
{
oc_mutex_free(g_mutexObjectList);
g_mutexObjectList = NULL;
}
+
+ if (g_mutexStartServerState)
+ {
+ oc_mutex_free(g_mutexStartServerState);
+ g_mutexStartServerState = NULL;
+ }
}
static CAResult_t CAEDRServerCreateMutex()
return CA_STATUS_FAILED;
}
+ g_mutexStartServerState = oc_mutex_new();
+ if (!g_mutexStartServerState)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to created mutex!");
+
+ CAEDRServerDestroyMutex();
+ return CA_STATUS_FAILED;
+ }
+
return CA_STATUS_OK;
}