summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2012-09-13 20:02:56 +0000
committerDavid M. Lee <dlee@digium.com>2012-09-13 20:02:56 +0000
commit192e6a0f7aec9b006b4c24c9cd16cdb2ac96c16c (patch)
tree22d71840979f9b7287770e0caca4f5a3fc28d336 /main
parentfb1d9a90a4e67c832486f35c54dab5b99ef62941 (diff)
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 ........ Merged revisions 373025 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 373029 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@373046 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/channel.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/main/channel.c b/main/channel.c
index d62f34239..b25484598 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -3530,7 +3530,6 @@ int ast_waitfor(struct ast_channel *c, int ms)
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);
@@ -3579,8 +3578,10 @@ int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const v
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(ast_channel_flags(c), AST_FLAG_ZOMBIE) || ast_check_hangup(c))
return -1;
@@ -3588,13 +3589,27 @@ int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int cmdfd)
/* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
ast_set_flag(ast_channel_flags(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) {