Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
ascs
提交
2158fe21
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,发现更多精彩内容 >>
提交
2158fe21
编写于
12月 31, 2020
作者:
Y
youngwolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Continue last commit.
上级
1865da17
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
22 addition
and
6 deletion
+22
-6
examples/echo_client/echo_client.cpp
examples/echo_client/echo_client.cpp
+9
-1
examples/echo_server/echo_server.cpp
examples/echo_server/echo_server.cpp
+9
-1
include/ascs/ext/unpacker.h
include/ascs/ext/unpacker.h
+4
-4
未找到文件。
examples/echo_client/echo_client.cpp
浏览文件 @
2158fe21
...
...
@@ -25,7 +25,15 @@
//2-fixed length packer and unpacker
//3-prefix and/or suffix packer and unpacker
#if 1 == PACKER_UNPACKER_TYPE
#if 0 == PACKER_UNPACKER_TYPE
#define ASCS_HUGE_MSG
#define ASCS_MSG_BUFFER_SIZE 1000000
#define ASCS_MAX_SEND_BUF (10 * ASCS_MSG_BUFFER_SIZE)
#define ASCS_MAX_RECV_BUF (10 * ASCS_MSG_BUFFER_SIZE)
#define ASCS_DEFAULT_UNPACKER flexible_unpacker
//this unpacker only pre-allocated a buffer of 4000 bytes, but it can parse messages up to ST_ASIO_MSG_BUFFER_SIZE (here is 1000000) bytes,
//it works as the default unpacker for messages <= 4000, otherwise, it works as non_copy_unpacker
#elif
1
==
PACKER_UNPACKER_TYPE
#define ASCS_DEFAULT_PACKER packer2<unique_buffer<std::string>, std::string>
#define ASCS_DEFAULT_UNPACKER unpacker2<unique_buffer<std::string>>
#elif 2 == PACKER_UNPACKER_TYPE
...
...
examples/echo_server/echo_server.cpp
浏览文件 @
2158fe21
...
...
@@ -25,7 +25,15 @@
//2-fixed length packer and unpacker
//3-prefix and/or suffix packer and unpacker
#if 1 == PACKER_UNPACKER_TYPE
#if 0 == PACKER_UNPACKER_TYPE
#define ASCS_HUGE_MSG
#define ASCS_MSG_BUFFER_SIZE 1000000
#define ASCS_MAX_SEND_BUF (10 * ASCS_MSG_BUFFER_SIZE)
#define ASCS_MAX_RECV_BUF (10 * ASCS_MSG_BUFFER_SIZE)
#define ASCS_DEFAULT_UNPACKER flexible_unpacker
//this unpacker only pre-allocated a buffer of 4000 bytes, but it can parse messages up to ST_ASIO_MSG_BUFFER_SIZE (here is 1000000) bytes,
//it works as the default unpacker for messages <= 4000, otherwise, it works as non_copy_unpacker
#elif
1
==
PACKER_UNPACKER_TYPE
#define ASCS_DEFAULT_PACKER packer2<unique_buffer<std::string>, std::string>
#define ASCS_DEFAULT_UNPACKER unpacker2<unique_buffer<std::string>>
#elif 2 == PACKER_UNPACKER_TYPE
...
...
include/ascs/ext/unpacker.h
浏览文件 @
2158fe21
...
...
@@ -379,7 +379,7 @@ protected:
//protocol: length + body
//T can be unique_buffer<std::string> or shared_buffer<std::string>, the latter makes output messages seemingly copyable.
template
<
typename
T
=
shared_buffer
<
std
::
string
>
>
template
<
typename
T
=
shared_buffer
<
std
::
string
>
,
typename
Unpacker
=
unpacker
>
class
unpacker2
:
public
ascs
::
i_unpacker
<
T
>
{
private:
...
...
@@ -390,10 +390,10 @@ public:
virtual
void
dump_left_data
()
const
{
unpacker_
.
dump_left_data
();}
virtual
bool
parse_msg
(
size_t
bytes_transferred
,
typename
super
::
container_type
&
msg_can
)
{
u
npacker
::
container_type
tmp_can
;
typename
U
npacker
::
container_type
tmp_can
;
unpacker_
.
stripped
(
this
->
stripped
());
auto
unpack_ok
=
unpacker_
.
parse_msg
(
bytes_transferred
,
tmp_can
);
do_something_to_all
(
tmp_can
,
[
&
msg_can
](
u
npacker
::
msg_type
&
item
)
{
msg_can
.
emplace_back
(
new
std
::
string
(
std
::
move
(
item
)));});
do_something_to_all
(
tmp_can
,
[
&
msg_can
](
typename
U
npacker
::
msg_type
&
item
)
{
msg_can
.
emplace_back
(
new
std
::
string
(
std
::
move
(
item
)));});
//if unpacking failed, successfully parsed msgs will still returned via msg_can(sticky package), please note.
return
unpack_ok
;
...
...
@@ -408,7 +408,7 @@ public:
virtual
size_t
raw_data_len
(
typename
super
::
msg_ctype
&
msg
)
const
{
return
this
->
stripped
()
?
msg
.
size
()
:
msg
.
size
()
-
ASCS_HEAD_LEN
;}
protected:
u
npacker
unpacker_
;
U
npacker
unpacker_
;
};
//protocol: UDP has message boundary, so we don't need a specific protocol to unpack it.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录