Module: sems
Branch: master
Commit: cbf59af49dd2a9382325992c46e2439fe65cb051
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=cbf59af49dd2a9382325992c46e2439fe65cb051

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Wed Sep 22 15:28:25 2010 +0200

introduced max_shutdown_time, limits server stop

to prevent SEMS from stopping if there are hanging sessions,
a limit on the maximum shutdown time (actually time to wait
for sessions to stop) can be configured

default: 10 seconds
turn off by setting to 0

---

 core/AmConfig.cpp           |    6 +++++-
 core/AmConfig.h             |    2 ++
 core/AmSessionContainer.cpp |   15 +++++++++++----
 core/etc/sems.conf.sample   |    9 +++++++++
 core/sems.h                 |    2 ++
 5 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp
index e693a2a..a966f5f 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 a708f8b..623a826 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 5378f92..8777fbc 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 14750e3..2240afb 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=<time in seconds>
+#
+# Limit on server shutdown time (time to send/resend BYE
+# to active calls). 0 to disable (infinite).
+#
+# Default: 10
+#
+#max_shutdown_time = 10
+
 # optional parameter: syslog_facility={DAEMON|USER|LOCAL[0-7]}
 #
 # - sets the log facility that is used for syslog. Using this,
diff --git a/core/sems.h b/core/sems.h
index 3ff50d5..0ea57ed 100644
--- a/core/sems.h
+++ b/core/sems.h
@@ -40,6 +40,8 @@
 #define RTP_HIGHPORT        0xffff
 #define MAX_FORWARDS        70
 
+#define DEFAULT_MAX_SHUTDOWN_TIME 10 // 10 seconds max for shutting down
+
 #ifndef DISABLE_DAEMON_MODE
 # define DEFAULT_DAEMON_MODE        true
 # define DEFAULT_DAEMON_PID_FILE    "/var/local/run/sems.pid"

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to