diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-03-05 18:22:31 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-03-05 18:22:31 +0000 |
commit | 4337816856d05e2fe3da99f6a393572c0a5ae4fc (patch) | |
tree | b21ffd715f5920eed6932847178a49382f524290 /channel.c | |
parent | 0d088255b7b12c27744b6cc4cb7bed06efebbcd7 (diff) |
Consider whentohangup in timeout (bug #1107)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2349 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channel.c')
-rwxr-xr-x | channel.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -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); |