summaryrefslogtreecommitdiff
path: root/main/channel.c
diff options
context:
space:
mode:
authorKevin P. Fleming <kpfleming@digium.com>2008-07-01 19:53:03 +0000
committerKevin P. Fleming <kpfleming@digium.com>2008-07-01 19:53:03 +0000
commit8cdb1f7f416a232ba02ef90afd36189b723f04e7 (patch)
tree834e9c6668afd0656a96748b66d93ef77919f281 /main/channel.c
parentcfb8fb7e438d0bef845a59f6817617e61d8ff1c1 (diff)
change the process of inserting a delay into the ast_answer() path so that we don't tell the calling channel that it has been answered unutil after the delay; for a single-thread call this won't matter all, but for a dual-thread call (using chan_local) this may fix the problem in issue 12924
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@127113 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/channel.c')
-rw-r--r--main/channel.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/main/channel.c b/main/channel.c
index a83c3c94d..f94afd9cd 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1696,15 +1696,31 @@ int __ast_answer(struct ast_channel *chan, unsigned int delay)
switch (chan->_state) {
case AST_STATE_RINGING:
case AST_STATE_RING:
- if (chan->tech->answer)
- res = chan->tech->answer(chan);
- ast_setstate(chan, AST_STATE_UP);
- ast_cdr_answer(chan->cdr);
- ast_channel_unlock(chan);
- if (delay)
+ if (delay) {
+ int needanswer = (chan->tech->answer != NULL);
+
+ ast_setstate(chan, AST_STATE_UP);
+ ast_cdr_answer(chan->cdr);
+ ast_channel_unlock(chan);
ast_safe_sleep(chan, delay);
+ /* don't tell the channel it has been answered until *after* the delay,
+ so that the media path will be in place and usable when it wants to
+ send media
+ */
+ if (needanswer) {
+ ast_channel_lock(chan);
+ res = chan->tech->answer(chan);
+ ast_channel_unlock(chan);
+ }
+ } else {
+ if (chan->tech->answer) {
+ res = chan->tech->answer(chan);
+ }
+ ast_setstate(chan, AST_STATE_UP);
+ ast_cdr_answer(chan->cdr);
+ ast_channel_unlock(chan);
+ }
return res;
- break;
case AST_STATE_UP:
ast_cdr_answer(chan->cdr);
break;