typedef struct listener listener_t;
+static struct {
+ switch_mutex_t *listener_mutex;
+ switch_event_node_t *node;
+} globals;
+
static struct {
switch_socket_t *sock;
- switch_mutex_t *mutex;
switch_mutex_t *sock_mutex;
listener_t *listeners;
uint8_t ready;
static uint32_t next_id(void)
{
uint32_t id;
- switch_mutex_lock(listen_list.mutex);
+ switch_mutex_lock(globals.listener_mutex);
id = ++prefs.id;
- switch_mutex_unlock(listen_list.mutex);
+ switch_mutex_unlock(globals.listener_mutex);
return id;
}
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj);
static void launch_listener_thread(listener_t *listener);
-static struct {
- switch_event_node_t *node;
-} globals;
-
-
static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
{
listener_t *l;
- switch_mutex_lock(listen_list.mutex);
+ switch_mutex_lock(globals.listener_mutex);
for (l = listen_list.listeners; l; l = l->next) {
if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
char *data = strdup(node->data);
}
}
}
- switch_mutex_unlock(listen_list.mutex);
+ switch_mutex_unlock(globals.listener_mutex);
return SWITCH_STATUS_SUCCESS;
}
lp = listen_list.listeners;
- switch_mutex_lock(listen_list.mutex);
+ switch_mutex_lock(globals.listener_mutex);
while(lp) {
int send = 0;
}
}
- switch_mutex_unlock(listen_list.mutex);
+ switch_mutex_unlock(globals.listener_mutex);
}
SWITCH_STANDARD_APP(socket_function)
}
switch_event_unbind(&globals.node);
- switch_mutex_lock(listen_list.mutex);
+ switch_mutex_lock(globals.listener_mutex);
for (l = listen_list.listeners; l; l = l->next) {
close_socket(&l->sock);
}
- switch_mutex_unlock(listen_list.mutex);
+ switch_mutex_unlock(globals.listener_mutex);
static void add_listener(listener_t *listener)
{
/* add me to the listeners so I get events */
- switch_mutex_lock(listen_list.mutex);
+ switch_mutex_lock(globals.listener_mutex);
listener->next = listen_list.listeners;
listen_list.listeners = listener;
- switch_mutex_unlock(listen_list.mutex);
+ switch_mutex_unlock(globals.listener_mutex);
}
static void remove_listener(listener_t *listener)
{
listener_t *l, *last = NULL;
- switch_mutex_lock(listen_list.mutex);
+ switch_mutex_lock(globals.listener_mutex);
for (l = listen_list.listeners; l; l = l->next) {
if (l == listener) {
if (last) {
}
last = l;
}
- switch_mutex_unlock(listen_list.mutex);
+ switch_mutex_unlock(globals.listener_mutex);
}
{
listener_t *l, *r = NULL;
- switch_mutex_lock(listen_list.mutex);
+ switch_mutex_lock(globals.listener_mutex);
for (l = listen_list.listeners; l; l = l->next) {
if (l->id && l->id == id) {
if (switch_thread_rwlock_tryrdlock(l->rwlock) == SWITCH_STATUS_SUCCESS) {
break;
}
}
- switch_mutex_unlock(listen_list.mutex);
+ switch_mutex_unlock(globals.listener_mutex);
return r;
}
switch_application_interface_t *app_interface;
switch_api_interface_t *api_interface;
+ switch_mutex_init(&globals.listener_mutex, SWITCH_MUTEX_NESTED, pool);
+
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_APP(app_interface, "socket", "Connect to a socket", "Connect to a socket", socket_function, "<ip>[:<port>]", SAF_SUPPORT_NOMEDIA);
switch_channel_t *channel = NULL;
switch_event_t *revent = NULL;
- switch_mutex_lock(listen_list.mutex);
+ switch_mutex_lock(globals.listener_mutex);
prefs.threads++;
- switch_mutex_unlock(listen_list.mutex);
+ switch_mutex_unlock(globals.listener_mutex);
switch_assert(listener != NULL);
switch_core_destroy_memory_pool(&pool);
}
- switch_mutex_lock(listen_list.mutex);
+ switch_mutex_lock(globals.listener_mutex);
prefs.threads--;
- switch_mutex_unlock(listen_list.mutex);
+ switch_mutex_unlock(globals.listener_mutex);
return NULL;
}
return SWITCH_STATUS_TERM;
}
- switch_mutex_init(&listen_list.mutex, SWITCH_MUTEX_NESTED, pool);
+
switch_mutex_init(&listen_list.sock_mutex, SWITCH_MUTEX_NESTED, pool);