summaryrefslogtreecommitdiff
path: root/channel.c
diff options
context:
space:
mode:
authorMark Spencer <markster@digium.com>2004-03-05 18:22:31 +0000
committerMark Spencer <markster@digium.com>2004-03-05 18:22:31 +0000
commit94f3b5751af5d9a885af3706ae0a72eca9160079 (patch)
treeb21ffd715f5920eed6932847178a49382f524290 /channel.c
parente42e998f765bc4196cf180fa355b6bfab2d52617 (diff)
Consider whentohangup in timeout (bug #1107)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2349 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channel.c')
-rwxr-xr-xchannel.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/channel.c b/channel.c
index fa14749ed..603796a42 100755
--- a/channel.c
+++ b/channel.c
@@ -809,15 +809,25 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds,
fd_set rfds, efds;
int res;
int x, y, max=-1;
+ time_t now;
+ long whentohangup = 0, havewhen = 0, diff;
struct ast_channel *winner = NULL;
if (outfd)
- *outfd = -1;
+ *outfd = -99999;
if (exception)
*exception = 0;
+ time(&now);
/* Perform any pending masquerades */
for (x=0;x<n;x++) {
ast_mutex_lock(&c[x]->lock);
+ if (c[x]->whentohangup) {
+ diff = c[x]->whentohangup - now;
+ if (!havewhen || (diff < whentohangup)) {
+ havewhen++;
+ whentohangup = diff;
+ }
+ }
if (c[x]->masq) {
if (ast_do_masquerade(c[x], 1)) {
ast_log(LOG_WARNING, "Masquerade failed\n");
@@ -831,6 +841,13 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds,
tv.tv_sec = *ms / 1000;
tv.tv_usec = (*ms % 1000) * 1000;
+
+ if (havewhen) {
+ if ((*ms < 0) || (whentohangup * 1000 < *ms)) {
+ tv.tv_sec = whentohangup / 1000;
+ tv.tv_usec = (whentohangup % 1000) * 1000;
+ }
+ }
FD_ZERO(&rfds);
FD_ZERO(&efds);
@@ -851,7 +868,7 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds,
if (fds[x] > max)
max = fds[x];
}
- if (*ms >= 0)
+ if ((*ms >= 0) || (havewhen))
res = ast_select(max + 1, &rfds, NULL, &efds, &tv);
else
res = ast_select(max + 1, &rfds, NULL, &efds, NULL);