diff options
Diffstat (limited to 'apps/app_waitforring.c')
-rw-r--r-- | apps/app_waitforring.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/apps/app_waitforring.c b/apps/app_waitforring.c index bd0353b07..fc02de303 100644 --- a/apps/app_waitforring.c +++ b/apps/app_waitforring.c @@ -63,22 +63,29 @@ static int waitforring_exec(struct ast_channel *chan, const char *data) struct ast_silence_generator *silgen = NULL; int res = 0; double s; + int timeout_ms; int ms; + struct timeval start = ast_tvnow(); if (!data || (sscanf(data, "%30lg", &s) != 1)) { ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n"); return 0; } + if (s < 0.0) { + ast_log(LOG_WARNING, "Invalid timeout provided for WaitForRing (%lg)\n", s); + return 0; + } + if (ast_opt_transmit_silence) { silgen = ast_channel_start_silence_generator(chan); } - ms = s * 1000.0; - while (ms > 0) { + timeout_ms = s * 1000.0; + while ((ms = ast_remaining_ms(start, timeout_ms))) { ms = ast_waitfor(chan, ms); if (ms < 0) { - res = ms; + res = -1; break; } if (ms > 0) { @@ -95,14 +102,12 @@ static int waitforring_exec(struct ast_channel *chan, const char *data) } /* Now we're really ready for the ring */ if (!res) { - ms = 99999999; - while(ms > 0) { - ms = ast_waitfor(chan, ms); - if (ms < 0) { - res = ms; + for (;;) { + int wait_res = ast_waitfor(chan, -1); + if (wait_res < 0) { + res = -1; break; - } - if (ms > 0) { + } else { f = ast_read(chan); if (!f) { res = -1; |