Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
ascs
提交
28c1e371
A
ascs
项目概览
youngwolf
/
ascs
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
ascs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
28c1e371
编写于
12月 31, 2020
作者:
Y
youngwolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize unpackers.
上级
c4ed0dd5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
12 addition
and
13 deletion
+12
-13
include/ascs/ext/unpacker.h
include/ascs/ext/unpacker.h
+12
-13
未找到文件。
include/ascs/ext/unpacker.h
浏览文件 @
28c1e371
...
...
@@ -55,12 +55,8 @@ public:
unpacker
()
{
reset
();}
size_t
current_msg_length
()
const
{
return
cur_msg_len
;}
//current msg's total length, -1 means not available
bool
parse_msg
(
s
ize_t
bytes_transferred
,
s
td
::
list
<
std
::
pair
<
const
char
*
,
size_t
>>&
msg_can
)
bool
parse_msg
(
std
::
list
<
std
::
pair
<
const
char
*
,
size_t
>>&
msg_can
)
{
//length + msg
remain_len
+=
bytes_transferred
;
assert
(
remain_len
<=
ASCS_MSG_BUFFER_SIZE
);
auto
pnext
=
&*
std
::
begin
(
raw_buff
);
auto
unpack_ok
=
true
;
while
(
unpack_ok
)
//considering sticky package problem, we need a loop
...
...
@@ -102,8 +98,12 @@ public:
virtual
void
dump_left_data
()
const
{
unpacker_helper
::
dump_left_data
(
raw_buff
.
data
(),
cur_msg_len
,
remain_len
);}
virtual
bool
parse_msg
(
size_t
bytes_transferred
,
container_type
&
msg_can
)
{
//length + msg
remain_len
+=
bytes_transferred
;
assert
(
remain_len
<=
ASCS_MSG_BUFFER_SIZE
);
std
::
list
<
std
::
pair
<
const
char
*
,
size_t
>>
msg_pos_can
;
auto
unpack_ok
=
parse_msg
(
bytes_transferred
,
msg_pos_can
);
auto
unpack_ok
=
parse_msg
(
msg_pos_can
);
do_something_to_all
(
msg_pos_can
,
[
this
,
&
msg_can
](
decltype
(
msg_pos_can
.
front
())
item
)
{
if
(
item
.
second
>
ASCS_HEAD_LEN
)
//ignore heartbeat
{
...
...
@@ -144,7 +144,7 @@ public:
return
0
;
}
return
data_len
>=
cur_msg_len
?
0
:
asio
::
detail
::
default_max_transfer_size
;
return
data_len
>=
cur_msg_len
?
0
:
ASCS_MSG_BUFFER_SIZE
;
//read as many as possible except that we have already got an entire msg
}
...
...
@@ -316,12 +316,12 @@ public:
if
(
0
==
step
)
//want the head
{
assert
(
raw_buff
.
empty
());
return
asio
::
detail
::
default_max_transfer_size
;
return
ASCS_HEAD_LEN
;
}
else
if
(
1
==
step
)
//want the body
{
assert
(
!
raw_buff
.
empty
());
return
asio
::
detail
::
default_max_transfer_size
;
return
raw_buff
.
size
()
;
}
else
assert
(
false
);
...
...
@@ -377,8 +377,7 @@ public:
//a return value of 0 indicates that the read operation is complete. a non-zero value indicates the maximum number
//of bytes to be read on the next call to the stream's async_read_some function. ---asio::async_read
virtual
size_t
completion_condition
(
const
asio
::
error_code
&
ec
,
size_t
bytes_transferred
)
{
return
ec
||
bytes_transferred
==
raw_buff
.
size
()
?
0
:
asio
::
detail
::
default_max_transfer_size
;}
virtual
size_t
completion_condition
(
const
asio
::
error_code
&
ec
,
size_t
bytes_transferred
)
{
return
ec
||
bytes_transferred
==
raw_buff
.
size
()
?
0
:
_fixed_length
;}
//this is just to satisfy the compiler, it's not a real scatter-gather buffer,
//if you introduce a ring buffer, then you will have the chance to provide a real scatter-gather buffer.
...
...
@@ -433,7 +432,7 @@ public:
return
0
;
//invalid msg, stop reading
}
return
asio
::
detail
::
default_max_transfer_size
;
//read as many as possible
return
ASCS_MSG_BUFFER_SIZE
;
//read as many as possible
}
//like strstr, except support \0 in the middle of mem and sub_mem
...
...
@@ -537,7 +536,7 @@ public:
return
true
;
}
virtual
size_t
completion_condition
(
const
asio
::
error_code
&
ec
,
size_t
bytes_transferred
)
{
return
ec
||
bytes_transferred
>
0
?
0
:
asio
::
detail
::
default_max_transfer_size
;}
virtual
size_t
completion_condition
(
const
asio
::
error_code
&
ec
,
size_t
bytes_transferred
)
{
return
ec
||
bytes_transferred
>
0
?
0
:
ASCS_MSG_BUFFER_SIZE
;}
//this is just to satisfy the compiler, it's not a real scatter-gather buffer,
//if you introduce a ring buffer, then you will have the chance to provide a real scatter-gather buffer.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录