Browse Source

simplify the client's openSecureChannel

Julius Pfrommer 7 years ago
parent
commit
d1e91c8e40
1 changed files with 9 additions and 7 deletions
  1. 9 7
      src/client/ua_client_connect.c

+ 9 - 7
src/client/ua_client_connect.c

@@ -212,21 +212,23 @@ openSecureChannel(UA_Client *client, UA_Boolean renew) {
         UA_LOG_ERROR(client->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
                      "Sending OPN message failed with error %s", UA_StatusCode_name(retval));
         UA_Client_disconnect(client);
-        if(renew)
+        if(ac)
             UA_free(ac);
         return retval;
     }
 
     UA_LOG_DEBUG(client->config.logger, UA_LOGCATEGORY_SECURECHANNEL, "OPN message sent");
 
-    /* Store the entry for async processing and return */
-    if(renew) {
+    if(!renew) {
+        /* During OpenSecureChannel, block until the response */
+        retval = UA_Connection_receiveChunksBlocking(&client->connection, client,
+                                                     processOPNResponse, client->config.timeout);
+    } else {
+        /* For renewal, store the entry for async processing and return */
         LIST_INSERT_HEAD(&client->asyncServiceCalls, ac, pointers);
-        return retval;
     }
 
-    return UA_Connection_receiveChunksBlocking(&client->connection, client,
-                                               processOPNResponse, client->config.timeout);
+    return retval;
 }
 
 static UA_StatusCode
@@ -522,7 +524,7 @@ UA_Client_disconnect(UA_Client *client) {
     if(client->state == UA_CLIENTSTATE_SESSION){
         client->state = UA_CLIENTSTATE_SESSION_DISCONNECTED;
         sendCloseSession(client);
-    }    
+    }
 
     /* Is a secure channel established? */
     if(client->state >= UA_CLIENTSTATE_SECURECHANNEL)