net: check if sdb/gdb port is available
authorMunkyu Im <munkyu.im@samsung.com>
Tue, 29 Dec 2015 08:20:11 +0000 (17:20 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 30 Dec 2015 07:31:44 +0000 (16:31 +0900)
It is an additional port checking to improve stability.

Change-Id: I6124fd6f1479b40b5c803f4a1b495e994c63f51f
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
tizen/src/util/sdb.c

index 4b3fd1bc149d623702e369d4910ba12911aa9907..ccdd13c3039cdaed49b8ff9c7cac9f20f5f400cf 100644 (file)
@@ -169,13 +169,22 @@ int check_port_bind_listen(uint32_t port)
 int find_available_port(uint32_t base_port)
 {
     int ret = 0;
-    /* TODO: additional check for sdb and gdb port using for redirection */
-    ret = check_port_bind_listen(base_port + ECS_INDEX);
-    if (ret > 0) {
-        emul_vm_base_socket = ret;
-    } else {
-        LOG_INFO("socket close. port:%d\n", base_port + ECS_INDEX);
+    int i = 0;
+    for (i = SDB_INDEX; i <= ECS_INDEX; i++) {
+        ret = check_port_bind_listen(base_port + i);
+        if (ret >= 0 && i != ECS_INDEX) {
+            //TODO: Because of checking and closing socket,
+            // not guaranteed fully that sdb/gdb port is available,
+            // when the time call net_slirp_redir()
+            closesocket(ret);
+        } else if (ret < 0) {
+            LOG_INFO("port(%"PRIu32") is reserved.\n", base_port + i);
+            return -1;
+        }
     }
+    // save ecs socket fd as global variable
+    emul_vm_base_socket = ret;
+    LOG_INFO("find available port: %"PRIu32"\n", base_port);
     return ret;
 }