ソースを参照

small cleanup in server initialization

Julius Pfrommer 6 年 前
コミット
d78ff6e5e4
共有1 個のファイルを変更した14 個の追加9 個の削除を含む
  1. 14 9
      src/server/ua_server.c

+ 14 - 9
src/server/ua_server.c

@@ -160,18 +160,23 @@ UA_Server_cleanup(UA_Server *server, void *_) {
 
 UA_Server *
 UA_Server_new(const UA_ServerConfig *config) {
-    UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
-    if(!server)
+    /* A config is required */
+    if(!config)
         return NULL;
 
+    /* At least one endpoint has to be configured */
     if(config->endpointsSize == 0) {
-        UA_LOG_FATAL(config->logger,
-                     UA_LOGCATEGORY_SERVER,
+        UA_LOG_FATAL(config->logger, UA_LOGCATEGORY_SERVER,
                      "There has to be at least one endpoint.");
-        UA_free(server);
         return NULL;
     }
 
+    /* Allocate the server */
+    UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
+    if(!server)
+        return NULL;
+
+    /* Set the config */
     server->config = *config;
 
     /* Init start time to zero, the actual start time will be sampled in
@@ -244,10 +249,10 @@ UA_Server_new(const UA_ServerConfig *config) {
 
     /* Initialize namespace 0*/
     UA_StatusCode retVal = UA_Server_initNS0(server);
-    if (retVal != UA_STATUSCODE_GOOD) {
-        UA_LOG_ERROR(config->logger,
-                     UA_LOGCATEGORY_SERVER,
-                     "Initialization of Namespace 0 failed with %s. See previous outputs for any error messages.",
+    if(retVal != UA_STATUSCODE_GOOD) {
+        UA_LOG_ERROR(config->logger, UA_LOGCATEGORY_SERVER,
+                     "Initialization of Namespace 0 failed with %s. "
+                     "See previous outputs for any error messages.",
                      UA_StatusCode_name(retVal));
         UA_Server_delete(server);
         return NULL;