[asterisk-commits] mmichelson: branch mmichelson/timeout_fixes r373908 - /team/mmichelson/timeou...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 27 11:27:47 CDT 2012


Author: mmichelson
Date: Thu Sep 27 11:27:42 2012
New Revision: 373908

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=373908
Log:
Take care of 6 of the 7 timeout problems in res_fax.

The seventh is a little more involved, so I'm doing
it as a separate change.


Modified:
    team/mmichelson/timeout_fixes/res/res_fax.c

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=373908&r1=373907&r2=373908
==============================================================================
--- team/mmichelson/timeout_fixes/res/res_fax.c (original)
+++ team/mmichelson/timeout_fixes/res/res_fax.c Thu Sep 27 11:27:42 2012
@@ -1084,9 +1084,10 @@
 
 static int disable_t38(struct ast_channel *chan)
 {
-	int ms;
+	int timeout_ms;
 	struct ast_frame *frame = NULL;
 	struct ast_control_t38_parameters t38_parameters = { .request_response = AST_T38_REQUEST_TERMINATE, };
+	struct timeval start;
 
 	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) {
@@ -1095,16 +1096,18 @@
 	}
 
 	/* wait up to five seconds for negotiation to complete */
-	ms = 5000;
-
-	while (ms > 0) {
-		ms = ast_waitfor(chan, ms);
-		if (ms < 0) {
+	timeout_ms = 5000;
+	start = ast_tvnow();
+	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
+		int ms = ast_remaining_ms(start, timeout_ms);
+		int res = ast_waitfor(chan, ms);
+
+		if (res < 0) {
 			ast_debug(1, "error while disabling T.38 on channel '%s'\n", chan->name);
 			return -1;
 		}
 
-		if (ms == 0) { /* all done, nothing happened */
+		if (res == 0) { /* all done, nothing happened */
 			ast_debug(1, "channel '%s' timed-out during T.38 shutdown\n", chan->name);
 			break;
 		}
@@ -1407,9 +1410,10 @@
 
 static int receivefax_t38_init(struct ast_channel *chan, struct ast_fax_session_details *details)
 {
-	int ms;
+	int timeout_ms;
 	struct ast_frame *frame = NULL;
 	struct ast_control_t38_parameters t38_parameters;
+	struct timeval start;
 
 	t38_parameters_ast_to_fax(&details->our_t38_parameters, &our_t38_parameters);
 
@@ -1421,16 +1425,19 @@
 			return -1;
 		}
 
-		ms = 3000;
-		while (ms > 0) {
-			ms = ast_waitfor(chan, ms);
-			if (ms < 0) {
+		timeout_ms = 3000;
+		start = ast_tvnow();
+		while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
+			int ms = ast_remaining_ms(start, timeout_ms);
+			int res = ast_waitfor(chan, ms);
+
+			if (res < 0) {
 				ast_log(LOG_ERROR, "error while generating CED tone on %s\n", chan->name);
 				ast_playtones_stop(chan);
 				return -1;
 			}
 
-			if (ms == 0) { /* all done, nothing happened */
+			if (res == 0) { /* all done, nothing happened */
 				break;
 			}
 
@@ -1480,7 +1487,7 @@
 	ast_debug(1, "Negotiating T.38 for receive on %s\n", chan->name);
 
 	/* wait up to five seconds for negotiation to complete */
-	ms = 5000;
+	timeout_ms = 5000;
 
 	/* set parameters based on the session's parameters */
 	t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
@@ -1489,14 +1496,17 @@
 		return -1;
 	}
 
-	while (ms > 0) {
-		ms = ast_waitfor(chan, ms);
-		if (ms < 0) {
+	start = ast_tvnow();
+	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
+		int ms = ast_remaining_ms(start, timeout_ms);
+		int res = ast_waitfor(chan, ms);
+
+		if (res < 0) {
 			ast_log(LOG_WARNING, "error on '%s' while waiting for T.38 negotiation.\n", chan->name);
 			return -1;
 		}
 
-		if (ms == 0) { /* all done, nothing happened */
+		if (res == 0) { /* all done, nothing happened */
 			ast_log(LOG_WARNING, "channel '%s' timed-out during the T.38 negotiation.\n", chan->name);
 			details->caps &= ~AST_FAX_TECH_T38;
 			break;
@@ -1805,9 +1815,10 @@
 
 static int sendfax_t38_init(struct ast_channel *chan, struct ast_fax_session_details *details)
 {
-	int ms;
+	int timeout_ms;
 	struct ast_frame *frame = NULL;
 	struct ast_control_t38_parameters t38_parameters;
+	struct timeval start;
 
 	t38_parameters_ast_to_fax(&details->our_t38_parameters, &our_t38_parameters);
 
@@ -1817,7 +1828,7 @@
 	 *
 	 * 10500 is enough time for 3 CNG tones
 	 */
-	ms = 10500;
+	timeout_ms = 10500;
 
 	/* don't send any audio if we've already received a T.38 reinvite */
 	if (ast_channel_get_t38_state(chan) != T38_STATE_NEGOTIATING) {
@@ -1827,15 +1838,18 @@
 		}
 	}
 
-	while (ms > 0) {
-		ms = ast_waitfor(chan, ms);
-		if (ms < 0) {
+	start = ast_tvnow();
+	while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
+		int ms = ast_remaining_ms(start, timeout_ms);
+		int res = ast_waitfor(chan, ms);
+
+		if (res < 0) {
 			ast_log(LOG_ERROR, "error while generating CNG tone on %s\n", chan->name);
 			ast_playtones_stop(chan);
 			return -1;
 		}
 
-		if (ms == 0) { /* all done, nothing happened */
+		if (res == 0) { /* all done, nothing happened */
 			break;
 		}
 
@@ -1885,7 +1899,7 @@
 		ast_debug(1, "Negotiating T.38 for send on %s\n", chan->name);
 
 		/* wait up to five seconds for negotiation to complete */
-		ms = 5000;
+		timeout_ms = 5000;
 
 		/* set parameters based on the session's parameters */
 		t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
@@ -1894,14 +1908,17 @@
 			return -1;
 		}
 
-		while (ms > 0) {
-			ms = ast_waitfor(chan, ms);
-			if (ms < 0) {
+		start = ast_tvnow();
+		while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
+			int ms = ast_remaining_ms(start, timeout_ms);
+			int res = ast_waitfor(chan, ms);
+
+			if (res < 0) {
 				ast_log(LOG_WARNING, "error on '%s' while waiting for T.38 negotiation.\n", chan->name);
 				return -1;
 			}
 
-			if (ms == 0) { /* all done, nothing happened */
+			if (res == 0) { /* all done, nothing happened */
 				ast_log(LOG_WARNING, "channel '%s' timed-out during the T.38 negotiation.\n", chan->name);
 				details->caps &= ~AST_FAX_TECH_T38;
 				break;
@@ -1958,16 +1975,19 @@
 				return -1;
 			}
 
-			ms = 3500;
-			while (ms > 0) {
-				ms = ast_waitfor(chan, ms);
-				if (ms < 0) {
+			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);
+				int res = ast_waitfor(chan, ms);
+
+				if (res < 0) {
 					ast_log(LOG_ERROR, "error while generating second CNG tone on %s\n", chan->name);
 					ast_playtones_stop(chan);
 					return -1;
 				}
 
-				if (ms == 0) { /* all done, nothing happened */
+				if (res == 0) { /* all done, nothing happened */
 					break;
 				}
 




More information about the asterisk-commits mailing list