Browse Source

recover an existing session if possible

Julius Pfrommer 7 years ago
parent
commit
15c65b5129
1 changed files with 12 additions and 8 deletions
  1. 12 8
      src/client/ua_client_connect.c

+ 12 - 8
src/client/ua_client_connect.c

@@ -398,18 +398,22 @@ UA_Client_connectInternal(UA_Client *client, const char *endpointUrl,
         goto cleanup;
     client->state = UA_CLIENTSTATE_SECURECHANNEL;
 
-    /* Get Endpoints */
-    if(endpointsHandshake) {
-        retval = getEndpoints(client);
+    /* There is no session to recover and we want to have a session */
+    if(createNewSession && UA_NodeId_equal(&client->authenticationToken, &UA_NODEID_NULL)) {
+        /* Get Endpoints */
+        if(endpointsHandshake) {
+            retval = getEndpoints(client);
+            if(retval != UA_STATUSCODE_GOOD)
+                goto cleanup;
+        }
+        /* Create a Session */
+        retval = createSession(client);
         if(retval != UA_STATUSCODE_GOOD)
             goto cleanup;
     }
 
-    /* Open a Session */
-    if(createNewSession) {
-        retval = createSession(client);
-        if(retval != UA_STATUSCODE_GOOD)
-            goto cleanup;
+    /* Activate the Session for this SecureChannel */
+    if(!UA_NodeId_equal(&client->authenticationToken, &UA_NODEID_NULL)) {
         retval = activateSession(client);
         if(retval != UA_STATUSCODE_GOOD)
             goto cleanup;