Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
ascs
提交
71a7df67
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,发现更多精彩内容 >>
提交
71a7df67
编写于
8月 20, 2020
作者:
Y
youngwolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
client socket and udp socket support deleting itself from object_pool (via i_Matrix).
上级
3700fad9
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
38 addition
and
5 deletion
+38
-5
examples/client/client.cpp
examples/client/client.cpp
+0
-3
include/ascs/base.h
include/ascs/base.h
+2
-1
include/ascs/object_pool.h
include/ascs/object_pool.h
+22
-0
include/ascs/socket_service.h
include/ascs/socket_service.h
+2
-0
include/ascs/tcp/client_socket.h
include/ascs/tcp/client_socket.h
+5
-0
include/ascs/tcp/server.h
include/ascs/tcp/server.h
+2
-0
include/ascs/udp/socket.h
include/ascs/udp/socket.h
+4
-0
include/ascs/udp/socket_service.h
include/ascs/udp/socket_service.h
+1
-1
未找到文件。
examples/client/client.cpp
浏览文件 @
71a7df67
...
...
@@ -3,9 +3,6 @@
//configuration
#define ASCS_SERVER_PORT 9527
#define ASCS_DELAY_CLOSE 1 //this demo not used object pool and doesn't need life cycle management,
//so, define this to avoid hooks for async call (and slightly improve efficiency),
//any value which is bigger than zero is okay.
#define ASCS_SYNC_SEND
#define ASCS_SYNC_RECV
//#define ASCS_PASSIVE_RECV //because we not defined this macro, this demo will use mix model to receive messages, which means
...
...
include/ascs/base.h
浏览文件 @
71a7df67
...
...
@@ -73,6 +73,7 @@ public:
virtual
bool
socket_exist
(
uint_fast64_t
id
)
=
0
;
virtual
std
::
shared_ptr
<
tracked_executor
>
find_socket
(
uint_fast64_t
id
)
=
0
;
virtual
bool
del_socket
(
uint_fast64_t
id
)
=
0
;
};
namespace
tcp
...
...
@@ -80,7 +81,7 @@ namespace tcp
class
i_server
:
public
i_matrix
{
public:
virtual
bool
del_socket
(
const
std
::
shared_ptr
<
tracked_executor
>&
socket_ptr
)
=
0
;
virtual
bool
del_socket
(
const
std
::
shared_ptr
<
tracked_executor
>&
socket_ptr
)
=
0
;
//hide i_matrix::del_socket
virtual
bool
restore_socket
(
const
std
::
shared_ptr
<
tracked_executor
>&
socket_ptr
,
uint_fast64_t
id
,
bool
init
)
=
0
;
};
}
//namespace
...
...
include/ascs/object_pool.h
浏览文件 @
71a7df67
...
...
@@ -83,6 +83,28 @@ protected:
return
exist
;
}
bool
del_object
(
uint_fast64_t
id
)
{
auto
object_ptr
=
object_type
();
std
::
unique_lock
<
ASCS_SHARED_MUTEX_TYPE
>
lock
(
object_can_mutex
);
auto
iter
=
object_can
.
find
(
id
);
if
(
iter
!=
std
::
end
(
object_can
))
{
object_ptr
=
iter
->
second
;
object_can
.
erase
(
iter
);
}
lock
.
unlock
();
if
(
object_ptr
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
invalid_object_can_mutex
);
try
{
invalid_object_can
.
emplace_back
(
object_ptr
);}
catch
(
const
std
::
exception
&
e
)
{
unified_out
::
error_out
(
"cannot hold more objects (%s)"
,
e
.
what
());}
}
return
!!
object_ptr
;
}
//you can do some statistic about object creations at here
virtual
void
on_create
(
object_ctype
&
object_ptr
)
{}
...
...
include/ascs/socket_service.h
浏览文件 @
71a7df67
...
...
@@ -55,8 +55,10 @@ public:
virtual
bool
started
()
const
{
return
this
->
service_started
();}
virtual
service_pump
&
get_service_pump
()
{
return
Pool
::
get_service_pump
();}
virtual
const
service_pump
&
get_service_pump
()
const
{
return
Pool
::
get_service_pump
();}
virtual
bool
socket_exist
(
uint_fast64_t
id
)
{
return
this
->
exist
(
id
);}
virtual
std
::
shared_ptr
<
tracked_executor
>
find_socket
(
uint_fast64_t
id
)
{
return
this
->
find
(
id
);}
virtual
bool
del_socket
(
uint_fast64_t
id
)
{
return
this
->
del_object
(
id
);}
typename
Pool
::
object_type
create_object
()
{
return
Pool
::
create_object
(
*
this
);}
template
<
typename
Arg
>
typename
Pool
::
object_type
create_object
(
Arg
&&
arg
)
{
return
Pool
::
create_object
(
*
this
,
std
::
forward
<
Arg
>
(
arg
));}
...
...
include/ascs/tcp/client_socket.h
浏览文件 @
71a7df67
...
...
@@ -143,6 +143,11 @@ protected:
force_shutdown
(
need_reconnect
);
this
->
status
=
super
::
link_status
::
BROKEN
;
#ifndef ASCS_CLEAR_OBJECT_INTERVAL
if
(
!
need_reconnect
&&
nullptr
!=
matrix
)
matrix
->
del_socket
(
this
->
id
());
#endif
}
virtual
void
on_async_shutdown_error
()
{
force_shutdown
(
need_reconnect
);}
...
...
include/ascs/tcp/server.h
浏览文件 @
71a7df67
...
...
@@ -102,8 +102,10 @@ public:
virtual
bool
started
()
const
{
return
this
->
service_started
();}
virtual
service_pump
&
get_service_pump
()
{
return
Pool
::
get_service_pump
();}
virtual
const
service_pump
&
get_service_pump
()
const
{
return
Pool
::
get_service_pump
();}
virtual
bool
socket_exist
(
uint_fast64_t
id
)
{
return
this
->
exist
(
id
);}
virtual
std
::
shared_ptr
<
tracked_executor
>
find_socket
(
uint_fast64_t
id
)
{
return
this
->
find
(
id
);}
virtual
bool
del_socket
(
uint_fast64_t
id
)
{
unified_out
::
error_out
(
"use bool del_socket(const std::shared_ptr<tracked_executor>&) please."
);
assert
(
false
);
return
false
;}
virtual
bool
del_socket
(
const
std
::
shared_ptr
<
tracked_executor
>&
socket_ptr
)
{
...
...
include/ascs/udp/socket.h
浏览文件 @
71a7df67
...
...
@@ -204,6 +204,10 @@ protected:
{
if
(
asio
::
error
::
operation_aborted
!=
ec
)
unified_out
::
error_out
(
ASCS_LLF
" recv msg error (%d %s)"
,
this
->
id
(),
ec
.
value
(),
ec
.
message
().
data
());
#ifndef ASCS_CLEAR_OBJECT_INTERVAL
else
if
(
nullptr
!=
matrix
)
matrix
->
del_socket
(
this
->
id
());
#endif
}
virtual
bool
on_heartbeat_error
()
...
...
include/ascs/udp/socket_service.h
浏览文件 @
71a7df67
...
...
@@ -58,7 +58,7 @@ public:
void
graceful_shutdown
()
{
this
->
do_something_to_all
([](
typename
Pool
::
object_ctype
&
item
)
{
item
->
graceful_shutdown
();});}
protected:
virtual
void
uninit
()
{
this
->
stop
();
graceful
_shutdown
();}
virtual
void
uninit
()
{
this
->
stop
();
force
_shutdown
();}
};
}}
//namespace
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录