From 718a311a41d2c7e93259fd3014e36a7aa4c3da13 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2012 07:52:58 -0500 Subject: [PATCH] FS-4224 --resolve add optional wait param to sofia profile stop [sofia profile foo stop wait] --- src/mod/endpoints/mod_sofia/mod_sofia.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 6f64078509..8d50a221e8 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -3640,6 +3640,17 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t if (!strcasecmp(argv[1], "stop")) { sofia_clear_pflag_locked(profile, PFLAG_RUNNING); + if (argv[2] && !strcasecmp(argv[2], "wait")) { + int loops = 20 * 2; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Waiting for %s to finish SIP transactions.\n", profile->name); + while (!sofia_test_pflag(profile, PFLAG_SHUTDOWN)) { + switch_yield(500000); + if (!--loops) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timeout Waiting for %s to finish SIP transactions.\n", profile->name); + break; + } + } + } stream->write_function(stream, "stopping: %s", profile->name); } else { sofia_set_pflag_locked(profile, PFLAG_RESPAWN); @@ -4129,7 +4140,7 @@ SWITCH_STANDARD_API(sofia_function) "sofia global siptrace \n" "sofia capture \n" " watchdog \n\n" - "sofia profile [start | stop | restart | rescan]\n" + "sofia profile [start | stop | restart | rescan] [wait]\n" " flush_inbound_reg [ | <[user]@domain>] [reboot]\n" " check_sync [ | <[user]@domain>]\n" " [register | unregister] [ | all]\n" @@ -5555,9 +5566,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) switch_console_set_complete("add sofia profile"); switch_console_set_complete("add sofia profile restart all"); - + switch_console_set_complete("add sofia profile ::sofia::list_profiles start"); - switch_console_set_complete("add sofia profile ::sofia::list_profiles stop"); + switch_console_set_complete("add sofia profile ::sofia::list_profiles stop wait"); switch_console_set_complete("add sofia profile ::sofia::list_profiles rescan"); switch_console_set_complete("add sofia profile ::sofia::list_profiles restart");