Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
e260fd09
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e260fd09
编写于
9月 22, 2020
作者:
G
Guodong Rong
提交者:
Liu Jiaming
9月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use two buffers to handle message larger than 65536 bytes.
上级
8a2f1992
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
25 deletion
+52
-25
modules/contrib/cyber_bridge/client.cc
modules/contrib/cyber_bridge/client.cc
+47
-23
modules/contrib/cyber_bridge/client.h
modules/contrib/cyber_bridge/client.h
+5
-2
未找到文件。
modules/contrib/cyber_bridge/client.cc
浏览文件 @
e260fd09
...
...
@@ -12,6 +12,7 @@
#include <utility>
#include "boost/bind.hpp"
#include "cyber/common/log.h"
#include "cyber/message/protobuf_factory.h"
#include "modules/contrib/cyber_bridge/clients.h"
...
...
@@ -93,12 +94,24 @@ void Client::handle_read(const boost::system::error_code& ec,
}
void
Client
::
handle_write
(
const
boost
::
system
::
error_code
&
ec
)
{
if
(
ec
&&
ec
!=
boost
::
asio
::
error
::
operation_aborted
)
{
AERROR
<<
"Client write failed, disconnecting"
<<
ec
;
clients
.
stop
(
shared_from_this
());
node
.
remove
(
shared_from_this
());
if
(
ec
)
{
if
(
ec
!=
boost
::
asio
::
error
::
operation_aborted
)
{
AERROR
<<
"Client write failed, disconnecting"
<<
ec
;
clients
.
stop
(
shared_from_this
());
node
.
remove
(
shared_from_this
());
}
return
;
}
std
::
lock_guard
<
std
::
mutex
>
lock
(
publish_mutex
);
writing
.
clear
();
if
(
!
pending
.
empty
())
{
writing
.
swap
(
pending
);
boost
::
asio
::
async_write
(
socket
,
boost
::
asio
::
buffer
(
writing
.
data
(),
writing
.
size
()),
boost
::
bind
(
&
Client
::
handle_write
,
shared_from_this
(),
boost
::
asio
::
placeholders
::
error
));
}
}
// [1] [count] [string] ... [string]
...
...
@@ -255,32 +268,43 @@ void Client::handle_publish() {
buffer
.
erase
(
buffer
.
begin
(),
buffer
.
begin
()
+
offset
);
}
void
Client
::
publish
(
const
std
::
string
&
channel
,
const
std
::
string
&
msg
)
{
std
::
vector
<
uint8_t
>
data
;
data
.
reserve
(
sizeof
(
uint8_t
)
+
sizeof
(
uint32_t
)
+
channel
.
size
(
)
+
sizeof
(
uint32_t
)
+
msg
.
size
());
void
fill_data
(
std
::
vector
<
uint8_t
>*
data
,
const
std
::
string
&
channel
,
const
std
::
string
&
msg
)
{
data
->
reserve
(
data
->
size
()
+
sizeof
(
uint8_t
)
+
sizeof
(
uint32_t
)
+
channel
.
size
()
+
sizeof
(
uint32_t
)
+
msg
.
size
());
data
.
push_back
(
OP_PUBLISH
);
data
->
push_back
(
OP_PUBLISH
);
data
.
push_back
(
uint8_t
(
channel
.
size
()
>>
0
));
data
.
push_back
(
uint8_t
(
channel
.
size
()
>>
8
));
data
.
push_back
(
uint8_t
(
channel
.
size
()
>>
16
));
data
.
push_back
(
uint8_t
(
channel
.
size
()
>>
24
));
data
->
push_back
(
uint8_t
(
channel
.
size
()
>>
0
));
data
->
push_back
(
uint8_t
(
channel
.
size
()
>>
8
));
data
->
push_back
(
uint8_t
(
channel
.
size
()
>>
16
));
data
->
push_back
(
uint8_t
(
channel
.
size
()
>>
24
));
const
uint8_t
*
channel_data
=
reinterpret_cast
<
const
uint8_t
*>
(
channel
.
data
());
data
.
insert
(
data
.
end
(),
channel_data
,
channel_data
+
channel
.
size
());
data
->
insert
(
data
->
end
(),
channel_data
,
channel_data
+
channel
.
size
());
data
.
push_back
(
uint8_t
(
msg
.
size
()
>>
0
));
data
.
push_back
(
uint8_t
(
msg
.
size
()
>>
8
));
data
.
push_back
(
uint8_t
(
msg
.
size
()
>>
16
));
data
.
push_back
(
uint8_t
(
msg
.
size
()
>>
24
));
data
->
push_back
(
uint8_t
(
msg
.
size
()
>>
0
));
data
->
push_back
(
uint8_t
(
msg
.
size
()
>>
8
));
data
->
push_back
(
uint8_t
(
msg
.
size
()
>>
16
));
data
->
push_back
(
uint8_t
(
msg
.
size
()
>>
24
));
const
uint8_t
*
msg_data
=
reinterpret_cast
<
const
uint8_t
*>
(
msg
.
data
());
data
.
insert
(
data
.
end
(),
msg_data
,
msg_data
+
msg
.
size
());
data
->
insert
(
data
->
end
(),
msg_data
,
msg_data
+
msg
.
size
());
}
boost
::
asio
::
async_write
(
socket
,
boost
::
asio
::
buffer
(
data
.
data
(),
data
.
size
()),
boost
::
bind
(
&
Client
::
handle_write
,
shared_from_this
(),
boost
::
asio
::
placeholders
::
error
));
void
Client
::
publish
(
const
std
::
string
&
channel
,
const
std
::
string
&
msg
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
publish_mutex
);
if
(
writing
.
empty
())
{
fill_data
(
&
writing
,
channel
,
msg
);
boost
::
asio
::
async_write
(
socket
,
boost
::
asio
::
buffer
(
writing
.
data
(),
writing
.
size
()),
boost
::
bind
(
&
Client
::
handle_write
,
shared_from_this
(),
boost
::
asio
::
placeholders
::
error
));
}
else
if
(
pending
.
size
()
<
MAX_PENDING_SIZE
)
{
fill_data
(
&
pending
,
channel
,
msg
);
}
else
{
// If pending size is larger than MAX_PENDING_SIZE, discard the message.
AERROR
<<
"Pending size too large. Discard message."
;
}
}
uint32_t
Client
::
get32le
(
size_t
offset
)
const
{
...
...
modules/contrib/cyber_bridge/client.h
浏览文件 @
e260fd09
...
...
@@ -17,8 +17,7 @@ class Node;
class
Client
:
public
std
::
enable_shared_from_this
<
Client
>
{
public:
Client
(
Node
*
node
,
Clients
*
clients
,
boost
::
asio
::
ip
::
tcp
::
socket
socket
);
Client
(
Node
*
node
,
Clients
*
clients
,
boost
::
asio
::
ip
::
tcp
::
socket
socket
);
~
Client
();
void
start
();
...
...
@@ -34,6 +33,10 @@ class Client : public std::enable_shared_from_this<Client> {
uint8_t
temp
[
1024
*
1024
];
std
::
vector
<
uint8_t
>
buffer
;
std
::
vector
<
uint8_t
>
writing
;
std
::
vector
<
uint8_t
>
pending
;
std
::
mutex
publish_mutex
;
const
uint
MAX_PENDING_SIZE
=
1073741824
;
// 1GB
void
handle_read
(
const
boost
::
system
::
error_code
&
ec
,
std
::
size_t
length
);
void
handle_write
(
const
boost
::
system
::
error_code
&
ec
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录