Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
5b65045d
提交
5b65045d
authored
11月 21, 2011
作者:
Tamas Cseke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix connection leaking
上级
f2cf68bf
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
17 行增加
和
14 行删除
+17
-14
mod_mongo.cpp
src/mod/applications/mod_mongo/mod_mongo.cpp
+4
-4
mod_mongo.h
src/mod/applications/mod_mongo/mod_mongo.h
+1
-1
mongo_conn.cpp
src/mod/applications/mod_mongo/mongo_conn.cpp
+12
-9
没有找到文件。
src/mod/applications/mod_mongo/mod_mongo.cpp
浏览文件 @
5b65045d
...
...
@@ -49,7 +49,7 @@ SWITCH_STANDARD_API(mongo_mapreduce_function)
conn
=
mongo_connection_pool_get
(
globals
.
conn_pool
);
if
(
conn
)
{
conn
->
runCommand
(
conn
->
nsGetDB
(
ns
),
cmd
.
done
(),
out
);
mongo_connection_pool_put
(
globals
.
conn_pool
,
conn
);
mongo_connection_pool_put
(
globals
.
conn_pool
,
conn
,
SWITCH_FALSE
);
stream
->
write_function
(
stream
,
"-OK
\n
%s
\n
"
,
out
.
toString
().
c_str
());
}
else
{
...
...
@@ -57,7 +57,7 @@ SWITCH_STANDARD_API(mongo_mapreduce_function)
}
}
catch
(
DBException
&
e
)
{
if
(
conn
)
{
mongo_connection_
destroy
(
&
conn
);
mongo_connection_
pool_put
(
globals
.
conn_pool
,
conn
,
SWITCH_TRUE
);
}
stream
->
write_function
(
stream
,
"-ERR
\n
%s
\n
"
,
e
.
toString
().
c_str
());
}
...
...
@@ -97,7 +97,7 @@ SWITCH_STANDARD_API(mongo_find_one_function)
conn
=
mongo_connection_pool_get
(
globals
.
conn_pool
);
if
(
conn
)
{
BSONObj
res
=
conn
->
findOne
(
ns
,
Query
(
query
),
&
fields
);
mongo_connection_pool_put
(
globals
.
conn_pool
,
conn
);
mongo_connection_pool_put
(
globals
.
conn_pool
,
conn
,
SWITCH_FALSE
);
stream
->
write_function
(
stream
,
"-OK
\n
%s
\n
"
,
res
.
toString
().
c_str
());
}
else
{
...
...
@@ -105,7 +105,7 @@ SWITCH_STANDARD_API(mongo_find_one_function)
}
}
catch
(
DBException
&
e
)
{
if
(
conn
)
{
mongo_connection_
destroy
(
&
conn
);
mongo_connection_
pool_put
(
globals
.
conn_pool
,
conn
,
SWITCH_TRUE
);
}
stream
->
write_function
(
stream
,
"-ERR
\n
%s
\n
"
,
e
.
toString
().
c_str
());
}
...
...
src/mod/applications/mod_mongo/mod_mongo.h
浏览文件 @
5b65045d
...
...
@@ -30,7 +30,7 @@ void mongo_connection_pool_destroy(mongo_connection_pool_t **conn_pool);
DBClientBase
*
mongo_connection_pool_get
(
mongo_connection_pool_t
*
conn_pool
);
switch_status_t
mongo_connection_pool_put
(
mongo_connection_pool_t
*
conn_pool
,
DBClientBase
*
conn
);
switch_status_t
mongo_connection_pool_put
(
mongo_connection_pool_t
*
conn_pool
,
DBClientBase
*
conn
,
switch_bool_t
destroy
);
#endif
...
...
src/mod/applications/mod_mongo/mongo_conn.cpp
浏览文件 @
5b65045d
...
...
@@ -15,23 +15,27 @@ switch_status_t mongo_connection_create(DBClientBase **connection, const char *c
DBClientBase
*
conn
=
NULL
;
string
conn_string
(
conn_str
),
err_msg
;
ConnectionString
cs
=
ConnectionString
::
parse
(
conn_string
,
err_msg
);
switch_status_t
status
=
SWITCH_STATUS_FALSE
;
if
(
!
cs
.
isValid
())
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Can't parse url: %s
\n
"
,
err_msg
.
c_str
());
return
SWITCH_STATUS_GENERR
;
return
status
;
}
try
{
conn
=
cs
.
connect
(
err_msg
);
}
catch
(
DBException
&
e
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Can't connect to mongo [%s]: %s
\n
"
,
conn_str
,
err_msg
.
c_str
());
return
SWITCH_STATUS_GENERR
;
return
status
;
}
*
connection
=
conn
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Connected to mongo [%s]
\n
"
,
conn_str
);
if
(
conn
)
{
*
connection
=
conn
;
status
=
SWITCH_STATUS_SUCCESS
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Connected to mongo [%s]
\n
"
,
conn_str
);
}
return
SWITCH_STATUS_SUCCESS
;
return
status
;
}
void
mongo_connection_destroy
(
DBClientBase
**
conn
)
...
...
@@ -75,7 +79,7 @@ switch_status_t mongo_connection_pool_create(mongo_connection_pool_t **conn_pool
for
(
cpool
->
size
=
0
;
cpool
->
size
<
min_connections
;
cpool
->
size
++
)
{
if
(
mongo_connection_create
(
&
conn
,
conn_str
)
==
SWITCH_STATUS_SUCCESS
)
{
mongo_connection_pool_put
(
cpool
,
conn
);
mongo_connection_pool_put
(
cpool
,
conn
,
SWITCH_FALSE
);
}
else
{
break
;
}
...
...
@@ -89,7 +93,6 @@ switch_status_t mongo_connection_pool_create(mongo_connection_pool_t **conn_pool
switch_core_destroy_memory_pool
(
&
pool
);
}
return
status
;
}
...
...
@@ -137,7 +140,7 @@ DBClientBase *mongo_connection_pool_get(mongo_connection_pool_t *conn_pool)
return
conn
;
}
switch_status_t
mongo_connection_pool_put
(
mongo_connection_pool_t
*
conn_pool
,
DBClientBase
*
conn
)
switch_status_t
mongo_connection_pool_put
(
mongo_connection_pool_t
*
conn_pool
,
DBClientBase
*
conn
,
switch_bool_t
destroy
)
{
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
...
...
@@ -145,7 +148,7 @@ switch_status_t mongo_connection_pool_put(mongo_connection_pool_t *conn_pool, DB
switch_assert
(
conn
!=
NULL
);
switch_mutex_lock
(
conn_pool
->
mutex
);
if
(
conn_pool
->
size
>
conn_pool
->
max_connections
)
{
if
(
destroy
||
conn_pool
->
size
>
conn_pool
->
max_connections
)
{
#ifdef MONGO_POOL_DEBUG
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"POOL: Destroy connection %p
\n
"
,
conn
);
#endif
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论