Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
8915c6a9
提交
8915c6a9
authored
7月 24, 2010
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reduce memory usage
上级
7d554c11
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
52 行增加
和
37 行删除
+52
-37
mod_fifo.c
src/mod/applications/mod_fifo/mod_fifo.c
+27
-23
mod_event_socket.c
src/mod/event_handlers/mod_event_socket/mod_event_socket.c
+25
-14
没有找到文件。
src/mod/applications/mod_fifo/mod_fifo.c
浏览文件 @
8915c6a9
...
@@ -562,7 +562,7 @@ static struct {
...
@@ -562,7 +562,7 @@ static struct {
switch_event_node_t
*
node
;
switch_event_node_t
*
node
;
char
hostname
[
256
];
char
hostname
[
256
];
char
*
dbname
;
char
*
dbname
;
char
*
odbc_dsn
;
char
odbc_dsn
[
1024
]
;
char
*
odbc_user
;
char
*
odbc_user
;
char
*
odbc_pass
;
char
*
odbc_pass
;
int
node_thread_running
;
int
node_thread_running
;
...
@@ -781,6 +781,7 @@ static fifo_node_t *create_node(const char *name, uint32_t importance, switch_mu
...
@@ -781,6 +781,7 @@ static fifo_node_t *create_node(const char *name, uint32_t importance, switch_mu
return
NULL
;
return
NULL
;
}
}
switch_core_new_memory_pool
(
&
pool
);
switch_core_new_memory_pool
(
&
pool
);
node
=
switch_core_alloc
(
pool
,
sizeof
(
*
node
));
node
=
switch_core_alloc
(
pool
,
sizeof
(
*
node
));
...
@@ -788,7 +789,7 @@ static fifo_node_t *create_node(const char *name, uint32_t importance, switch_mu
...
@@ -788,7 +789,7 @@ static fifo_node_t *create_node(const char *name, uint32_t importance, switch_mu
node
->
outbound_strategy
=
default_strategy
;
node
->
outbound_strategy
=
default_strategy
;
node
->
name
=
switch_core_strdup
(
node
->
pool
,
name
);
node
->
name
=
switch_core_strdup
(
node
->
pool
,
name
);
for
(
x
=
0
;
x
<
MAX_PRI
;
x
++
)
{
for
(
x
=
0
;
x
<
MAX_PRI
;
x
++
)
{
fifo_queue_create
(
&
node
->
fifo_list
[
x
],
SWITCH_CORE_QUEUE_LEN
,
node
->
pool
);
fifo_queue_create
(
&
node
->
fifo_list
[
x
],
1000
,
node
->
pool
);
switch_assert
(
node
->
fifo_list
[
x
]);
switch_assert
(
node
->
fifo_list
[
x
]);
}
}
...
@@ -844,7 +845,7 @@ struct call_helper {
...
@@ -844,7 +845,7 @@ struct call_helper {
switch_memory_pool_t
*
pool
;
switch_memory_pool_t
*
pool
;
};
};
#define MAX_ROWS 2
048
#define MAX_ROWS 2
5
struct
callback_helper
{
struct
callback_helper
{
int
need
;
int
need
;
switch_memory_pool_t
*
pool
;
switch_memory_pool_t
*
pool
;
...
@@ -1138,16 +1139,16 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void
...
@@ -1138,16 +1139,16 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void
struct
call_helper
*
rows
[
MAX_ROWS
]
=
{
0
};
struct
call_helper
*
rows
[
MAX_ROWS
]
=
{
0
};
int
rowcount
=
0
;
int
rowcount
=
0
;
switch_memory_pool_t
*
pool
;
switch_memory_pool_t
*
pool
;
if
(
!
globals
.
running
)
return
NULL
;
switch_uuid_get
(
&
uuid
);
switch_uuid_format
(
uuid_str
,
&
uuid
);
switch_mutex_lock
(
globals
.
mutex
);
switch_mutex_lock
(
globals
.
mutex
);
globals
.
threads
++
;
globals
.
threads
++
;
switch_mutex_unlock
(
globals
.
mutex
);
switch_mutex_unlock
(
globals
.
mutex
);
if
(
!
globals
.
running
)
goto
dpool
;
switch_uuid_get
(
&
uuid
);
switch_uuid_format
(
uuid_str
,
&
uuid
);
if
(
!
cbh
->
rowcount
)
{
if
(
!
cbh
->
rowcount
)
{
goto
end
;
goto
end
;
}
}
...
@@ -1451,6 +1452,8 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void
...
@@ -1451,6 +1452,8 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void
switch_event_destroy
(
&
pop_dup
);
switch_event_destroy
(
&
pop_dup
);
}
}
dpool:
pool
=
cbh
->
pool
;
pool
=
cbh
->
pool
;
switch_core_destroy_memory_pool
(
&
pool
);
switch_core_destroy_memory_pool
(
&
pool
);
...
@@ -1971,7 +1974,7 @@ SWITCH_STANDARD_API(fifo_add_outbound_function)
...
@@ -1971,7 +1974,7 @@ SWITCH_STANDARD_API(fifo_add_outbound_function)
}
}
static
void
dec_use_count
(
switch_core_session_t
*
session
)
static
void
dec_use_count
(
switch_core_session_t
*
session
,
switch_bool_t
send_event
)
{
{
char
*
sql
;
char
*
sql
;
const
char
*
outbound_id
;
const
char
*
outbound_id
;
...
@@ -1991,12 +1994,14 @@ static void dec_use_count(switch_core_session_t *session)
...
@@ -1991,12 +1994,14 @@ static void dec_use_count(switch_core_session_t *session)
fifo_execute_sql
(
sql
,
globals
.
sql_mutex
);
fifo_execute_sql
(
sql
,
globals
.
sql_mutex
);
switch_safe_free
(
sql
);
switch_safe_free
(
sql
);
}
}
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
FIFO_EVENT
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
send_event
)
{
switch_channel_event_set_data
(
channel
,
event
);
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
FIFO_EVENT
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"FIFO-Name"
,
MANUAL_QUEUE_NAME
);
switch_channel_event_set_data
(
channel
,
event
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"FIFO-Action"
,
"bridge-consumer-stop"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"FIFO-Name"
,
MANUAL_QUEUE_NAME
);
switch_event_fire
(
&
event
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"FIFO-Action"
,
"bridge-consumer-stop"
);
switch_event_fire
(
&
event
);
}
}
}
}
}
...
@@ -2006,7 +2011,7 @@ static switch_status_t hanguphook(switch_core_session_t *session)
...
@@ -2006,7 +2011,7 @@ static switch_status_t hanguphook(switch_core_session_t *session)
switch_channel_state_t
state
=
switch_channel_get_state
(
channel
);
switch_channel_state_t
state
=
switch_channel_get_state
(
channel
);
if
(
state
==
CS_HANGUP
)
{
if
(
state
==
CS_HANGUP
)
{
dec_use_count
(
session
);
dec_use_count
(
session
,
SWITCH_TRUE
);
switch_core_event_hook_remove_state_change
(
session
,
hanguphook
);
switch_core_event_hook_remove_state_change
(
session
,
hanguphook
);
}
}
...
@@ -2142,7 +2147,7 @@ SWITCH_STANDARD_APP(fifo_function)
...
@@ -2142,7 +2147,7 @@ SWITCH_STANDARD_APP(fifo_function)
const
char
*
serviced_uuid
=
NULL
;
const
char
*
serviced_uuid
=
NULL
;
if
(
switch_core_event_hook_remove_receive_message
(
session
,
messagehook
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
switch_core_event_hook_remove_receive_message
(
session
,
messagehook
)
==
SWITCH_STATUS_SUCCESS
)
{
dec_use_count
(
session
);
dec_use_count
(
session
,
SWITCH_FALSE
);
switch_core_event_hook_remove_state_change
(
session
,
hanguphook
);
switch_core_event_hook_remove_state_change
(
session
,
hanguphook
);
}
}
...
@@ -3522,7 +3527,7 @@ void dump_hash(switch_hash_t *hash, switch_stream_handle_t *stream)
...
@@ -3522,7 +3527,7 @@ void dump_hash(switch_hash_t *hash, switch_stream_handle_t *stream)
switch_mutex_lock
(
globals
.
mutex
);
switch_mutex_lock
(
globals
.
mutex
);
for
(
hi
=
switch_hash_first
(
NULL
,
hash
);
hi
;
hi
=
switch_hash_next
(
hi
))
{
for
(
hi
=
switch_hash_first
(
NULL
,
hash
);
hi
;
hi
=
switch_hash_next
(
hi
))
{
switch_hash_this
(
hi
,
&
var
,
NULL
,
&
val
);
switch_hash_this
(
hi
,
&
var
,
NULL
,
&
val
);
stream
->
write_function
(
stream
,
" %s
: %s
\n
"
,
(
char
*
)
var
,
(
char
*
)
val
);
stream
->
write_function
(
stream
,
" %s
\n
"
,
(
char
*
)
var
);
}
}
switch_mutex_unlock
(
globals
.
mutex
);
switch_mutex_unlock
(
globals
.
mutex
);
}
}
...
@@ -3607,6 +3612,7 @@ SWITCH_STANDARD_API(fifo_api_function)
...
@@ -3607,6 +3612,7 @@ SWITCH_STANDARD_API(fifo_api_function)
if
(
!
strcasecmp
(
argv
[
0
],
"reparse"
))
{
if
(
!
strcasecmp
(
argv
[
0
],
"reparse"
))
{
load_config
(
1
,
argv
[
1
]
&&
!
strcasecmp
(
argv
[
1
],
"del_all"
));
load_config
(
1
,
argv
[
1
]
&&
!
strcasecmp
(
argv
[
1
],
"del_all"
));
stream
->
write_function
(
stream
,
"+OK
\n
"
);
goto
done
;
goto
done
;
}
}
...
@@ -3814,7 +3820,7 @@ static switch_status_t load_config(int reload, int del_all)
...
@@ -3814,7 +3820,7 @@ static switch_status_t load_config(int reload, int del_all)
if
(
!
strcasecmp
(
var
,
"odbc-dsn"
)
&&
!
zstr
(
val
))
{
if
(
!
strcasecmp
(
var
,
"odbc-dsn"
)
&&
!
zstr
(
val
))
{
if
(
switch_odbc_available
())
{
if
(
switch_odbc_available
())
{
globals
.
odbc_dsn
=
switch_core_strdup
(
globals
.
pool
,
val
);
switch_set_string
(
globals
.
odbc_dsn
,
val
);
if
((
globals
.
odbc_user
=
strchr
(
globals
.
odbc_dsn
,
':'
)))
{
if
((
globals
.
odbc_user
=
strchr
(
globals
.
odbc_dsn
,
':'
)))
{
*
globals
.
odbc_user
++
=
'\0'
;
*
globals
.
odbc_user
++
=
'\0'
;
if
((
globals
.
odbc_pass
=
strchr
(
globals
.
odbc_user
,
':'
)))
{
if
((
globals
.
odbc_pass
=
strchr
(
globals
.
odbc_user
,
':'
)))
{
...
@@ -4247,7 +4253,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load)
...
@@ -4247,7 +4253,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load)
return
SWITCH_STATUS_GENERR
;
return
SWITCH_STATUS_GENERR
;
}
}
switch_core_new_memory_pool
(
&
globals
.
pool
)
;
globals
.
pool
=
pool
;
switch_core_hash_init
(
&
globals
.
fifo_hash
,
globals
.
pool
);
switch_core_hash_init
(
&
globals
.
fifo_hash
,
globals
.
pool
);
switch_core_hash_init
(
&
globals
.
caller_orig_hash
,
globals
.
pool
);
switch_core_hash_init
(
&
globals
.
caller_orig_hash
,
globals
.
pool
);
...
@@ -4266,7 +4272,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load)
...
@@ -4266,7 +4272,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load)
switch_event_unbind
(
&
globals
.
node
);
switch_event_unbind
(
&
globals
.
node
);
switch_event_free_subclass
(
FIFO_EVENT
);
switch_event_free_subclass
(
FIFO_EVENT
);
switch_core_hash_destroy
(
&
globals
.
fifo_hash
);
switch_core_hash_destroy
(
&
globals
.
fifo_hash
);
switch_core_destroy_memory_pool
(
&
globals
.
pool
);
return
status
;
return
status
;
}
}
...
@@ -4300,7 +4305,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown)
...
@@ -4300,7 +4305,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown)
void
*
val
;
void
*
val
;
switch_event_t
*
pop
=
NULL
;
switch_event_t
*
pop
=
NULL
;
fifo_node_t
*
node
;
fifo_node_t
*
node
;
switch_memory_pool_t
*
pool
=
globals
.
pool
;
switch_mutex_t
*
mutex
=
globals
.
mutex
;
switch_mutex_t
*
mutex
=
globals
.
mutex
;
switch_event_unbind
(
&
globals
.
node
);
switch_event_unbind
(
&
globals
.
node
);
...
@@ -4340,7 +4344,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown)
...
@@ -4340,7 +4344,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown)
switch_core_hash_destroy
(
&
globals
.
fifo_hash
);
switch_core_hash_destroy
(
&
globals
.
fifo_hash
);
memset
(
&
globals
,
0
,
sizeof
(
globals
));
memset
(
&
globals
,
0
,
sizeof
(
globals
));
switch_mutex_unlock
(
mutex
);
switch_mutex_unlock
(
mutex
);
switch_core_destroy_memory_pool
(
&
pool
);
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
...
...
src/mod/event_handlers/mod_event_socket/mod_event_socket.c
浏览文件 @
8915c6a9
...
@@ -31,7 +31,8 @@
...
@@ -31,7 +31,8 @@
*/
*/
#include <switch.h>
#include <switch.h>
#define CMD_BUFLEN 1024 * 1000
#define CMD_BUFLEN 1024 * 1000
#define MAX_QUEUE_LEN 5000
#define MAX_MISSED 200
SWITCH_MODULE_LOAD_FUNCTION
(
mod_event_socket_load
);
SWITCH_MODULE_LOAD_FUNCTION
(
mod_event_socket_load
);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_event_socket_shutdown
);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_event_socket_shutdown
);
SWITCH_MODULE_RUNTIME_FUNCTION
(
mod_event_socket_runtime
);
SWITCH_MODULE_RUNTIME_FUNCTION
(
mod_event_socket_runtime
);
...
@@ -142,6 +143,7 @@ static const char *format2str(event_format_t format)
...
@@ -142,6 +143,7 @@ static const char *format2str(event_format_t format)
}
}
static
void
remove_listener
(
listener_t
*
listener
);
static
void
remove_listener
(
listener_t
*
listener
);
static
void
kill_listener
(
listener_t
*
l
);
static
void
kill_all_listeners
(
void
);
static
void
kill_all_listeners
(
void
);
static
uint32_t
next_id
(
void
)
static
uint32_t
next_id
(
void
)
...
@@ -181,7 +183,9 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l
...
@@ -181,7 +183,9 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l
}
}
}
else
{
}
else
{
switch_log_node_free
(
&
dnode
);
switch_log_node_free
(
&
dnode
);
l
->
lost_logs
++
;
if
(
++
l
->
lost_logs
>
MAX_MISSED
)
{
kill_listener
(
l
);
}
}
}
}
}
}
}
...
@@ -374,7 +378,9 @@ static void event_handler(switch_event_t *event)
...
@@ -374,7 +378,9 @@ static void event_handler(switch_event_t *event)
}
}
}
}
}
else
{
}
else
{
l
->
lost_events
++
;
if
(
++
l
->
lost_events
>
MAX_MISSED
)
{
kill_listener
(
l
);
}
switch_event_destroy
(
&
clone
);
switch_event_destroy
(
&
clone
);
}
}
}
else
{
}
else
{
...
@@ -454,8 +460,8 @@ SWITCH_STANDARD_APP(socket_function)
...
@@ -454,8 +460,8 @@ SWITCH_STANDARD_APP(socket_function)
}
}
switch_thread_rwlock_create
(
&
listener
->
rwlock
,
switch_core_session_get_pool
(
session
));
switch_thread_rwlock_create
(
&
listener
->
rwlock
,
switch_core_session_get_pool
(
session
));
switch_queue_create
(
&
listener
->
event_queue
,
SWITCH_CORE
_QUEUE_LEN
,
switch_core_session_get_pool
(
session
));
switch_queue_create
(
&
listener
->
event_queue
,
MAX
_QUEUE_LEN
,
switch_core_session_get_pool
(
session
));
switch_queue_create
(
&
listener
->
log_queue
,
SWITCH_CORE
_QUEUE_LEN
,
switch_core_session_get_pool
(
session
));
switch_queue_create
(
&
listener
->
log_queue
,
MAX
_QUEUE_LEN
,
switch_core_session_get_pool
(
session
));
listener
->
sock
=
new_sock
;
listener
->
sock
=
new_sock
;
listener
->
pool
=
switch_core_session_get_pool
(
session
);
listener
->
pool
=
switch_core_session_get_pool
(
session
);
...
@@ -573,6 +579,15 @@ static void remove_listener(listener_t *listener)
...
@@ -573,6 +579,15 @@ static void remove_listener(listener_t *listener)
switch_mutex_unlock
(
globals
.
listener_mutex
);
switch_mutex_unlock
(
globals
.
listener_mutex
);
}
}
static
void
kill_listener
(
listener_t
*
l
)
{
switch_clear_flag
(
l
,
LFLAG_RUNNING
);
if
(
l
->
sock
)
{
switch_socket_shutdown
(
l
->
sock
,
SWITCH_SHUTDOWN_READWRITE
);
switch_socket_close
(
l
->
sock
);
}
}
static
void
kill_all_listeners
(
void
)
static
void
kill_all_listeners
(
void
)
{
{
...
@@ -580,11 +595,7 @@ static void kill_all_listeners(void)
...
@@ -580,11 +595,7 @@ static void kill_all_listeners(void)
switch_mutex_lock
(
globals
.
listener_mutex
);
switch_mutex_lock
(
globals
.
listener_mutex
);
for
(
l
=
listen_list
.
listeners
;
l
;
l
=
l
->
next
)
{
for
(
l
=
listen_list
.
listeners
;
l
;
l
=
l
->
next
)
{
switch_clear_flag
(
l
,
LFLAG_RUNNING
);
kill_listener
(
l
);
if
(
l
->
sock
)
{
switch_socket_shutdown
(
l
->
sock
,
SWITCH_SHUTDOWN_READWRITE
);
switch_socket_close
(
l
->
sock
);
}
}
}
switch_mutex_unlock
(
globals
.
listener_mutex
);
switch_mutex_unlock
(
globals
.
listener_mutex
);
}
}
...
@@ -787,8 +798,8 @@ SWITCH_STANDARD_API(event_sink_function)
...
@@ -787,8 +798,8 @@ SWITCH_STANDARD_API(event_sink_function)
switch_set_flag
(
listener
,
LFLAG_AUTHED
);
switch_set_flag
(
listener
,
LFLAG_AUTHED
);
switch_set_flag
(
listener
,
LFLAG_STATEFUL
);
switch_set_flag
(
listener
,
LFLAG_STATEFUL
);
switch_set_flag
(
listener
,
LFLAG_ALLOW_LOG
);
switch_set_flag
(
listener
,
LFLAG_ALLOW_LOG
);
switch_queue_create
(
&
listener
->
event_queue
,
SWITCH_CORE
_QUEUE_LEN
,
listener
->
pool
);
switch_queue_create
(
&
listener
->
event_queue
,
MAX
_QUEUE_LEN
,
listener
->
pool
);
switch_queue_create
(
&
listener
->
log_queue
,
SWITCH_CORE
_QUEUE_LEN
,
listener
->
pool
);
switch_queue_create
(
&
listener
->
log_queue
,
MAX
_QUEUE_LEN
,
listener
->
pool
);
if
(
loglevel
)
{
if
(
loglevel
)
{
switch_log_level_t
ltype
=
switch_log_str2level
(
loglevel
);
switch_log_level_t
ltype
=
switch_log_str2level
(
loglevel
);
...
@@ -2716,8 +2727,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
...
@@ -2716,8 +2727,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
}
}
switch_thread_rwlock_create
(
&
listener
->
rwlock
,
listener_pool
);
switch_thread_rwlock_create
(
&
listener
->
rwlock
,
listener_pool
);
switch_queue_create
(
&
listener
->
event_queue
,
SWITCH_CORE
_QUEUE_LEN
,
listener_pool
);
switch_queue_create
(
&
listener
->
event_queue
,
MAX
_QUEUE_LEN
,
listener_pool
);
switch_queue_create
(
&
listener
->
log_queue
,
SWITCH_CORE
_QUEUE_LEN
,
listener_pool
);
switch_queue_create
(
&
listener
->
log_queue
,
MAX
_QUEUE_LEN
,
listener_pool
);
listener
->
sock
=
inbound_socket
;
listener
->
sock
=
inbound_socket
;
listener
->
pool
=
listener_pool
;
listener
->
pool
=
listener_pool
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论