[svn-commits] dlee: branch 10 r373025 - in /branches/10: ./ include/asterisk/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Sep 13 13:44:33 CDT 2012


Author: dlee
Date: Thu Sep 13 13:44:30 2012
New Revision: 373025

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=373025
Log:
Fix timeouts for ast_waitfordigit[_full].

ast_waitfordigit_full would simply pass its timeout to ast_waitfor_nandfds,
expecting it to decrement the timeout by however many milliseconds were
waited. This is a problem if it consistently waits less than 1ms. The timeout
will never be decremented, and we wait... FOREVER!

This patch makes ast_waitfordigit_full manage the timeout itself. It maintains
the previously undocumented behavior that negative timeouts wait forever.

(closes issue ASTERISK-20375)
Reported by: Mark Michelson
Tested by: Mark Michelson
Review: https://reviewboard.asterisk.org/r/2109/
........

Merged revisions 373024 from http://svn.asterisk.org/svn/asterisk/branches/1.8

Modified:
    branches/10/   (props changed)
    branches/10/include/asterisk/channel.h
    branches/10/main/channel.c

Propchange: branches/10/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.

Modified: branches/10/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/branches/10/include/asterisk/channel.h?view=diff&rev=373025&r1=373024&r2=373025
==============================================================================
--- branches/10/include/asterisk/channel.h (original)
+++ branches/10/include/asterisk/channel.h Thu Sep 13 13:44:30 2012
@@ -1910,7 +1910,7 @@
 /*!
  * \brief Waits for a digit
  * \param c channel to wait for a digit on
- * \param ms how many milliseconds to wait
+ * \param ms how many milliseconds to wait (<0 for indefinite).
  * \return Returns <0 on error, 0 on no entry, and the digit on success.
  */
 int ast_waitfordigit(struct ast_channel *c, int ms);
@@ -1919,7 +1919,7 @@
  * \brief Wait for a digit
  * Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
  * \param c channel to wait for a digit on
- * \param ms how many milliseconds to wait
+ * \param ms how many milliseconds to wait (<0 for indefinite).
  * \param audiofd audio file descriptor to write to if audio frames are received
  * \param ctrlfd control file descriptor to monitor for reading
  * \return Returns 1 if ctrlfd becomes available

Modified: branches/10/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/main/channel.c?view=diff&rev=373025&r1=373024&r2=373025
==============================================================================
--- branches/10/main/channel.c (original)
+++ branches/10/main/channel.c Thu Sep 13 13:44:30 2012
@@ -3566,7 +3566,6 @@
 	return ms;
 }
 
-/* XXX never to be called with ms = -1 */
 int ast_waitfordigit(struct ast_channel *c, int ms)
 {
 	return ast_waitfordigit_full(c, ms, -1, -1);
@@ -3615,8 +3614,10 @@
 	return res;
 }
 
-int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int cmdfd)
-{
+int ast_waitfordigit_full(struct ast_channel *c, int timeout_ms, int audiofd, int cmdfd)
+{
+	struct timeval start = ast_tvnow();
+
 	/* Stop if we're a zombie or need a soft hangup */
 	if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
 		return -1;
@@ -3624,15 +3625,29 @@
 	/* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
 	ast_set_flag(c, AST_FLAG_END_DTMF_ONLY);
 
-	/* Wait for a digit, no more than ms milliseconds total. */
-	
-	while (ms) {
+	/* 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) {
 		struct ast_channel *rchan;
 		int outfd=-1;
+		int ms;
+
+		if (timeout_ms < 0) {
+			ms = timeout_ms;
+		} else {
+			ms = timeout_ms - ast_tvdiff_ms(ast_tvnow(), start);
+			if (ms < 0) {
+				ms = 0;
+			}
+		}
 
 		errno = 0;
+		/* While ast_waitfor_nandfds tries to help by reducing the timeout by how much was waited,
+		 * it is unhelpful if it waited less than a millisecond.
+		 */
 		rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
-		
+
 		if (!rchan && outfd < 0 && ms) {
 			if (errno == 0 || errno == EINTR)
 				continue;




More information about the svn-commits mailing list