[asterisk-commits] mmichelson: branch mmichelson/timeout_fixes r374228 - in /team/mmichelson/tim...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 2 15:05:35 CDT 2012


Author: mmichelson
Date: Tue Oct  2 15:05:31 2012
New Revision: 374228

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=374228
Log:
Make Richard's suggestions.


Modified:
    team/mmichelson/timeout_fixes/apps/app_dial.c
    team/mmichelson/timeout_fixes/apps/app_queue.c
    team/mmichelson/timeout_fixes/apps/app_record.c
    team/mmichelson/timeout_fixes/apps/app_waitforring.c
    team/mmichelson/timeout_fixes/channels/chan_agent.c
    team/mmichelson/timeout_fixes/channels/chan_dahdi.c
    team/mmichelson/timeout_fixes/channels/chan_iax2.c
    team/mmichelson/timeout_fixes/channels/sig_analog.c
    team/mmichelson/timeout_fixes/channels/sig_pri.c
    team/mmichelson/timeout_fixes/main/channel.c
    team/mmichelson/timeout_fixes/main/pbx.c
    team/mmichelson/timeout_fixes/res/res_fax.c

Modified: team/mmichelson/timeout_fixes/apps/app_dial.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/apps/app_dial.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/apps/app_dial.c (original)
+++ team/mmichelson/timeout_fixes/apps/app_dial.c Tue Oct  2 15:05:31 2012
@@ -1096,7 +1096,7 @@
 		ast_poll_channel_add(in, epollo->chan);
 #endif
 
-	while ((ast_tvdiff_ms(ast_tvnow(), start) < orig || orig < 0) && !peer) {
+	while ((*to = ast_remaining_ms(start, orig)) && !peer) {
 		struct chanlist *o;
 		int pos = 0; /* how many channels do we handle */
 		int numlines = prestart;
@@ -1128,7 +1128,6 @@
 			}
 			return NULL;
 		}
-		*to = ast_remaining_ms(start, orig);
 		winner = ast_waitfor_n(watchers, pos, to);
 		for (o = outgoing; o; o = o->next) {
 			struct ast_frame *f;
@@ -1628,14 +1627,13 @@
 skip_frame:;
 			ast_frfree(f);
 		}
-		if (ast_remaining_ms(start, orig) == 0)
-			ast_verb(3, "Nobody picked up in %d ms\n", orig);
-		if (ast_remaining_ms(start, orig) == 0 || ast_check_hangup(in))
-			ast_cdr_noanswer(in->cdr);
-	}
-
-	if (orig > -1 && ast_tvdiff_ms(ast_tvnow(), start) <= 0) {
-		*to = 0;
+	}
+
+	if (!*to) {
+		ast_verb(3, "Nobody picked up in %d ms\n", orig);
+	}
+	if (!*to || ast_check_hangup(in)) {
+		ast_cdr_noanswer(in->cdr);
 	}
 
 #ifdef HAVE_EPOLL

Modified: team/mmichelson/timeout_fixes/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/apps/app_queue.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/apps/app_queue.c (original)
+++ team/mmichelson/timeout_fixes/apps/app_queue.c Tue Oct  2 15:05:31 2012
@@ -3487,7 +3487,7 @@
 	}
 #endif
 	
-	while ((ast_tvdiff_ms(ast_tvnow(), start_time_tv) < orig || orig < 0) && !peer) {
+	while ((*to = ast_remaining_ms(start_time_tv, orig)) && !peer) {
 		int numlines, retry, pos = 1;
 		struct ast_channel *watchers[AST_MAX_WATCHERS];
 		watchers[0] = in;
@@ -3530,7 +3530,6 @@
 		}
 
 		/* Poll for events from both the incoming channel as well as any outgoing channels */
-		*to = ast_remaining_ms(start_time_tv, orig);
 		winner = ast_waitfor_n(watchers, pos, to);
 
 		/* Service all of the outgoing channels */
@@ -3900,14 +3899,12 @@
 			}
 			ast_frfree(f);
 		}
-		if (ast_remaining_ms(start_time_tv, orig) <= 0) {
-			for (o = start; o; o = o->call_next)
-				rna(orig, qe, o->interface, o->member->membername, 1);
-		}
-	}
-	
-	if (orig > -1 && ast_tvdiff_ms(ast_tvnow(), start_time_tv)) {
-		*to = 0;
+	}
+
+	if (!*to) {
+		for (o = start; o; o = o->call_next) {
+			rna(orig, qe, o->interface, o->member->membername, 1);
+		}
 	}
 
 #ifdef HAVE_EPOLL

Modified: team/mmichelson/timeout_fixes/apps/app_record.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/apps/app_record.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/apps/app_record.c (original)
+++ team/mmichelson/timeout_fixes/apps/app_record.c Tue Oct  2 15:05:31 2012
@@ -169,6 +169,7 @@
 		AST_APP_ARG(maxduration);
 		AST_APP_ARG(options);
 	);
+	int ms;
 	struct timeval start;
 	
 	/* The next few lines of code parse out the filename and header from the input string */
@@ -332,15 +333,13 @@
 		maxduration = -1;
 
 	start = ast_tvnow();
-	while (ast_tvdiff_ms(ast_tvnow(), start) < maxduration || maxduration < 0) {
-		int ms = ast_remaining_ms(start, maxduration);
-
+	while ((ms = ast_remaining_ms(start, maxduration))) {
 		waitres = ast_waitfor(chan, ms);
 		if (waitres < 0) {
 			break;
 		}
 
-		if (ms > 0 && waitres == 0) {
+		if (maxduration > 0 && waitres == 0) {
 			gottimeout = 1;
 			pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "TIMEOUT");
 			break;

Modified: team/mmichelson/timeout_fixes/apps/app_waitforring.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/apps/app_waitforring.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/apps/app_waitforring.c (original)
+++ team/mmichelson/timeout_fixes/apps/app_waitforring.c Tue Oct  2 15:05:31 2012
@@ -64,6 +64,7 @@
 	int res = 0;
 	double s;
 	int timeout_ms;
+	int ms;
 	struct timeval start = ast_tvnow();
 
 	if (!data || (sscanf(data, "%30lg", &s) != 1)) {
@@ -81,8 +82,7 @@
 	}
 
 	timeout_ms = s * 1000.0;
-	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms || timeout_ms < 0) {
-		int ms = ast_remaining_ms(start, timeout_ms);
+	while ((ms = ast_remaining_ms(start, timeout_ms))) {
 
 		ms = ast_waitfor(chan, ms);
 		if (ms < 0) {

Modified: team/mmichelson/timeout_fixes/channels/chan_agent.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/chan_agent.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/channels/chan_agent.c (original)
+++ team/mmichelson/timeout_fixes/channels/chan_agent.c Tue Oct  2 15:05:31 2012
@@ -1046,6 +1046,7 @@
 	int to = 1000;
 	struct ast_frame *f;
 	struct timeval start = ast_tvnow();
+	int ms;
 
 	/* Wait a second and look for something */
 
@@ -1053,9 +1054,7 @@
 	if (!p->chan) 
 		return -1;
 
-	while (ast_tvdiff_ms(ast_tvnow(), start) < to) {
-		int ms = ast_remaining_ms(start, to);
-		
+	while ((ms = ast_remaining_ms(start, to))) {
 		res = ast_waitfor(p->chan, ms);
 		if (res <= 0) {
 			return res;

Modified: team/mmichelson/timeout_fixes/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/chan_dahdi.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/channels/chan_dahdi.c (original)
+++ team/mmichelson/timeout_fixes/channels/chan_dahdi.c Tue Oct  2 15:05:31 2012
@@ -10504,6 +10504,7 @@
 				int k = 0;
 				int off_ms;
 				struct timeval start = ast_tvnow();
+				int ms;
 				cs = NULL;
 				ast_debug(1, "Receiving DTMF cid on channel %s\n", chan->name);
 				dahdi_setlinear(p->subs[idx].dfd, 0);
@@ -10515,9 +10516,8 @@
 				 */
 				ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
 				off_ms = 4000;/* This is a typical OFF time between rings. */
-				while (ast_tvdiff_ms(ast_tvnow(), start) < off_ms) {
+				while ((ms = ast_remaining_ms(start, off_ms))) {
 					struct ast_frame *f;
-					int ms = ast_remaining_ms(start, off_ms);
 
 					res = ast_waitfor(chan, ms);
 					if (res <= 0) {
@@ -10564,6 +10564,7 @@
 				if (cs) {
 					int off_ms;
 					struct timeval start;
+					int ms;
 					samples = 0;
 #if 1
 					bump_gains(p);
@@ -10642,9 +10643,8 @@
 					/* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
 					start = ast_tvnow();
 					off_ms = 4000;/* This is a typical OFF time between rings. */
-					while (ast_tvdiff_ms(ast_tvnow(), start) < off_ms) {
+					while ((ms = ast_remaining_ms(start, off_ms))) {
 						struct ast_frame *f;
-						int ms = ast_remaining_ms(start, off_ms);
 
 						res = ast_waitfor(chan, ms);
 						if (res <= 0) {
@@ -10776,13 +10776,13 @@
 				int k = 0;
 				int off_ms;
 				struct timeval start;
+				int ms;
 				cs = NULL;
 				dahdi_setlinear(p->subs[idx].dfd, 0);
 				off_ms = 2000;
 				start = ast_tvnow();
-				while (ast_tvdiff_ms(ast_tvnow(), start) < off_ms) {
+				while ((ms = ast_remaining_ms(start, off_ms))) {
 					struct ast_frame *f;
-					int ms = ast_remaining_ms(start, off_ms);
 
 					res = ast_waitfor(chan, ms);
 					if (res <= 0) {

Modified: team/mmichelson/timeout_fixes/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/chan_iax2.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/channels/chan_iax2.c (original)
+++ team/mmichelson/timeout_fixes/channels/chan_iax2.c Tue Oct  2 15:05:31 2012
@@ -13709,6 +13709,7 @@
 	/* By here we must have a dp */
 	if (dp->flags & CACHE_FLAG_PENDING) {
 		struct timeval start;
+		int ms;
 		/* Okay, here it starts to get nasty.  We need a pipe now to wait
 		   for a reply to come back so long as it's pending */
 		for (x = 0; x < ARRAY_LEN(dp->waiters); x++) {
@@ -13734,8 +13735,7 @@
 			old = ast_channel_defer_dtmf(chan);
 		doabort = 0;
 		start = ast_tvnow();
-		while (ast_tvdiff_ms(ast_tvnow(), start) < timeout) {
-			int ms = ast_remaining_ms(start, timeout);
+		while ((ms = ast_remaining_ms(start, timeout))) {
 			c = ast_waitfor_nandfds(&chan, chan ? 1 : 0, &com[0], 1, NULL, &outfd, &ms);
 			if (outfd > -1)
 				break;

Modified: team/mmichelson/timeout_fixes/channels/sig_analog.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/sig_analog.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/channels/sig_analog.c (original)
+++ team/mmichelson/timeout_fixes/channels/sig_analog.c Tue Oct  2 15:05:31 2012
@@ -2387,6 +2387,7 @@
 				int k = 0;
 				int oldlinearity; 
 				int timeout_ms;
+				int ms;
 				struct timeval start = ast_tvnow();
 				cs = NULL;
 				ast_debug(1, "Receiving DTMF cid on channel %s\n", chan->name);
@@ -2401,10 +2402,9 @@
 				 */
 				ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
 				timeout_ms = 4000;/* This is a typical OFF time between rings. */
-				while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
+				while ((ms = ast_remaining_ms(start, timeout_ms))) {
 					struct ast_frame *f;
-					int ms = ast_remaining_ms(start, timeout_ms);
-					
+
 					res = ast_waitfor(chan, ms);
 					if (res <= 0) {
 						/*
@@ -2461,6 +2461,7 @@
 
 				if (!analog_start_cid_detect(p, p->cid_signalling)) {
 					int off_ms;
+					int ms;
 					struct timeval off_start;
 					while (1) {
 						res = analog_get_callerid(p, namebuf, numbuf, &ev, timeout - ast_tvdiff_ms(ast_tvnow(), start));
@@ -2501,9 +2502,8 @@
 					/* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
 					off_start = ast_tvnow();
 					off_ms = 4000;/* This is a typical OFF time between rings. */
-					while (ast_tvdiff_ms(ast_tvnow(), off_start) < off_ms) {
+					while ((ms = ast_remaining_ms(off_start, off_ms))) {
 						struct ast_frame *f;
-						int ms = ast_remaining_ms(off_start, off_ms);
 
 						res = ast_waitfor(chan, ms);
 						if (res <= 0) {

Modified: team/mmichelson/timeout_fixes/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/sig_pri.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/channels/sig_pri.c (original)
+++ team/mmichelson/timeout_fixes/channels/sig_pri.c Tue Oct  2 15:05:31 2012
@@ -1832,6 +1832,7 @@
 	char ex[80];
 	/* Wait up to 30 seconds for an answer */
 	int timeout_ms = 30000;
+	int ms;
 	struct timeval start;
 
 	ast_verb(3, "Initiating idle call on channel %s\n", chan->name);
@@ -1842,9 +1843,7 @@
 		return NULL;
 	}
 	start = ast_tvnow();
-	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
-		int ms = ast_remaining_ms(start, timeout_ms);
-
+	while ((ms = ast_remaining_ms(start, timeout_ms))) {
 		if (ast_waitfor(chan, ms) <= 0) {
 			break;
 		}

Modified: team/mmichelson/timeout_fixes/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/main/channel.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/main/channel.c (original)
+++ team/mmichelson/timeout_fixes/main/channel.c Tue Oct  2 15:05:31 2012
@@ -1842,6 +1842,7 @@
 	struct ast_silence_generator *silgen = NULL;
 	int res = 0;
 	struct timeval start;
+	int ms;
 	AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;
 
 	AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
@@ -1852,9 +1853,8 @@
 	}
 
 	start = ast_tvnow();
-	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
+	while ((ms = ast_remaining_ms(start, timeout_ms))) {
 		struct ast_frame *dup_f = NULL;
-		int ms = ast_remaining_ms(start, timeout_ms);
 
 		if (cond && ((*cond)(data) == 0)) {
 			break;
@@ -3576,6 +3576,7 @@
 int ast_waitfordigit_full(struct ast_channel *c, int timeout_ms, int audiofd, int cmdfd)
 {
 	struct timeval start = ast_tvnow();
+	int ms;
 
 	/* Stop if we're a zombie or need a soft hangup */
 	if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
@@ -3587,10 +3588,9 @@
 	/* Wait for a digit, no more than timeout_ms milliseconds total.
 	 * Or, wait indefinitely if timeout_ms is <0.
 	 */
-	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms || timeout_ms < 0) {
+	while ((ms = ast_remaining_ms(start, timeout_ms))) {
 		struct ast_channel *rchan;
 		int outfd = -1;
-		int ms = ast_remaining_ms(start, timeout_ms);
 
 		errno = 0;
 		/* While ast_waitfor_nandfds tries to help by reducing the timeout by how much was waited,

Modified: team/mmichelson/timeout_fixes/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/main/pbx.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/main/pbx.c (original)
+++ team/mmichelson/timeout_fixes/main/pbx.c Tue Oct  2 15:05:31 2012
@@ -8719,11 +8719,10 @@
 	struct ast_frame *f;
 	struct ast_app *app;
 	struct timeval start = ast_tvnow();
-
-	while ((ast_tvdiff_ms(ast_tvnow(), start) < timeout || timeout < 0) &&
+	int ms;
+
+	while ((ms = ast_remaining_ms(start, timeout)) &&
 			chan->_state != AST_STATE_UP) {
-		int ms = ast_remaining_ms(start, timeout);
-
 		res = ast_waitfor(chan, ms);
 		if (res < 1)
 			break;

Modified: team/mmichelson/timeout_fixes/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/res/res_fax.c?view=diff&rev=374228&r1=374227&r2=374228
==============================================================================
--- team/mmichelson/timeout_fixes/res/res_fax.c (original)
+++ team/mmichelson/timeout_fixes/res/res_fax.c Tue Oct  2 15:05:31 2012
@@ -1088,6 +1088,7 @@
 	struct ast_frame *frame = NULL;
 	struct ast_control_t38_parameters t38_parameters = { .request_response = AST_T38_REQUEST_TERMINATE, };
 	struct timeval start;
+	int ms;
 
 	ast_debug(1, "Shutting down T.38 on %s\n", chan->name);
 	if (ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)) != 0) {
@@ -1098,8 +1099,7 @@
 	/* wait up to five seconds for negotiation to complete */
 	timeout_ms = 5000;
 	start = ast_tvnow();
-	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
-		int ms = ast_remaining_ms(start, timeout_ms);
+	while ((ms = ast_remaining_ms(start, timeout_ms))) {
 		int res = ast_waitfor(chan, ms);
 
 		if (res < 0) {
@@ -1419,6 +1419,7 @@
 	struct ast_frame *frame = NULL;
 	struct ast_control_t38_parameters t38_parameters;
 	struct timeval start;
+	int ms;
 
 	t38_parameters_ast_to_fax(&details->our_t38_parameters, &our_t38_parameters);
 
@@ -1432,8 +1433,7 @@
 
 		timeout_ms = 3000;
 		start = ast_tvnow();
-		while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
-			int ms = ast_remaining_ms(start, timeout_ms);
+		while ((ms = ast_remaining_ms(start, timeout_ms))) {
 			int res = ast_waitfor(chan, ms);
 
 			if (res < 0) {
@@ -1502,7 +1502,7 @@
 	}
 
 	start = ast_tvnow();
-	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
+	while ((ms = ast_remaining_ms(start, timeout_ms))) {
 		int ms = ast_remaining_ms(start, timeout_ms);
 		int res = ast_waitfor(chan, ms);
 
@@ -1824,6 +1824,7 @@
 	struct ast_frame *frame = NULL;
 	struct ast_control_t38_parameters t38_parameters;
 	struct timeval start;
+	int ms;
 
 	t38_parameters_ast_to_fax(&details->our_t38_parameters, &our_t38_parameters);
 
@@ -1844,8 +1845,7 @@
 	}
 
 	start = ast_tvnow();
-	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
-		int ms = ast_remaining_ms(start, timeout_ms);
+	while ((ms = ast_remaining_ms(start, timeout_ms))) {
 		int res = ast_waitfor(chan, ms);
 
 		if (res < 0) {
@@ -1914,8 +1914,7 @@
 		}
 
 		start = ast_tvnow();
-		while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
-			int ms = ast_remaining_ms(start, timeout_ms);
+		while ((ms = ast_remaining_ms(start, timeout_ms))) {
 			int res = ast_waitfor(chan, ms);
 
 			if (res < 0) {
@@ -1982,8 +1981,7 @@
 
 			timeout_ms = 3500;
 			start = ast_tvnow();
-			while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms || timeout_ms < 0) {
-				int ms = ast_remaining_ms(start, timeout_ms);
+			while ((ms = ast_remaining_ms(start, timeout_ms))) {
 				int res = ast_waitfor(chan, ms);
 
 				if (res < 0) {




More information about the asterisk-commits mailing list