From 884cfc4465999bb4867a22d086c653ea6b57913c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 29 Aug 2006 20:27:43 +0000 Subject: [PATCH] fix event_socket bugs git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2430 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 2 +- .../mod_event_socket/mod_event_socket.c | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 22878436a4..898456fb5a 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -61,7 +61,7 @@ BEGIN_EXTERN_C !strcasecmp(expr, "true") ||\ atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE -#define SWITCH_STATUS_IS_BREAK(x) (x || x == SWITCH_STATUS_BREAK || x == 730035 || x == 35) +#define SWITCH_STATUS_IS_BREAK(x) (x == SWITCH_STATUS_BREAK || x == 730035 || x == 35) /*! \brief Return a printable name of a switch_priority_t diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index 26270ea767..cd9a97539d 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -31,7 +31,6 @@ */ #include #define CMD_BUFLEN 1024 * 1000 -#define IS_BREAK(x) ((int)x || SWITCH_STATUS_BREAK || (int)x == 730035 || (int)x == 35) static const char modname[] = "mod_event_socket"; static char *MARKER = "1"; @@ -68,6 +67,7 @@ typedef struct listener listener_t; static struct { switch_socket_t *sock; switch_mutex_t *mutex; + switch_mutex_t *sock_mutex; listener_t *listeners; uint8_t ready; } listen_list; @@ -152,25 +152,28 @@ static switch_loadable_module_interface_t event_socket_module_interface = { static void close_socket(switch_socket_t **sock) { - + switch_mutex_lock(listen_list.sock_mutex); if (*sock) { apr_socket_shutdown(*sock, APR_SHUTDOWN_READWRITE); switch_socket_close(*sock); *sock = NULL; } + switch_mutex_unlock(listen_list.sock_mutex); } SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void) { listener_t *l; + close_socket(&listen_list.sock); + switch_mutex_lock(listen_list.mutex); for (l = listen_list.listeners; l; l = l->next) { close_socket(&l->sock); } switch_mutex_unlock(listen_list.mutex); - close_socket(&listen_list.sock); + return SWITCH_STATUS_SUCCESS; } @@ -646,7 +649,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj) } -/* Create a thread for the conference and launch it */ +/* Create a thread for the socket and launch it */ static void launch_listener_thread(listener_t *listener) { switch_thread_t *thread; @@ -718,7 +721,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) } switch_mutex_init(&listen_list.mutex, SWITCH_MUTEX_NESTED, pool); - + switch_mutex_init(&listen_list.sock_mutex, SWITCH_MUTEX_NESTED, pool); + for(;;) { rv = switch_sockaddr_info_get(&sa, prefs.ip, APR_INET, prefs.port, 0, pool); @@ -767,11 +771,12 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) listener->sock = inbound_socket; listener->pool = listener_pool; + listener_pool = NULL; listener->format = EVENT_FORMAT_PLAIN; - switch_mutex_init(&listener->flag_mutex, SWITCH_MUTEX_NESTED, listener_pool); - switch_core_hash_init(&listener->event_hash, listener_pool); - + switch_mutex_init(&listener->flag_mutex, SWITCH_MUTEX_NESTED, listener->pool); + switch_core_hash_init(&listener->event_hash, listener->pool); launch_listener_thread(listener); + } close_socket(&listen_list.sock);