[asterisk-commits] russell: branch 1.4 r91777 - /branches/1.4/main/autoservice.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 7 10:08:36 CST 2007


Author: russell
Date: Fri Dec  7 10:08:35 2007
New Revision: 91777

URL: http://svn.digium.com/view/asterisk?view=rev&rev=91777
Log:
* Add a bit more of a verbose comment as to why a hangup frame needs to be
  queued up if autoservice gets a NULL return from ast_read().
* Make the process of queueing the hangup frame more efficient by putting the
  frame where it is going to end up and avoiding some locking and extra memory
  allocations and freeing.

Modified:
    branches/1.4/main/autoservice.c

Modified: branches/1.4/main/autoservice.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/autoservice.c?view=diff&rev=91777&r1=91776&r2=91777
==============================================================================
--- branches/1.4/main/autoservice.c (original)
+++ branches/1.4/main/autoservice.c Fri Dec  7 10:08:35 2007
@@ -66,10 +66,24 @@
 
 static pthread_t asthread = AST_PTHREADT_NULL;
 
+static void defer_frame(struct ast_channel *chan, struct ast_frame *f)
+{
+	struct ast_frame *dup_f;
+	struct asent *as;
+
+	AST_LIST_LOCK(&aslist);
+	AST_LIST_TRAVERSE(&aslist, as, list) {
+		if (as->chan != chan)
+			continue;
+		if ((dup_f = ast_frdup(f)))
+			AST_LIST_INSERT_TAIL(&as->dtmf_frames, dup_f, frame_list);
+	}
+	AST_LIST_UNLOCK(&aslist);
+}
+
 static void *autoservice_run(void *ign)
 {
-
-	for(;;) {
+	for (;;) {
 		struct ast_channel *mons[MAX_AUTOMONS];
 		struct ast_channel *chan;
 		struct asent *as;
@@ -91,8 +105,18 @@
 			struct ast_frame *f = ast_read(chan);
 	
 			if (!f) {
-				/* NULL means we got a hangup*/
-				ast_queue_hangup(chan);
+				struct ast_frame hangup_frame = { 0, };
+				/* No frame means the channel has been hung up.
+				 * A hangup frame needs to be queued here as ast_waitfor() may
+				 * never return again for the condition to be detected outside
+				 * of autoservice.  So, we'll leave a HANGUP queued up so the
+				 * thread in charge of this channel will know. */
+
+				hangup_frame.frametype = AST_FRAME_CONTROL;
+				hangup_frame.subclass = AST_CONTROL_HANGUP;
+
+				defer_frame(chan, &hangup_frame);
+
 				continue;
 			}
 			
@@ -107,18 +131,8 @@
 			case AST_FRAME_TEXT:
 			case AST_FRAME_IMAGE:
 			case AST_FRAME_HTML:
-			{
-				struct ast_frame *dup_f;
-
-				AST_LIST_LOCK(&aslist);
-				AST_LIST_TRAVERSE(&aslist, as, list) {
-					if (as->chan != chan)
-						continue;
-					if ((dup_f = ast_frdup(f)))
-						AST_LIST_INSERT_TAIL(&as->dtmf_frames, dup_f, frame_list);
-				}
-				AST_LIST_UNLOCK(&aslist);
-			}
+				defer_frame(chan, f);
+				break;
 
 			/* Throw these frames away */
 			case AST_FRAME_VOICE:




More information about the asterisk-commits mailing list