提交 33238099 authored 作者: Anthony Minessale's avatar Anthony Minessale 提交者: Muteesa Fred

FS-11259: [mod_perl] mod_perl tweaks #resolve

上级 9d0ad92d
...@@ -16,6 +16,8 @@ Session::Session():CoreSession() ...@@ -16,6 +16,8 @@ Session::Session():CoreSession()
Session::Session(char *uuid, CoreSession *a_leg):CoreSession(uuid, a_leg) Session::Session(char *uuid, CoreSession *a_leg):CoreSession(uuid, a_leg)
{ {
init_me(); init_me();
switch_mutex_init(&callback_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
if (session && allocated) { if (session && allocated) {
suuid = switch_core_session_sprintf(session, "main::uuid_%s\n", switch_core_session_get_uuid(session)); suuid = switch_core_session_sprintf(session, "main::uuid_%s\n", switch_core_session_get_uuid(session));
for (char *p = suuid; p && *p; p++) { for (char *p = suuid; p && *p; p++) {
...@@ -32,6 +34,8 @@ Session::Session(char *uuid, CoreSession *a_leg):CoreSession(uuid, a_leg) ...@@ -32,6 +34,8 @@ Session::Session(char *uuid, CoreSession *a_leg):CoreSession(uuid, a_leg)
Session::Session(switch_core_session_t *new_session):CoreSession(new_session) Session::Session(switch_core_session_t *new_session):CoreSession(new_session)
{ {
init_me(); init_me();
switch_mutex_init(&callback_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
if (session) { if (session) {
suuid = switch_core_session_sprintf(session, "main::uuid_%s\n", switch_core_session_get_uuid(session)); suuid = switch_core_session_sprintf(session, "main::uuid_%s\n", switch_core_session_get_uuid(session));
for (char *p = suuid; p && *p; p++) { for (char *p = suuid; p && *p; p++) {
...@@ -52,6 +56,10 @@ void Session::destroy(void) ...@@ -52,6 +56,10 @@ void Session::destroy(void)
return; return;
} }
switch_mutex_lock(callback_mutex);
destroying = 1;
switch_mutex_unlock(callback_mutex);
if (session) { if (session) {
if (!channel) { if (!channel) {
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
...@@ -216,10 +224,15 @@ void Session::setInputCallback(char *cbfunc, char *funcargs) ...@@ -216,10 +224,15 @@ void Session::setInputCallback(char *cbfunc, char *funcargs)
switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype) switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype)
{ {
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (!getPERL()) { if (!getPERL()) {
return SWITCH_STATUS_FALSE;; return SWITCH_STATUS_FALSE;;
} }
switch_mutex_lock(callback_mutex);
if (!destroying) {
switch (itype) { switch (itype) {
case SWITCH_INPUT_TYPE_DTMF: case SWITCH_INPUT_TYPE_DTMF:
{ {
...@@ -248,7 +261,7 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp ...@@ -248,7 +261,7 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
Perl_eval_pv(my_perl, code, FALSE); Perl_eval_pv(my_perl, code, FALSE);
free(code); free(code);
return process_callback_result(SvPV(get_sv("__RV", TRUE), n_a)); status = process_callback_result(SvPV(get_sv("__RV", TRUE), n_a));
} }
break; break;
case SWITCH_INPUT_TYPE_EVENT: case SWITCH_INPUT_TYPE_EVENT:
...@@ -257,14 +270,14 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp ...@@ -257,14 +270,14 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
int arg_count = 2; int arg_count = 2;
char *code; char *code;
switch_uuid_t uuid; switch_uuid_t uuid;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1] = "";
char var_name[SWITCH_UUID_FORMATTED_LENGTH + 25]; char var_name[SWITCH_UUID_FORMATTED_LENGTH + 25] = "";
char *p; char *p;
switch_uuid_get(&uuid); switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid); switch_uuid_format(uuid_str, &uuid);
switch_snprintf(var_name, sizeof(var_name), "main::__event_%s", uuid_str); switch_snprintf(var_name, sizeof(var_name), "__event_%s", uuid_str);
for(p = var_name; p && *p; p++) { for(p = var_name; p && *p; p++) {
if (*p == '-') { if (*p == '-') {
*p = '_'; *p = '_';
...@@ -277,10 +290,13 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp ...@@ -277,10 +290,13 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
Perl_eval_pv(my_perl, code, FALSE); Perl_eval_pv(my_perl, code, FALSE);
free(code); free(code);
return process_callback_result(SvPV(get_sv("__RV", TRUE), n_a)); status = process_callback_result(SvPV(get_sv("__RV", TRUE), n_a));
} }
break; break;
} }
}
return SWITCH_STATUS_SUCCESS; switch_mutex_unlock(callback_mutex);
return status;
} }
...@@ -41,6 +41,9 @@ namespace PERL { ...@@ -41,6 +41,9 @@ namespace PERL {
void unsetInputCallback(void); void unsetInputCallback(void);
void setHangupHook(char *func, char *arg = NULL); void setHangupHook(char *func, char *arg = NULL);
bool ready(); bool ready();
switch_mutex_t *callback_mutex;
int destroying = 0;
int event_idx = 0;
char *suuid; char *suuid;
char *cb_function; char *cb_function;
char *cb_arg; char *cb_arg;
......
...@@ -143,7 +143,11 @@ static int perl_parse_and_execute(PerlInterpreter * my_perl, char *input_code, c ...@@ -143,7 +143,11 @@ static int perl_parse_and_execute(PerlInterpreter * my_perl, char *input_code, c
return error; return error;
} }
#ifdef DEBUG_PERL
#define HACK_CLEAN_CODE "eval{foreach my $kl(keys %main::) {eval{print qq'DEBUG: ' . $kl . '/' . $$kl . '/' . $$$kl . qq'\n';undef($$kl);} if (defined($$kl) && ($kl =~ /^\\w+[\\w\\d_]+$/))}}"
#else
#define HACK_CLEAN_CODE "eval{foreach my $kl(keys %main::) {eval{undef($$kl);} if (defined($$kl) && ($kl =~ /^\\w+[\\w\\d_]+$/))}}" #define HACK_CLEAN_CODE "eval{foreach my $kl(keys %main::) {eval{undef($$kl);} if (defined($$kl) && ($kl =~ /^\\w+[\\w\\d_]+$/))}}"
#endif
static void destroy_perl(PerlInterpreter ** to_destroy) static void destroy_perl(PerlInterpreter ** to_destroy)
{ {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论