瀏覽代碼

create a new session when recovering the old one is not possible

Julius Pfrommer 7 年之前
父節點
當前提交
68bb79cd2d
共有 2 個文件被更改,包括 12 次插入1 次删除
  1. 11 0
      src/client/ua_client_connect.c
  2. 1 1
      tests/client/check_client.c

+ 11 - 0
src/client/ua_client_connect.c

@@ -415,6 +415,15 @@ UA_Client_connectInternal(UA_Client *client, const char *endpointUrl,
     /* Activate the Session for this SecureChannel */
     if(!UA_NodeId_equal(&client->authenticationToken, &UA_NODEID_NULL)) {
         retval = activateSession(client);
+
+        /* Could not recover an old session. Create a new one */
+        if(retval == UA_STATUSCODE_BADSESSIONIDINVALID) {
+            retval = createSession(client);
+            if(retval != UA_STATUSCODE_GOOD)
+                goto cleanup;
+            retval = activateSession(client);
+        }
+
         if(retval != UA_STATUSCODE_GOOD)
             goto cleanup;
         client->state = UA_CLIENTSTATE_SESSION;
@@ -489,6 +498,8 @@ UA_Client_disconnect(UA_Client *client) {
         client->state = UA_CLIENTSTATE_SESSION_DISCONNECTED;
         sendCloseSession(client);
     }
+    UA_NodeId_deleteMembers(&client->authenticationToken);
+    client->requestHandle = 0;
 
     /* Is a secure channel established? */
     if(client->state >= UA_CLIENTSTATE_SECURECHANNEL)

+ 1 - 1
tests/client/check_client.c

@@ -141,7 +141,7 @@ START_TEST(Client_reconnect) {
         ck_assert_uint_eq(retval, UA_STATUSCODE_BADCONNECTIONCLOSED);
 
         retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
-        ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
+        ck_assert_msg(retval == UA_STATUSCODE_GOOD, UA_StatusCode_name(retval));
 
         retval = UA_Client_readValueAttribute(client, nodeId, &val);
         ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);