Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
bde909f0
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,发现更多精彩内容 >>
提交
bde909f0
编写于
9月 12, 2017
作者:
S
siyangy
提交者:
unacao
9月 12, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Dreamview: small refactor of SendData (#1702)
上级
fd9bd6a2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
15 addition
and
12 deletion
+15
-12
modules/dreamview/backend/simulation_world/simulation_world_updater.cc
...view/backend/simulation_world/simulation_world_updater.cc
+3
-3
modules/dreamview/backend/websocket/websocket.cc
modules/dreamview/backend/websocket/websocket.cc
+6
-5
modules/dreamview/backend/websocket/websocket.h
modules/dreamview/backend/websocket/websocket.h
+6
-4
未找到文件。
modules/dreamview/backend/simulation_world/simulation_world_updater.cc
浏览文件 @
bde909f0
...
...
@@ -59,7 +59,7 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
response
[
"type"
]
=
"MapData"
;
response
[
"data"
]
=
Json
::
parse
(
retrieved_json_string
);
websocket_
->
SendData
(
response
.
dump
(),
conn
);
websocket_
->
SendData
(
conn
,
response
.
dump
()
);
}
});
...
...
@@ -72,7 +72,7 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
}
auto
response
=
sim_world_service_
.
GetUpdateAsJson
(
*
radius
);
websocket_
->
SendData
(
response
.
dump
(),
conn
);
websocket_
->
SendData
(
conn
,
response
.
dump
()
);
});
websocket_
->
RegisterMessageHandler
(
...
...
@@ -107,7 +107,7 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
boost
::
shared_lock
<
boost
::
shared_mutex
>
reader_lock
(
mutex_
);
to_send
=
simulation_world_json_
;
}
websocket_
->
SendData
(
to_send
,
conn
);
websocket_
->
SendData
(
conn
,
to_send
,
true
);
});
}
...
...
modules/dreamview/backend/websocket/websocket.cc
浏览文件 @
bde909f0
...
...
@@ -67,7 +67,7 @@ bool WebSocketHandler::BroadcastData(const std::string &data) {
bool
all_success
=
true
;
for
(
Connection
*
conn
:
connections_to_send
)
{
if
(
!
SendData
(
data
,
conn
,
true
))
{
if
(
!
SendData
(
conn
,
data
,
true
))
{
all_success
=
false
;
}
}
...
...
@@ -75,8 +75,8 @@ bool WebSocketHandler::BroadcastData(const std::string &data) {
return
all_success
;
}
bool
WebSocketHandler
::
SendData
(
const
std
::
string
&
data
,
Connection
*
conn
,
bool
is_broadcast
)
{
bool
WebSocketHandler
::
SendData
(
Connection
*
conn
,
const
std
::
string
&
data
,
bool
skippable
)
{
std
::
shared_ptr
<
std
::
mutex
>
connection_lock
;
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex_
);
...
...
@@ -92,9 +92,10 @@ bool WebSocketHandler::SendData(const std::string &data, Connection *conn,
// Lock the connection while sending.
if
(
!
connection_lock
->
try_lock
())
{
// Skip sending data if:
// 1. This is a broadcast and there's higher priority data being sent.
// 1. Data is skippable according to sender and there's higher priority data
// being sent.
// 2. The connection has been closed.
if
(
is_broadcast
)
{
if
(
skippable
)
{
return
false
;
}
else
{
connection_lock
->
lock
();
// Block to acquire the lock.
...
...
modules/dreamview/backend/websocket/websocket.h
浏览文件 @
bde909f0
...
...
@@ -104,12 +104,14 @@ class WebSocketHandler : public CivetWebSocketHandler {
/**
* @brief Sends the provided data to a specific connected client.
*
@param data The message string to be sent.
*
* @param conn The connection to send to.
* @param is_broadcast whether this is a broadcast send.
* @param data The message string to be sent.
* @param skippable whether the data is allowed to be skipped if some other is
* being sent to this connection.
*/
bool
SendData
(
const
std
::
string
&
data
,
Connection
*
conn
,
bool
is_broadcast
=
false
);
bool
SendData
(
Connection
*
conn
,
const
std
::
string
&
data
,
bool
skippable
=
false
);
/**
* @brief Add a new message handler for a message type.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录