[IOT-2330] fix block issue related rfcomm accept logic
authorjihwan.seo <jihwan.seo@samsung.com>
Mon, 22 May 2017 07:58:44 +0000 (16:58 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 22 May 2017 15:45:43 +0000 (15:45 +0000)
Change-Id: I79f62fdd362542f1dc05cb77f986e34587c422e0
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20223
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
resource/csdk/connectivity/src/bt_edr_adapter/android/caedrserver.c

index 770cd70e2d7d5cbc78bd8ae8e80afac61725f305..c0ca7593ed9840957d86b4650cde12738d8a303d 100644 (file)
@@ -218,11 +218,6 @@ static void CAAcceptHandler(void *data)
 
     CAAdapterAcceptThreadContext_t *ctx = (CAAdapterAcceptThreadContext_t *) data;
 
-    // it should be initialized for restart accept thread
-    oc_mutex_lock(g_mutexAcceptServer);
-    g_stopAccept = false;
-    oc_mutex_unlock(g_mutexAcceptServer);
-
     while (true != *(ctx->stopFlag))
     {
         // when BT state is changed with Off. its thread will be stopped
@@ -273,6 +268,12 @@ CAResult_t CAEDRServerStart()
     }
     oc_mutex_unlock(g_mutexStartServerState);
 
+    // it should be initialized for restart accept thread
+    oc_mutex_lock(g_mutexAcceptServer);
+    OIC_LOG(DEBUG, TAG, "accept flag is set false");
+    g_stopAccept = false;
+    oc_mutex_unlock(g_mutexAcceptServer);
+
     CAResult_t res = CAEDRServerStartAcceptThread();
     if (CA_STATUS_OK == res)
     {
@@ -296,6 +297,7 @@ CAResult_t CAEDRServerStop()
     CAEDRStopReceiveThread();
 
     oc_mutex_lock(g_mutexAcceptServer);
+    OIC_LOG(DEBUG, TAG, "accept flag is set true");
     g_stopAccept = true;
     oc_mutex_unlock(g_mutexAcceptServer);
 
@@ -905,7 +907,7 @@ void CAEDRNativeAccept(JNIEnv *env, jobject serverSocketObject)
 {
     OIC_LOG(DEBUG, TAG, "CAEDRNativeAccept - IN");
 
-    if (NULL != serverSocketObject)
+    if (NULL != serverSocketObject && false == g_stopAccept)
     {
         jmethodID jni_mid_accept = CAGetJNIMethodID(env, CLASSPATH_BT_SERVER_SOCKET,
                                                     "accept",
@@ -982,6 +984,7 @@ void CAEDRNativeAccept(JNIEnv *env, jobject serverSocketObject)
  */
 void CAEDRNatvieCloseServerTask(JNIEnv* env)
 {
+    OIC_LOG(DEBUG, TAG, "CAEDRNatvieCloseServerTask");
     if (g_serverSocket)
     {
         OIC_LOG(DEBUG, TAG, "Accept Resource will be close");