Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
ascs
提交
7cf8cc75
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,发现更多精彩内容 >>
提交
7cf8cc75
编写于
1月 09, 2019
作者:
Y
yang li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Trim codes.
上级
044d5bc7
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
17 addition
and
55 deletion
+17
-55
examples/client/client.cpp
examples/client/client.cpp
+6
-25
examples/echo_server/echo_server.cpp
examples/echo_server/echo_server.cpp
+11
-30
未找到文件。
examples/client/client.cpp
浏览文件 @
7cf8cc75
...
@@ -90,24 +90,13 @@ private:
...
@@ -90,24 +90,13 @@ private:
class
short_client
:
public
multi_client_base
<
short_connection
>
,
protected
i_controller
class
short_client
:
public
multi_client_base
<
short_connection
>
,
protected
i_controller
{
{
public:
public:
short_client
(
service_pump
&
service_pump_
)
:
multi_client_base
<
short_connection
>
(
service_pump_
)
{}
short_client
(
service_pump
&
service_pump_
)
:
multi_client_base
(
service_pump_
)
{}
void
set_server_addr
(
unsigned
short
_port
,
const
std
::
string
&
_ip
=
ASCS_SERVER_IP
)
{
port
=
_port
;
ip
=
_ip
;
}
void
set_server_addr
(
unsigned
short
_port
,
const
std
::
string
&
_ip
=
ASCS_SERVER_IP
)
{
port
=
_port
;
ip
=
_ip
;}
bool
send_msg
(
const
std
::
string
&
msg
)
bool
send_msg
(
const
std
::
string
&
msg
)
{
{
auto
socket_ptr
=
add_socket
(
port
,
ip
);
auto
socket_ptr
=
add_socket
(
port
,
ip
);
if
(
socket_ptr
)
return
socket_ptr
?
socket_ptr
->
set_controller
(
this
),
socket_ptr
->
send_msg
(
msg
)
:
false
;
{
socket_ptr
->
set_controller
(
this
);
return
socket_ptr
->
send_msg
(
msg
);
}
return
false
;
}
}
protected:
protected:
...
@@ -151,22 +140,14 @@ int main(int argc, const char* argv[])
...
@@ -151,22 +140,14 @@ int main(int argc, const char* argv[])
// argv[2] = "::1" //ipv6
// argv[2] = "::1" //ipv6
// argv[2] = "127.0.0.1" //ipv4
// argv[2] = "127.0.0.1" //ipv4
unsigned
short
port
=
ASCS_SERVER_PORT
+
100
;
unsigned
short
port
=
ASCS_SERVER_PORT
+
100
;
std
::
string
ip
;
std
::
string
ip
=
ASCS_SERVER_IP
;
if
(
argc
>
1
)
if
(
argc
>
1
)
port
=
(
unsigned
short
)
atoi
(
argv
[
1
]);
port
=
(
unsigned
short
)
atoi
(
argv
[
1
]);
if
(
argc
>
2
)
if
(
argc
>
2
)
ip
=
argv
[
2
];
ip
=
argv
[
2
];
if
(
!
ip
.
empty
())
{
client
.
set_server_addr
(
port
,
ip
);
client
.
set_server_addr
(
port
,
ip
);
client2
.
set_server_addr
(
port
+
1
,
ip
);
client2
.
set_server_addr
(
port
+
1
,
ip
);
}
else
{
client
.
set_server_addr
(
port
);
client2
.
set_server_addr
(
port
+
1
);
}
sp
.
start_service
();
sp
.
start_service
();
auto
t
=
create_sync_recv_thread
(
client
);
auto
t
=
create_sync_recv_thread
(
client
);
...
...
examples/echo_server/echo_server.cpp
浏览文件 @
7cf8cc75
...
@@ -185,24 +185,12 @@ protected:
...
@@ -185,24 +185,12 @@ protected:
//msg handling
//msg handling
#ifdef ASCS_SYNC_DISPATCH
#ifdef ASCS_SYNC_DISPATCH
//do not hold msg_can for further using, return from on_msg as quickly as possible
//do not hold msg_can for further using, return from on_msg as quickly as possible
virtual
size_t
on_msg
(
std
::
list
<
out_msg_type
>&
msg_can
)
virtual
size_t
on_msg
(
std
::
list
<
out_msg_type
>&
msg_can
)
{
auto
re
=
server_socket_base
::
on_msg
(
msg_can
);
force_shutdown
();
return
re
;}
{
auto
re
=
server_socket_base
::
on_msg
(
msg_can
);
force_shutdown
();
return
re
;
}
#endif
#endif
#ifdef ASCS_DISPATCH_BATCH_MSG
#ifdef ASCS_DISPATCH_BATCH_MSG
//do not hold msg_can for further using, access msg_can and return from on_msg_handle as quickly as possible
//do not hold msg_can for further using, access msg_can and return from on_msg_handle as quickly as possible
virtual
size_t
on_msg_handle
(
out_queue_type
&
msg_can
)
virtual
size_t
on_msg_handle
(
out_queue_type
&
msg_can
)
{
auto
re
=
server_socket_base
::
on_msg_handle
(
msg_can
);
force_shutdown
();
return
re
;}
{
auto
re
=
server_socket_base
::
on_msg_handle
(
msg_can
);
force_shutdown
();
return
re
;
}
#else
#else
virtual
bool
on_msg_handle
(
out_msg_type
&
msg
)
{
auto
re
=
server_socket_base
::
on_msg_handle
(
msg
);
force_shutdown
();
return
re
;}
virtual
bool
on_msg_handle
(
out_msg_type
&
msg
)
{
auto
re
=
server_socket_base
::
on_msg_handle
(
msg
);
force_shutdown
();
return
re
;}
#endif
#endif
...
@@ -227,23 +215,16 @@ int main(int argc, const char* argv[])
...
@@ -227,23 +215,16 @@ int main(int argc, const char* argv[])
server_base
<
short_connection
>
short_server
(
sp
);
server_base
<
short_connection
>
short_server
(
sp
);
echo_server
echo_server_
(
sp
);
//echo server
echo_server
echo_server_
(
sp
);
//echo server
unsigned
short
port
=
ASCS_SERVER_PORT
;
std
::
string
ip
;
if
(
argc
>
2
)
port
=
(
unsigned
short
)
atoi
(
argv
[
2
]);
if
(
argc
>
3
)
if
(
argc
>
3
)
{
ip
=
argv
[
3
];
normal_server
.
set_server_addr
(
atoi
(
argv
[
2
])
+
100
,
argv
[
3
]);
short_server
.
set_server_addr
(
atoi
(
argv
[
2
])
+
101
,
argv
[
3
]);
normal_server
.
set_server_addr
(
port
+
100
,
ip
);
echo_server_
.
set_server_addr
(
atoi
(
argv
[
2
]),
argv
[
3
]);
short_server
.
set_server_addr
(
port
+
101
,
ip
);
}
echo_server_
.
set_server_addr
(
port
,
ip
);
else
if
(
argc
>
2
)
{
normal_server
.
set_server_addr
(
atoi
(
argv
[
2
])
+
100
);
short_server
.
set_server_addr
(
atoi
(
argv
[
2
])
+
101
);
echo_server_
.
set_server_addr
(
atoi
(
argv
[
2
]));
}
else
{
normal_server
.
set_server_addr
(
ASCS_SERVER_PORT
+
100
);
short_server
.
set_server_addr
(
ASCS_SERVER_PORT
+
101
);
}
auto
thread_num
=
1
;
auto
thread_num
=
1
;
if
(
argc
>
1
)
if
(
argc
>
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录