提交 59bb764f authored 作者: Mathieu Parent's avatar Mathieu Parent

Skinny: avoid some crashes

- move api to own file
- really allow several profiles (one thread per profile)
- global pool
- pool per profile
- Remove unused globals.calls
- Check for closed listener before sending data
- use mutex for hashes
上级 b8ac781c
......@@ -3,7 +3,7 @@ include $(top_srcdir)/build/modmake.rulesam
MODNAME=mod_skinny
mod_LTLIBRARIES = mod_skinny.la
mod_skinny_la_SOURCES = mod_skinny.c skinny_protocol.c skinny_tables.c
mod_skinny_la_SOURCES = mod_skinny.c skinny_protocol.c skinny_tables.c skinny_api.c
mod_skinny_la_CFLAGS = $(AM_CFLAGS) -DSKINNY_SVN_VERSION=\"`cat $(switch_builddir)/.version`\"
mod_skinny_la_LIBADD = $(switch_builddir)/libfreeswitch.la
mod_skinny_la_LDFLAGS = -avoid-version -module -no-undefined -shared
......@@ -45,13 +45,12 @@
#define SKINNY_EVENT_CALL_STATE "skinny::call_state"
struct skinny_globals {
/* data */
int calls;
switch_mutex_t *calls_mutex;
int running;
switch_memory_pool_t *pool;
switch_mutex_t *mutex;
switch_hash_t *profile_hash;
switch_event_node_t *heartbeat_node;
switch_event_node_t *call_state_node;
int running;
};
typedef struct skinny_globals skinny_globals_t;
......@@ -89,6 +88,8 @@ struct skinny_profile {
uint8_t listener_ready;
/* call id */
uint32_t next_call_id;
/* others */
switch_memory_pool_t *pool;
};
typedef struct skinny_profile skinny_profile_t;
......@@ -183,9 +184,13 @@ typedef struct private_object private_t;
/*****************************************************************************/
/* PROFILES FUNCTIONS */
/*****************************************************************************/
skinny_profile_t *skinny_find_profile(const char *profile_name);
switch_status_t skinny_profile_dump(const skinny_profile_t *profile, switch_stream_handle_t *stream);
switch_status_t skinny_profile_find_listener_by_device_name(skinny_profile_t *profile, const char *device_name, listener_t **listener);
switch_status_t skinny_profile_find_listener_by_device_name_and_instance(skinny_profile_t *profile, const char *device_name, uint32_t device_instance, listener_t **listener);
char * skinny_profile_find_session_uuid(skinny_profile_t *profile, listener_t *listener, uint32_t *line_instance_p, uint32_t call_id);
switch_core_session_t * skinny_profile_find_session(skinny_profile_t *profile, listener_t *listener, uint32_t *line_instance_p, uint32_t call_id);
switch_status_t dump_device(skinny_profile_t *profile, const char *device_name, switch_stream_handle_t *stream);
/*****************************************************************************/
/* SQL FUNCTIONS */
......@@ -197,6 +202,7 @@ switch_bool_t skinny_execute_sql_callback(skinny_profile_t *profile,
/*****************************************************************************/
/* LISTENER FUNCTIONS */
/*****************************************************************************/
uint8_t listener_is_ready(listener_t *listener);
switch_status_t keepalive_listener(listener_t *listener, void *pvt);
/*****************************************************************************/
......@@ -229,3 +235,14 @@ switch_endpoint_interface_t *skinny_get_endpoint_interface();
#endif /* _MOD_SKINNY_H */
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
......@@ -142,13 +142,13 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req)
return SWITCH_STATUS_MEMERR;
}
if (!globals.running) {
if (!listener_is_ready(listener)) {
return SWITCH_STATUS_FALSE;
}
ptr = mbuf;
while (listener->sock && globals.running) {
while (listener->sock && listener_is_ready(listener)) {
uint8_t do_sleep = 1;
if(bytes < SKINNY_MESSAGE_FIELD_SIZE) {
/* We have nothing yet, get length header field */
......@@ -160,7 +160,7 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req)
status = switch_socket_recv(listener->sock, ptr, &mlen);
if (!globals.running || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) {
if (!listener_is_ready(listener) || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Socket break.\n");
return SWITCH_STATUS_FALSE;
}
......@@ -536,7 +536,6 @@ error:
return SWITCH_STATUS_FALSE;
done:
switch_core_session_rwunlock(nsession);
*session = nsession;
return SWITCH_STATUS_SUCCESS;
}
......@@ -2273,3 +2272,14 @@ switch_status_t skinny_perform_send_reply(listener_t *listener, const char *file
return SWITCH_STATUS_SUCCESS;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
......@@ -742,3 +742,14 @@ switch_status_t send_reset(listener_t *listener,
#endif /* _SKINNY_PROTOCOL_H */
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
......@@ -190,3 +190,14 @@ struct skinny_table SKINNY_DEVICE_RESET_TYPES[] = {
SKINNY_DECLARE_ID2STR(skinny_device_reset_type2str, SKINNY_DEVICE_RESET_TYPES, "DeviceResetTypeUnknown")
SKINNY_DECLARE_STR2ID(skinny_str2device_reset_type, SKINNY_DEVICE_RESET_TYPES, -1)
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
......@@ -235,3 +235,14 @@ uint32_t skinny_str2device_reset_type(const char *str);
#endif /* _SKINNY_TABLES_H */
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论