Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
7d7eaee9
提交
7d7eaee9
authored
10月 08, 2012
作者:
Eliot Gable
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Switch to Poll instead of Select.
上级
dc1477e5
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
22 行删除
+30
-22
switch_pgsql.c
src/switch_pgsql.c
+30
-22
没有找到文件。
src/switch_pgsql.c
浏览文件 @
7d7eaee9
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#ifdef SWITCH_HAVE_PGSQL
#ifdef SWITCH_HAVE_PGSQL
#include <libpq-fe.h>
#include <libpq-fe.h>
#include <poll.h>
struct
switch_pgsql_handle
{
struct
switch_pgsql_handle
{
...
@@ -168,8 +169,8 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
...
@@ -168,8 +169,8 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
switch_time_t
ctime
;
switch_time_t
ctime
;
unsigned
int
usec
=
msec
*
1000
;
unsigned
int
usec
=
msec
*
1000
;
char
*
err_str
;
char
*
err_str
;
fd_set
pgset
;
struct
pollfd
fds
[
2
]
=
{
{
0
}
}
;
struct
timeval
timeout
;
int
poll_res
=
0
;
if
(
!
handle
)
{
if
(
!
handle
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"**BUG** Null handle passed to switch_pgsql_next_result.
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"**BUG** Null handle passed to switch_pgsql_next_result.
\n
"
);
...
@@ -183,30 +184,37 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
...
@@ -183,30 +184,37 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
/* Wait for a result to become available, up to msec milliseconds */
/* Wait for a result to become available, up to msec milliseconds */
start
=
switch_time_now
();
start
=
switch_time_now
();
while
((
ctime
=
switch_time_now
())
-
start
<=
usec
)
{
while
((
ctime
=
switch_micro_time_now
())
-
start
<=
usec
)
{
FD_ZERO
(
&
pgset
);
int
wait_time
=
(
usec
-
(
ctime
-
start
))
/
1000
;
FD_SET
(
handle
->
sock
,
&
pgset
);
fds
[
0
].
fd
=
handle
->
sock
;
fds
[
0
].
events
|=
POLLIN
;
fds
[
0
].
events
|=
POLLERR
;
timeout
.
tv_sec
=
0
;
timeout
.
tv_usec
=
500
;
/* Wait for the PostgreSQL socket to be ready for data reads. */
/* Wait for the PostgreSQL socket to be ready for data reads. */
if
(
select
(
FD_SETSIZE
,
&
pgset
,
NULL
,
NULL
,
&
timeout
)
>
0
)
{
if
((
poll_res
=
poll
(
&
fds
[
0
],
1
,
wait_time
))
>
-
1
)
{
/* Then try to consume any input waiting. */
if
(
fds
[
0
].
revents
&
POLLIN
)
{
if
(
PQconsumeInput
(
handle
->
con
))
{
/* Then try to consume any input waiting. */
/* And check to see if we have a full result ready for reading */
if
(
PQconsumeInput
(
handle
->
con
))
{
if
(
!
PQisBusy
(
handle
->
con
))
{
/* And check to see if we have a full result ready for reading */
/* If we can pull a full result without blocking, then break this loop */
if
(
!
PQisBusy
(
handle
->
con
))
{
break
;
/* If we can pull a full result without blocking, then break this loop */
break
;
}
}
else
{
/* If we had an error trying to consume input, report it and cancel the query. */
err_str
=
switch_pgsql_handle_get_error
(
handle
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"An error occurred trying to consume input for query (%s): %s
\n
"
,
handle
->
sql
,
err_str
);
switch_safe_free
(
err_str
);
switch_pgsql_cancel
(
handle
);
goto
error
;
}
}
}
else
{
}
else
if
(
fds
[
0
].
revents
&
POLLERR
)
{
/* If we had an error trying to consume input, report it and cancel the query. */
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"Poll error trying to read PGSQL socket for query (%s)
\n
"
,
handle
->
sql
);
err_str
=
switch_pgsql_handle_get_error
(
handle
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"An error occurred trying to consume input for query (%s): %s
\n
"
,
handle
->
sql
,
err_str
);
switch_safe_free
(
err_str
);
switch_pgsql_cancel
(
handle
);
goto
error
;
goto
error
;
}
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"Poll failed trying to read PGSQL socket for query (%s)
\n
"
,
handle
->
sql
);
goto
error
;
}
}
}
}
...
@@ -318,7 +326,7 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_finish_results_real(const cha
...
@@ -318,7 +326,7 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_finish_results_real(const cha
#endif
#endif
}
}
#ifdef SWITCH_HAVE_PG
#ifdef SWITCH_HAVE_PG
SQL
static
int
db_is_up
(
switch_pgsql_handle_t
*
handle
)
static
int
db_is_up
(
switch_pgsql_handle_t
*
handle
)
{
{
int
ret
=
0
;
int
ret
=
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论