[asterisk-commits] coreyfarrell: branch 12 r424579 - in /branches/12: ./ main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Oct 4 19:45:34 CDT 2014


Author: coreyfarrell
Date: Sat Oct  4 19:45:30 2014
New Revision: 424579

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=424579
Log:
Release AMI connections on shutdown.

ASTERISK-24378 #close
Reported by: Corey Farrell
Review: https://reviewboard.asterisk.org/r/4037/
........

Merged revisions 424578 from http://svn.asterisk.org/svn/asterisk/branches/11

Modified:
    branches/12/   (props changed)
    branches/12/main/manager.c

Propchange: branches/12/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Modified: branches/12/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/manager.c?view=diff&rev=424579&r1=424578&r2=424579
==============================================================================
--- branches/12/main/manager.c (original)
+++ branches/12/main/manager.c Sat Oct  4 19:45:30 2014
@@ -1171,6 +1171,9 @@
 #define MGR_SHOW_TERMINAL_WIDTH 80
 
 #define MAX_VARS 128
+
+/*! \brief Fake event class used to end sessions at shutdown */
+#define EVENT_FLAG_SHUTDOWN -1
 
 /*! \brief
  * Descriptor for a manager session, either on the AMI socket or over HTTP.
@@ -5276,6 +5279,10 @@
 		struct eventqent *eqe = s->session->last_ev;
 
 		while ((eqe = advance_event(eqe))) {
+			if (eqe->category == EVENT_FLAG_SHUTDOWN) {
+				ast_debug(3, "Received CloseSession event\n");
+				ret = -1;
+			}
 			if (!ret && s->session->authenticated &&
 			    (s->session->readperm & eqe->category) == eqe->category &&
 			    (s->session->send_events & eqe->category) == eqe->category) {
@@ -6192,7 +6199,7 @@
 		ao2_iterator_destroy(&i);
 	}
 
-	if (!AST_RWLIST_EMPTY(&manager_hooks)) {
+	if (category != EVENT_FLAG_SHUTDOWN && !AST_RWLIST_EMPTY(&manager_hooks)) {
 		AST_RWLIST_RDLOCK(&manager_hooks);
 		AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) {
 			hook->helper(category, event, ast_str_buffer(buf));
@@ -7972,6 +7979,9 @@
 {
 	struct ast_manager_user *user;
 
+	/* This event is not actually transmitted, but causes all TCP sessions to be closed */
+	manager_event(EVENT_FLAG_SHUTDOWN, "CloseSession", "CloseSession: true\r\n");
+
 	ast_manager_unregister("Ping");
 	ast_manager_unregister("Events");
 	ast_manager_unregister("Logoff");




More information about the asterisk-commits mailing list