From d70e1ff7d5ed40cbdf432a96ee75b8e3f06dedb2 Mon Sep 17 00:00:00 2001 From: Kang Lin Date: Fri, 3 Nov 2023 09:57:19 +0800 Subject: [PATCH] Refactor: modify setup_general_relay_servers to remove exit --- src/apps/relay/netengine.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/apps/relay/netengine.c b/src/apps/relay/netengine.c index ffd4ec6a0..d3d281eb3 100644 --- a/src/apps/relay/netengine.c +++ b/src/apps/relay/netengine.c @@ -414,7 +414,7 @@ static void allocate_relay_addrs_ports(void) { TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, " relay %s initialization...\n", turn_params.relay_addrs[i]); turnipports_add_ip(STUN_ATTRIBUTE_TRANSPORT_UDP_VALUE, &baddr); turnipports_add_ip(STUN_ATTRIBUTE_TRANSPORT_TCP_VALUE, &baddr); - //TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, " relay %s initialization done\n", turn_params.relay_addrs[i]); + // TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, " relay %s initialization done\n", turn_params.relay_addrs[i]); } } TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Total %d relay ports initialization done\n", turn_params.relays_number); @@ -1702,7 +1702,7 @@ static void *run_general_relay_thread(void *arg) { return arg; } -static void setup_general_relay_servers(void) { +static int setup_general_relay_servers(void) { size_t i = 0; for (i = 0; i < get_real_general_relay_servers_number(); i++) { @@ -1723,12 +1723,14 @@ static void setup_general_relay_servers(void) { general_relay_servers[i]->id = (turnserver_id)i; general_relay_servers[i]->sm = sm; if (pthread_create(&(general_relay_servers[i]->thr), NULL, run_general_relay_thread, general_relay_servers[i])) { - perror("Cannot create relay thread\n"); - exit(-1); + TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Cannot create relay thread\n"); + return -1; } pthread_detach(general_relay_servers[i]->thr); } } + TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Total General servers: %d\n", (int)get_real_general_relay_servers_number()); + return 0; } static int run_auth_server_flag = 1; @@ -1864,8 +1866,9 @@ int setup_server(void) { break; allocate_relay_addrs_ports(); setup_barriers(); - setup_general_relay_servers(); - TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Total General servers: %d\n", (int)get_real_general_relay_servers_number()); + nRet = setup_general_relay_servers(); + if (nRet) + break; if (turn_params.net_engine_version == NEV_UDP_SOCKET_PER_THREAD) setup_socket_per_thread_udp_listener_servers();