Browse Source

Client: Depreate UA_Client_close in favor of UA_Client_disconnect

Julius Pfrommer 6 years ago
parent
commit
4d6af8f425

+ 4 - 2
include/ua_client.h

@@ -147,8 +147,10 @@ UA_StatusCode UA_EXPORT
 UA_Client_disconnect_async(UA_Client *client, UA_UInt32 *requestId);
 
 /* Close a connection to the selected server */
-UA_StatusCode UA_EXPORT
-UA_Client_close(UA_Client *client);
+UA_DEPRECATED static UA_INLINE UA_StatusCode
+UA_Client_close(UA_Client *client) {
+    return UA_Client_disconnect(client);
+}
 
 /* Renew the underlying secure channel */
 UA_StatusCode UA_EXPORT

+ 5 - 5
src/client/ua_client.c

@@ -506,7 +506,7 @@ receiveServiceResponse(UA_Client *client, void *response, const UA_DataType *res
         if(retval != UA_STATUSCODE_GOOD && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
             if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
                 setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
-            UA_Client_close(client);
+            UA_Client_disconnect(client);
             break;
         }
     } while(!rd.received);
@@ -528,7 +528,7 @@ __UA_Client_Service(UA_Client *client, const void *request,
             respHeader->serviceResult = UA_STATUSCODE_BADREQUESTTOOLARGE;
         else
             respHeader->serviceResult = retval;
-        UA_Client_close(client);
+        UA_Client_disconnect(client);
         return;
     }
 
@@ -538,7 +538,7 @@ __UA_Client_Service(UA_Client *client, const void *request,
     retval = receiveServiceResponse(client, response, responseType, maxDate, &requestId);
     if(retval == UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
         /* In synchronous service, if we have don't have a reply we need to close the connection */
-        UA_Client_close(client);
+        UA_Client_disconnect(client);
         retval = UA_STATUSCODE_BADCONNECTIONCLOSED;
     }
     if(retval != UA_STATUSCODE_GOOD)
@@ -557,7 +557,7 @@ receiveServiceResponseAsync(UA_Client *client, void *response,
             && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
         if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
             setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
-        UA_Client_close(client);
+        UA_Client_disconnect(client);
     }
     return retval;
 }
@@ -578,7 +578,7 @@ receivePacketAsync(UA_Client *client) {
     if(retval != UA_STATUSCODE_GOOD && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
         if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
             setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
-        UA_Client_close(client);
+        UA_Client_disconnect(client);
     }
     return retval;
 }

+ 5 - 26
src/client/ua_client_connect.c

@@ -151,7 +151,7 @@ HelAckHandshake(UA_Client *client) {
                     "Receiving ACK message failed with %s", UA_StatusCode_name(retval));
         if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
             client->state = UA_CLIENTSTATE_DISCONNECTED;
-        UA_Client_close(client);
+        UA_Client_disconnect(client);
     }
     return retval;
 }
@@ -223,7 +223,7 @@ openSecureChannel(UA_Client *client, UA_Boolean renew) {
     if(retval != UA_STATUSCODE_GOOD) {
         UA_LOG_ERROR(client->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
                      "Sending OPN message failed with error %s", UA_StatusCode_name(retval));
-        UA_Client_close(client);
+        UA_Client_disconnect(client);
         return retval;
     }
 
@@ -244,7 +244,7 @@ openSecureChannel(UA_Client *client, UA_Boolean renew) {
                                     &requestId);
 
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_Client_close(client);
+        UA_Client_disconnect(client);
         return retval;
     }
 
@@ -664,7 +664,7 @@ UA_Client_connectInternal(UA_Client *client, const char *endpointUrl,
     return retval;
 
 cleanup:
-    UA_Client_close(client);
+    UA_Client_disconnect(client);
     return retval;
 }
 
@@ -691,7 +691,7 @@ UA_StatusCode
 UA_Client_manuallyRenewSecureChannel(UA_Client *client) {
     UA_StatusCode retval = openSecureChannel(client, true);
     if(retval != UA_STATUSCODE_GOOD)
-        UA_Client_close(client);
+        UA_Client_disconnect(client);
 
     return retval;
 }
@@ -764,24 +764,3 @@ UA_Client_disconnect(UA_Client *client) {
     setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
     return UA_STATUSCODE_GOOD;
 }
-
-UA_StatusCode
-UA_Client_close(UA_Client *client) {
-    client->requestHandle = 0;
-
-    if(client->state >= UA_CLIENTSTATE_SECURECHANNEL)
-        UA_SecureChannel_deleteMembersCleanup(&client->channel);
-
-    /* Close the TCP connection */
-    if(client->connection.state != UA_CONNECTION_CLOSED)
-        client->connection.close(&client->connection);
-
-#ifdef UA_ENABLE_SUBSCRIPTIONS
-// TODO REMOVE WHEN UA_SESSION_RECOVERY IS READY
-        /* We need to clean up the subscriptions */
-        UA_Client_Subscriptions_clean(client);
-#endif
-
-    setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
-    return UA_STATUSCODE_GOOD;
-}

+ 2 - 2
src/client/ua_client_connect_async.c

@@ -288,7 +288,7 @@ openSecureChannelAsync(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_close(client);
+        UA_Client_disconnect(client);
         //if(renew)
         //    UA_free(ac);
         return retval;
@@ -589,7 +589,7 @@ UA_Client_connectInternalAsync(UA_Client *client, const char *endpointUrl,
 
     return retval;
 
-    cleanup: UA_Client_close(client);
+    cleanup: UA_Client_disconnect(client);
         return retval;
 }
 

+ 2 - 2
src/client/ua_client_subscriptions.c

@@ -623,7 +623,7 @@ UA_Client_Subscriptions_processPublishResponse(UA_Client *client, UA_PublishRequ
     }
 
     if(response->responseHeader.serviceResult == UA_STATUSCODE_BADSESSIONIDINVALID) {
-        UA_Client_close(client); /* TODO: This should be handled before the process callback */
+        UA_Client_disconnect(client); /* TODO: This should be handled before the process callback */
         UA_LOG_WARNING(client->config.logger, UA_LOGCATEGORY_CLIENT,
                        "Received BadSessionIdInvalid");
         return;
@@ -655,7 +655,7 @@ UA_Client_Subscriptions_processPublishResponse(UA_Client *client, UA_PublishRequ
         /* This is an error. But we do not abort the connection. Some server
          * SDKs misbehave from time to time and send out-of-order sequence
          * numbers. (Probably some multi-threading synchronization issue.) */
-        /* UA_Client_close(client);
+        /* UA_Client_disconnect(client);
            return; */
     }
     /* According to f), a keep-alive message contains no notifications and has the sequence number

+ 1 - 1
tests/client/check_client.c

@@ -243,7 +243,7 @@ START_TEST(Client_activateSessionClose) {
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
     UA_Variant_deleteMembers(&val);
 
-    UA_Client_close(client);
+    UA_Client_disconnect(client);
 
     retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);