Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
e3698c20
提交
e3698c20
authored
3月 23, 2012
作者:
Stefan Knoblich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ftmod_misdn: Make sure misdn_read() doesn't loop forever and improve logging etc.
Signed-off-by:
Stefan Knoblich
<
stkn@openisdn.net
>
上级
ff4b3959
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
27 行增加
和
5 行删除
+27
-5
ftmod_misdn.c
libs/freetdm/src/ftmod/ftmod_misdn/ftmod_misdn.c
+27
-5
没有找到文件。
libs/freetdm/src/ftmod/ftmod_misdn/ftmod_misdn.c
浏览文件 @
e3698c20
...
...
@@ -76,6 +76,15 @@
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
#endif
#ifndef CLAMP
#define CLAMP(val,min,max) (MIN(max,MAX(min,val)))
#endif
typedef
enum
{
MISDN_CAPS_NONE
=
0
,
...
...
@@ -1208,6 +1217,7 @@ static FIO_READ_FUNCTION(misdn_read)
struct
mISDNhead
*
hh
=
(
struct
mISDNhead
*
)
rbuf
;
int
bytes
=
*
datalen
;
int
retval
;
int
maxretry
=
10
;
if
(
priv
->
state
==
MISDN_CHAN_STATE_CLOSED
)
{
ftdm_log_chan_msg
(
ftdmchan
,
FTDM_LOG_DEBUG
,
"mISDN ignoring read on closed channel
\n
"
);
...
...
@@ -1216,15 +1226,20 @@ static FIO_READ_FUNCTION(misdn_read)
return
FTDM_SUCCESS
;
}
/* nothing read yet */
*
datalen
=
0
;
/*
* try to read all messages, as long as we haven't received a PH_DATA_IND one
* we'll get a lot of "mISDN_send: error -12" message in dmesg otherwise
* (= b-channel receive queue overflowing)
*/
while
(
1
)
{
if
((
retval
=
recvfrom
(
ftdmchan
->
sockfd
,
rbuf
,
sizeof
(
rbuf
),
0
,
NULL
,
NULL
))
<
0
)
{
if
(
errno
==
EWOULDBLOCK
)
break
;
if
(
errno
==
EAGAIN
)
continue
;
while
(
maxretry
--
)
{
struct
sockaddr_mISDN
addr
;
socklen_t
addrlen
=
sizeof
(
addr
);
if
((
retval
=
recvfrom
(
ftdmchan
->
sockfd
,
rbuf
,
sizeof
(
rbuf
),
0
,
(
struct
sockaddr
*
)
&
addr
,
&
addrlen
))
<
0
)
{
if
(
errno
==
EWOULDBLOCK
||
errno
==
EAGAIN
)
break
;
ftdm_log_chan
(
ftdmchan
,
FTDM_LOG_ERROR
,
"mISDN failed to receive incoming message: %s
\n
"
,
strerror
(
errno
));
return
FTDM_FAIL
;
...
...
@@ -1236,9 +1251,12 @@ static FIO_READ_FUNCTION(misdn_read)
}
if
(
hh
->
prim
==
PH_DATA_IND
)
{
*
datalen
=
MIN
(
bytes
,
retval
-
MISDN_HEADER_LEN
);
*
datalen
=
CLAMP
(
retval
-
MISDN_HEADER_LEN
,
0
,
bytes
);
memcpy
(
data
,
rbuf
+
MISDN_HEADER_LEN
,
*
datalen
);
#ifdef MISDN_DEBUG_IO
ftdm_log_chan
(
ftdmchan
,
FTDM_LOG_DEBUG
,
"misdn_read() received '%s', id: %#x, with %d bytes from channel socket %d [dev.ch: %d.%d]
\n
"
,
misdn_event2str
(
hh
->
prim
),
hh
->
id
,
retval
-
MISDN_HEADER_LEN
,
ftdmchan
->
sockfd
,
addr
.
dev
,
addr
.
channel
);
if
(
*
datalen
>
0
)
{
char
hbuf
[
MAX_DATA_MEM
]
=
{
0
};
print_hex_bytes
(
data
,
*
datalen
,
hbuf
,
sizeof
(
hbuf
));
...
...
@@ -1248,6 +1266,10 @@ static FIO_READ_FUNCTION(misdn_read)
return
FTDM_SUCCESS
;
}
else
{
*
datalen
=
0
;
#ifdef MISDN_DEBUG_IO
ftdm_log_chan
(
ftdmchan
,
FTDM_LOG_DEBUG
,
"misdn_read() received '%s', id: %#x, with %d bytes from channel socket %d [dev.ch: %d.%d]
\n
"
,
misdn_event2str
(
hh
->
prim
),
hh
->
id
,
retval
-
MISDN_HEADER_LEN
,
ftdmchan
->
sockfd
,
addr
.
dev
,
addr
.
channel
);
#endif
/* event */
misdn_handle_incoming
(
ftdmchan
,
rbuf
,
retval
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论