From 4526ba30c6ec71e56cefb798c16d3867197f2989 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 8 Sep 2010 15:32:34 -0500 Subject: [PATCH] improve sofia recover in some nat cases --- src/mod/endpoints/mod_sofia/mod_sofia.c | 4 +++ src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 39 +++++++++++------------- src/mod/endpoints/mod_sofia/sofia_glue.c | 4 ++- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 19a44f43e1..799cf4f2af 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -85,6 +85,10 @@ static switch_status_t sofia_on_init(switch_core_session_t *session) sofia_glue_tech_absorb_sdp(tech_pvt); } + if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING) || sofia_test_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE)) { + sofia_set_flag(tech_pvt, TFLAG_RECOVERED); + } + if (sofia_test_flag(tech_pvt, TFLAG_OUTBOUND) || sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) { const char *var; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index aa2149503a..4cdb1a2912 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -275,6 +275,7 @@ typedef enum { TFLAG_RECOVERING, TFLAG_RECOVERING_BRIDGE, TFLAG_T38_PASSTHRU, + TFLAG_RECOVERED, /* No new flags below this line */ TFLAG_MAX } TFLAGS; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 14d05fd977..258be0ed59 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1225,7 +1225,7 @@ static void sofia_perform_profile_start_failure(sofia_profile_t *profile, char * #define sofia_profile_start_failure(p, xp) sofia_perform_profile_start_failure(p, xp, __FILE__, __LINE__) -#define SQLLEN 1024 * 64 +#define SQLLEN 1024 * 32 void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread, void *obj) { sofia_profile_t *profile = (sofia_profile_t *) obj; @@ -1236,7 +1236,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread void *pop; int loop_count = 0; switch_size_t sql_len = SQLLEN; - char *tmp, *sqlbuf = NULL; + char *sqlbuf = NULL; + char *sql = NULL; if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) { sqlbuf = (char *) malloc(sql_len); @@ -1253,7 +1254,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread while ((mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) || qsize) { if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) { - if (qsize > 0 && (qsize >= 1024 || ++loop_count >= profile->trans_timeout)) { + if ((qsize > 0 && (qsize >= 1024 || ++loop_count >= profile->trans_timeout)) || sql) { switch_size_t newlen; uint32_t itterations = 0; switch_size_t len = 0; @@ -1262,28 +1263,24 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread //sofia_glue_actually_execute_sql(profile, "begin;\n", NULL); - while (switch_queue_trypop(profile->sql_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) { - char *sql = (char *) pop; - + while (sql || (switch_queue_trypop(profile->sql_queue, &pop) == SWITCH_STATUS_SUCCESS && pop)) { + + if (!sql) { + sql = (char *) pop; + } + newlen = strlen(sql) + 2; - - if (newlen + 10 < SQLLEN) { - itterations++; - if (len + newlen + 10 > sql_len) { - sql_len = len + 10 + SQLLEN; - if (!(tmp = realloc(sqlbuf, sql_len))) { - abort(); - break; - } - sqlbuf = tmp; - } + itterations++; + + if (len + newlen + 10 < sql_len) { sprintf(sqlbuf + len, "%s;\n", sql); len += newlen; + switch_safe_free(sql); + } else { + break; } - - free(pop); } - + //printf("TRANS:\n%s\n", sqlbuf); sofia_glue_actually_execute_sql_trans(profile, sqlbuf, NULL); //sofia_glue_actually_execute_sql(profile, "commit;\n", NULL); @@ -2860,7 +2857,7 @@ switch_status_t config_sofia(int reload, char *profile_name) goto done; } - profile->trans_timeout = 500; + profile->trans_timeout = 100; profile->auto_rtp_bugs = RTP_BUG_CISCO_SKIP_MARK_BIT_2833;// | RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833; diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 82b933c981..45364cdac2 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -2059,6 +2059,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), NUTAG_SESSION_TIMER(session_timeout), + TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX)), TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)), TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)), TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected)), @@ -2087,6 +2088,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), NUTAG_SESSION_TIMER(session_timeout), + TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX)), TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)), TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)), TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected)), @@ -4644,7 +4646,7 @@ void sofia_glue_tech_untrack(sofia_profile_t *profile, switch_core_session_t *se } } - sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); + sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); sofia_clear_flag(tech_pvt, TFLAG_TRACKED); switch_safe_free(sql);