prevent race on execute_on_answer called from the B-leg of a call

This commit is contained in:
Anthony Minessale 2010-12-22 19:10:30 -06:00 committed by Brian West
parent 7e880ee33e
commit 751e0291ee
3 changed files with 31 additions and 5 deletions

View File

@ -1096,6 +1096,7 @@ typedef enum {
CF_RECOVERED,
CF_JITTERBUFFER,
CF_DIALPLAN,
CF_BLOCK_BROADCAST_UNTIL_MEDIA,
/* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */
CF_FLAG_MAX
} switch_channel_flag_t;

View File

@ -1841,6 +1841,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_async(sw
switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", arg);
}
if (!switch_channel_test_flag(session->channel, CF_PROXY_MODE)) {
switch_channel_set_flag(session->channel, CF_BLOCK_BROADCAST_UNTIL_MEDIA);
}
switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "event-lock", "true");
switch_core_session_queue_private_event(session, &execute_event, SWITCH_FALSE);
@ -1891,9 +1895,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flag
switch_goto_status(SWITCH_STATUS_FALSE, done);
}
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"Cannot execute app '%s' media required on an outbound channel that does not have media established\n", app);
switch_goto_status(SWITCH_STATUS_FALSE, done);
uint32_t ready = 0, sanity = 2000;
do {
sanity--;
ready = switch_channel_media_ready(session->channel);
switch_cond_next();
} while(!ready && sanity);
if (!ready) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"Cannot execute app '%s' media required on an outbound channel that does not have media established\n", app);
switch_goto_status(SWITCH_STATUS_FALSE, done);
}
}
}

View File

@ -698,12 +698,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_messages(switch_core_sessio
SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_events(switch_core_session_t *session)
{
int x = 0;
switch_channel_t *channel;
switch_ivr_parse_all_messages(session);
while (switch_ivr_parse_next_event(session) == SWITCH_STATUS_SUCCESS)
channel = switch_core_session_get_channel(session);
if (!switch_channel_test_flag(channel, CF_PROXY_MODE) && switch_channel_test_flag(channel, CF_BLOCK_BROADCAST_UNTIL_MEDIA)) {
if (switch_channel_media_ready(channel)) {
switch_channel_clear_flag(channel, CF_BLOCK_BROADCAST_UNTIL_MEDIA);
} else {
return SWITCH_STATUS_SUCCESS;
}
}
while (switch_ivr_parse_next_event(session) == SWITCH_STATUS_SUCCESS) {
x++;
}
if (x) {
switch_ivr_sleep(session, 0, SWITCH_TRUE, NULL);