From d355a572647297ac50da8340a4d17543f93d320f Mon Sep 17 00:00:00 2001 From: Brian West Date: Tue, 4 Jun 2019 17:12:47 -0500 Subject: [PATCH] FS-10634 [mod_spandsp]: txfax failing with 488 Not Acceptable Here race --- src/include/switch_channel.h | 3 +++ src/switch_channel.c | 33 +++++++++++++++++++++++++++++++++ src/switch_core_media.c | 3 +-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index ec066852c6..3786d4583c 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -101,6 +101,9 @@ SWITCH_DECLARE(void) switch_channel_wait_for_state_timeout(switch_channel_t *oth SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *channel, switch_channel_flag_t want_flag, switch_bool_t pres, uint32_t to, switch_channel_t *super_channel); +SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_app_flag(switch_channel_t *channel, + uint32_t app_flag, + const char *key, switch_bool_t pres, uint32_t to); SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_channel_t *channel, const char *file, const char *func, int line, switch_channel_state_t state); diff --git a/src/switch_channel.c b/src/switch_channel.c index c638fbc628..934db1e047 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1748,6 +1748,39 @@ SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *c return SWITCH_STATUS_SUCCESS; } +SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_app_flag(switch_channel_t *channel, + uint32_t app_flag, + const char *key, switch_bool_t pres, uint32_t to) +{ + if (to) { + to++; + } + + for (;;) { + if (pres) { + if (switch_channel_test_app_flag_key(key, channel, app_flag)) { + break; + } + } else { + if (!switch_channel_test_app_flag_key(key, channel, app_flag)) { + break; + } + } + + switch_cond_next(); + + if (switch_channel_down(channel)) { + return SWITCH_STATUS_FALSE; + } + + if (to && !--to) { + return SWITCH_STATUS_FALSE; + } + } + + return SWITCH_STATUS_SUCCESS; +} + SWITCH_DECLARE(void) switch_channel_set_cap_value(switch_channel_t *channel, switch_channel_cap_t cap, uint32_t value) { diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 4552ba8d9c..e7bce84b43 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -5223,9 +5223,8 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s } } - /* do nothing here, mod_fax will trigger a response (if it's listening =/) */ - if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38_POSSIBLE)) { + if (switch_channel_wait_for_app_flag(channel, CF_APP_T38_POSSIBLE, "T38", SWITCH_TRUE, 2000)) { fmatch = 1; } else {