diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp index e693a2a2..a966f5fb 100644 --- a/core/AmConfig.cpp +++ b/core/AmConfig.cpp @@ -58,6 +58,8 @@ string AmConfig::DaemonUid = DEFAULT_DAEMON_UID; string AmConfig::DaemonGid = DEFAULT_DAEMON_GID; #endif +unsigned int AmConfig::MaxShutdownTime = DEFAULT_MAX_SHUTDOWN_TIME; + string AmConfig::LocalIP = ""; string AmConfig::PublicIP = ""; string AmConfig::PrefixSep = PREFIX_SEPARATOR; @@ -416,6 +418,9 @@ int AmConfig::readConfiguration() } } + MaxShutdownTime = cfg.getParameterInt("max_shutdown_time", + DEFAULT_MAX_SHUTDOWN_TIME); + // user_prefix_separator PrefixSep = cfg.getParameter("user_prefix_separator",PrefixSep); @@ -468,7 +473,6 @@ int AmConfig::readConfiguration() } } - // single codec in 200 OK if(cfg.hasParameter("single_codec_in_ok")){ SingleCodecInOK = (cfg.getParameter("single_codec_in_ok") == "yes"); diff --git a/core/AmConfig.h b/core/AmConfig.h index a708f8b9..623a826d 100644 --- a/core/AmConfig.h +++ b/core/AmConfig.h @@ -75,6 +75,8 @@ struct AmConfig static string DaemonGid; #endif + static unsigned int MaxShutdownTime; + /** local IP for SDP media advertising */ static string LocalIP; diff --git a/core/AmSessionContainer.cpp b/core/AmSessionContainer.cpp index 5378f927..8777fbc2 100644 --- a/core/AmSessionContainer.cpp +++ b/core/AmSessionContainer.cpp @@ -63,7 +63,7 @@ void AmSessionContainer::dispose() if(!_instance->is_stopped()) { _instance->stop(); - while(!_instance->is_stopped()) + while (!_instance->is_stopped()) usleep(10000); } // todo: add locking here @@ -149,12 +149,19 @@ void AmSessionContainer::on_stop() DBG("waiting for active event queues to stop...\n"); - while (!AmEventDispatcher::instance()->empty()) - sleep(1); + for (unsigned int i=0; + (!AmEventDispatcher::instance()->empty() && + (!AmConfig::MaxShutdownTime || + i < AmConfig::MaxShutdownTime * 1000 / 10));i++) + usleep(10000); + + if (!AmEventDispatcher::instance()->empty()) { + WARN("Not all calls cleanly ended!\n"); + } DBG("cleaning sessions...\n"); while (clean_sessions()) - sleep(1); + usleep(10000); _run_cond.set(true); // so that thread stops } diff --git a/core/etc/sems.conf.sample b/core/etc/sems.conf.sample index 14750e3b..2240afb6 100644 --- a/core/etc/sems.conf.sample +++ b/core/etc/sems.conf.sample @@ -206,6 +206,15 @@ stderr=no # (same as -D) loglevel=2 +# optional parameter: max_shutdown_time=