Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
ascs
提交
7ba0e697
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,发现更多精彩内容 >>
提交
7ba0e697
编写于
6月 27, 2019
作者:
Y
yang li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More comments in demos to help you understand passive receiving and message handling more.
上级
06e0cdd2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
49 addition
and
2 deletion
+49
-2
examples/echo_client/echo_client.cpp
examples/echo_client/echo_client.cpp
+4
-0
examples/echo_server/echo_server.cpp
examples/echo_server/echo_server.cpp
+4
-0
examples/file_client/file_client.h
examples/file_client/file_client.h
+37
-0
include/ascs/container.h
include/ascs/container.h
+2
-0
include/ascs/tcp/socket.h
include/ascs/tcp/socket.h
+2
-2
未找到文件。
examples/echo_client/echo_client.cpp
浏览文件 @
7ba0e697
...
...
@@ -123,6 +123,8 @@ protected:
//except we can bear message disordering.
return
1
;
//if we indeed handled some messages, do return 1
//if we handled nothing, return 1 is also okey but will very slightly impact performance (if msg_can is not empty), return 0 is suggested
}
#endif
#ifdef ASCS_DISPATCH_BATCH_MSG
...
...
@@ -136,6 +138,8 @@ protected:
ascs
::
do_something_to_all
(
tmp_can
,
[
this
](
out_msg_type
&
msg
)
{
this
->
handle_msg
(
msg
);});
return
1
;
//if we indeed handled some messages, do return 1
//if we handled nothing, return 1 is also okey but will very slightly impact performance, return 0 is suggested
}
#else
virtual
bool
on_msg_handle
(
out_msg_type
&
msg
)
{
handle_msg
(
msg
);
return
true
;}
...
...
examples/echo_server/echo_server.cpp
浏览文件 @
7ba0e697
...
...
@@ -117,6 +117,8 @@ protected:
msg_can
.
clear
();
return
1
;
//if we indeed handled some messages, do return 1
//if we handled nothing, return 1 is also okey but will very slightly impact performance (if msg_can is not empty), return 0 is suggested
}
#endif
...
...
@@ -135,6 +137,8 @@ protected:
//following statement can avoid one memory replication if the type of out_msg_type and in_msg_type are identical.
ascs
::
do_something_to_all
(
tmp_can
,
[
this
](
out_msg_type
&
msg
)
{
this
->
send_msg
(
std
::
move
(
msg
),
true
);});
return
1
;
//if we indeed handled some messages, do return 1
//if we handled nothing, return 1 is also okey but will very slightly impact performance, return 0 is suggested
}
#else
//following statement can avoid one memory replication if the type of out_msg_type and in_msg_type are identical.
...
...
examples/file_client/file_client.h
浏览文件 @
7ba0e697
...
...
@@ -65,9 +65,46 @@ public:
protected:
//msg handling
#ifdef ASCS_SYNC_DISPATCH
virtual
size_t
on_msg
(
list
<
out_msg_type
>&
msg_can
)
{
//ascs will never append empty message automatically for on_msg (if no message nor error returned from the unpacker) even with
// macro ASCS_PASSIVE_RECV, but will do it for on_msg_handle (with macro ASCS_PASSIVE_RECV), please note.
if
(
msg_can
.
empty
())
handle_msg
(
out_msg_type
());
//we need empty message as a notification, it's just our business logic.
else
{
ascs
::
do_something_to_all
(
msg_can
,
[
this
](
out_msg_type
&
msg
)
{
this
->
handle_msg
(
msg
);});
msg_can
.
clear
();
}
recv_msg
();
//we always handled all messages, so calling recv_msg() at here is very reasonable.
return
1
;
//if we indeed handled some messages, do return 1
//if we handled nothing, return 1 is also okey but will very slightly impact performance (if msg_can is not empty), return 0 is suggested
}
#endif
#ifdef ASCS_DISPATCH_BATCH_MSG
virtual
size_t
on_msg_handle
(
out_queue_type
&
msg_can
)
{
//msg_can can't be empty, with macro ASCS_PASSIVE_RECV, ascs will append an empty message automatically for on_msg_handle if no message nor
// error returned from the unpacker to provide a chance to call recv_msg (calling recv_msg out of on_msg and on_msg_handle is forbidden), please note.
assert
(
!
msg_can
.
empty
());
out_container_type
tmp_can
;
msg_can
.
swap
(
tmp_can
);
ascs
::
do_something_to_all
(
tmp_can
,
[
this
](
out_msg_type
&
msg
)
{
this
->
handle_msg
(
msg
);});
recv_msg
();
//we always handled all messages, so calling recv_msg() at here is very reasonable.
return
1
;
//if we indeed handled some messages, do return 1
//if we handled nothing, return 1 is also okey but will very slightly impact performance, return 0 is suggested
}
#else
virtual
bool
on_msg_handle
(
out_msg_type
&
msg
)
{
handle_msg
(
msg
);
if
(
0
==
get_pending_recv_msg_size
())
recv_msg
();
return
true
;}
//only raise recv_msg() invocation after recveiving buffer becomes empty, it's very important, otherwise we must use mutex to guarantee that at any time,
//there only exists one or zero asynchronous reception.
#endif
//msg handling end
virtual
void
on_connect
()
...
...
include/ascs/container.h
浏览文件 @
7ba0e697
...
...
@@ -114,6 +114,8 @@ public:
{
if
(
0
==
size_in_byte
)
size_in_byte
=
ascs
::
get_size_in_byte
(
src
);
else
assert
(
ascs
::
get_size_in_byte
(
src
)
==
size_in_byte
);
this
->
splice
(
this
->
end
(),
src
);
total_size
+=
size_in_byte
;
...
...
include/ascs/tcp/socket.h
浏览文件 @
7ba0e697
...
...
@@ -269,7 +269,7 @@ private:
on_unpack_error
();
//the user will decide whether to reset the unpacker or not in this callback
#ifdef ASCS_PASSIVE_RECV
reading
=
false
;
//clear reading flag before call
handle_msg() to make sure that recv_msg() can be called successfully in
on_msg_handle()
reading
=
false
;
//clear reading flag before call
ing handle_msg() to make sure that recv_msg() is available in on_msg() and
on_msg_handle()
#endif
if
(
handle_msg
())
//if macro ASCS_PASSIVE_RECV been defined, handle_msg will always return false
do_recv_msg
();
//receive msg in sequence
...
...
@@ -277,7 +277,7 @@ private:
else
{
#ifdef ASCS_PASSIVE_RECV
reading
=
false
;
//clear reading flag before call
handle_msg() to make sure that recv_msg() can be called successfully in
on_msg_handle()
reading
=
false
;
//clear reading flag before call
ing handle_msg() to make sure that recv_msg() is available in on_msg() and
on_msg_handle()
#endif
if
(
ec
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录