提交 b1e72c8b authored 作者: Anthony Minessale's avatar Anthony Minessale

improve shutdown/unload

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9573 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 804c4fb8
...@@ -350,6 +350,8 @@ SWITCH_DECLARE(void) switch_core_session_rwunlock(_In_ switch_core_session_t *se ...@@ -350,6 +350,8 @@ SWITCH_DECLARE(void) switch_core_session_rwunlock(_In_ switch_core_session_t *se
*/ */
SWITCH_DECLARE(int) switch_core_add_state_handler(_In_ const switch_state_handler_table_t *state_handler); SWITCH_DECLARE(int) switch_core_add_state_handler(_In_ const switch_state_handler_table_t *state_handler);
SWITCH_DECLARE(void) switch_core_remove_state_handler(_In_ const switch_state_handler_table_t *state_handler);
/*! /*!
\brief Access a state handler \brief Access a state handler
\param index the desired index to access \param index the desired index to access
......
...@@ -60,7 +60,7 @@ static struct { ...@@ -60,7 +60,7 @@ static struct {
SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load); SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown);
SWITCH_MODULE_DEFINITION(mod_cdr_csv, mod_cdr_csv_load, NULL, NULL); SWITCH_MODULE_DEFINITION(mod_cdr_csv, mod_cdr_csv_load, mod_cdr_csv_shutdown, NULL);
static off_t fd_size(int fd) static off_t fd_size(int fd)
{ {
...@@ -172,6 +172,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session) ...@@ -172,6 +172,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
const char *log_dir = NULL, *accountcode = NULL, *a_template_str = NULL, *g_template_str = NULL; const char *log_dir = NULL, *accountcode = NULL, *a_template_str = NULL, *g_template_str = NULL;
char *log_line, *path = NULL; char *log_line, *path = NULL;
if (globals.shutdown) {
return SWITCH_STATUS_SUCCESS;
}
if (!((globals.legs & CDR_LEG_A) && (globals.legs & CDR_LEG_B))) { if (!((globals.legs & CDR_LEG_A) && (globals.legs & CDR_LEG_B))) {
if ((globals.legs & CDR_LEG_A)) { if ((globals.legs & CDR_LEG_A)) {
if (switch_channel_get_originator_caller_profile(channel)) { if (switch_channel_get_originator_caller_profile(channel)) {
...@@ -258,6 +262,10 @@ static void event_handler(switch_event_t *event) ...@@ -258,6 +262,10 @@ static void event_handler(switch_event_t *event)
void *val; void *val;
cdr_fd_t *fd; cdr_fd_t *fd;
if (globals.shutdown) {
return;
}
if (sig && !strcmp(sig, "HUP")) { if (sig && !strcmp(sig, "HUP")) {
for (hi = switch_hash_first(NULL, globals.fd_hash); hi; hi = switch_hash_next(hi)) { for (hi = switch_hash_first(NULL, globals.fd_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val); switch_hash_this(hi, NULL, NULL, &val);
...@@ -385,6 +393,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown) ...@@ -385,6 +393,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown)
{ {
globals.shutdown = 1; globals.shutdown = 1;
switch_event_unbind_callback(event_handler);
switch_core_remove_state_handler(&state_handlers);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
......
...@@ -78,6 +78,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session) ...@@ -78,6 +78,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
if (globals.shutdown) {
return SWITCH_STATUS_SUCCESS;
}
if (!globals.log_b && channel && switch_channel_get_originator_caller_profile(channel)) { if (!globals.log_b && channel && switch_channel_get_originator_caller_profile(channel)) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -344,6 +348,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_cdr_shutdown) ...@@ -344,6 +348,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_cdr_shutdown)
{ {
globals.shutdown = 1; globals.shutdown = 1;
switch_core_remove_state_handler(&state_handlers);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
......
...@@ -163,15 +163,46 @@ SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel_t channel) ...@@ -163,15 +163,46 @@ SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel_t channel)
return handle; return handle;
} }
SWITCH_DECLARE(void) switch_core_remove_state_handler(const switch_state_handler_table_t *state_handler)
{
int index, total = 0;
const switch_state_handler_table_t *tmp[SWITCH_MAX_STATE_HANDLERS+1] = { 0 };
switch_mutex_lock(runtime.global_mutex);
for (index = 0; index < runtime.state_handler_index; index++) {
const switch_state_handler_table_t *cur = runtime.state_handlers[index];
runtime.state_handlers[index] = NULL;
if (cur == state_handler) {
continue;
}
tmp[index] = runtime.state_handlers[index];
total++;
}
runtime.state_handler_index = 0;
for (index = 0; index < total; index++) {
runtime.state_handlers[runtime.state_handler_index++] = tmp[index];
}
switch_mutex_unlock(runtime.global_mutex);
}
SWITCH_DECLARE(int) switch_core_add_state_handler(const switch_state_handler_table_t *state_handler) SWITCH_DECLARE(int) switch_core_add_state_handler(const switch_state_handler_table_t *state_handler)
{ {
int index = runtime.state_handler_index++; int index;
switch_mutex_lock(runtime.global_mutex);
index = runtime.state_handler_index++;
if (runtime.state_handler_index >= SWITCH_MAX_STATE_HANDLERS) { if (runtime.state_handler_index >= SWITCH_MAX_STATE_HANDLERS) {
return -1; index = -1;
} else {
runtime.state_handlers[index] = state_handler;
} }
runtime.state_handlers[index] = state_handler; switch_mutex_unlock(runtime.global_mutex);
return index; return index;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论