[bugfix] Set available port when user set port to '0'
authorhyunil park <hyunil46.park@samsung.com>
Wed, 18 Oct 2023 00:50:53 +0000 (09:50 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 18 Oct 2023 10:16:21 +0000 (19:16 +0900)
- set available port when user set port to '0'
- ml service api set '0' as the default port if the port isn't set
  but '0' is an invalid port

Signed-off-by: hyunil park <hyunil46.park@samsung.com>
include/nnstreamer-edge.h
src/libnnstreamer-edge/nnstreamer-edge-util.c
tests/unittest_nnstreamer-edge-aitt.cc
tests/unittest_nnstreamer-edge.cc

index ffa5edc7b4be9351294786893307812e1cd8b649..ba2e56a4c80361b843edcadf764ac9e709a1652f 100644 (file)
@@ -310,7 +310,7 @@ int nns_edge_is_connected (nns_edge_h edge_h);
  * ---------------------|--------------------------------------------------------------
  * CAPS or CAPABILITY   | capability strings.
  * IP or HOST           | IP address of the node to accept connection from other node.
- * PORT                 | Port of the node to accept connection from other node. The value should be 0 or higher.
+ * PORT                 | Port of the node to accept connection from other node. The value should be 0 or higher, if the port is set to 0 then the available port is allocated.
  * DEST_IP or DEST_HOST | IP address of the destination node. In case of TCP connection, it is the IP address of the destination node, and in the case of Hybrid or AITT connection, it is the IP address of the broker.
  * DEST_PORT            | Port of the destination node. In case of TCP connection, it is the port number of the destination node, and in the case of Hybrid or AITT connection, it is the port number of the broker. The value should be 0 or higher.
  * TOPIC                | Topic used to publish/subscribe to/from the broker.
index a570c0aee4d6830972002d913d5e4dc472b74a05..599ac12987492c3e11c0790cf813999af7c45bb4 100644 (file)
@@ -149,6 +149,10 @@ nns_edge_parse_port_number (const char *port_str)
 
   port = (int) strtoll (port_str, NULL, 10);
 
+  if (port == 0) {
+    port = nns_edge_get_available_port ();
+  }
+
   if (!PORT_IS_VALID (port)) {
     nns_edge_loge ("Invalid port number %d.", port);
     port = -1;
index 6e0f4dc97f51da32ef4160014ddad04eded0896c..877e6d2f331caae9a2ea89e79dabfaf1f3d6b802 100644 (file)
@@ -336,7 +336,7 @@ TEST(edgeAitt, connectInvalidParam4_n)
   ret = nns_edge_aitt_create (&handle);
   EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
 
-  ret = nns_edge_aitt_connect (handle, "temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 0);
+  ret = nns_edge_aitt_connect (handle, "temp-aitt-id", "temp-aitt-topic", "127.0.0.1", -1);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 
   ret = nns_edge_aitt_close (handle);
index 14c4befdbd398a243893037ad0f8c773fb4ee444..6c2a31507c5dffbd83a562fbdf4efda8283923de 100644 (file)
@@ -826,8 +826,6 @@ TEST(edge, setInfoInvalidParam08_n)
   /* Invalid port number */
   ret = nns_edge_set_info (edge_h, "port", "-1");
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
-  ret = nns_edge_set_info (edge_h, "port", "0");
-  EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
   ret = nns_edge_set_info (edge_h, "port", "77777");
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);