From ae51ff54d1fec0d617467a4e18321a01b6e93ec5 Mon Sep 17 00:00:00 2001 From: Munkyu Im Date: Tue, 29 Dec 2015 17:20:11 +0900 Subject: [PATCH] net: check if sdb/gdb port is available It is an additional port checking to improve stability. Change-Id: I6124fd6f1479b40b5c803f4a1b495e994c63f51f Signed-off-by: Munkyu Im --- tizen/src/util/sdb.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tizen/src/util/sdb.c b/tizen/src/util/sdb.c index 4b3fd1bc14..ccdd13c303 100644 --- a/tizen/src/util/sdb.c +++ b/tizen/src/util/sdb.c @@ -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; } -- 2.34.1