Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
familyMart_takeaway
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guanghui.cui
familyMart_takeaway
Commits
27d8b327
Commit
27d8b327
authored
Jul 04, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ods连接异常和非法数据处理
parent
2f638ccc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
2 deletions
+32
-2
src/JsonModule.cpp
+17
-0
src/JsonModule.h
+6
-0
src/main.cpp
+9
-2
No files found.
src/JsonModule.cpp
View file @
27d8b327
...
@@ -626,6 +626,23 @@ bool JsonModule::getInitBackData(IN const char* inJson,OUT std::string& outJson)
...
@@ -626,6 +626,23 @@ bool JsonModule::getInitBackData(IN const char* inJson,OUT std::string& outJson)
return
false
;
return
false
;
}
}
bool
JsonModule
::
isInitBackValid
(
IN
const
char
*
inJson
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
inJson
);
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"isInitBackValid JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
}
if
(
document
.
HasMember
(
"code"
))
{
return
true
;
}
return
false
;
}
bool
JsonModule
::
getPosResponseData
(
int
status
,
const
std
::
string
&
msg
,
std
::
string
&
result
)
bool
JsonModule
::
getPosResponseData
(
int
status
,
const
std
::
string
&
msg
,
std
::
string
&
result
)
{
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
StringBuffer
buffer
;
...
...
src/JsonModule.h
View file @
27d8b327
...
@@ -30,6 +30,12 @@ public:
...
@@ -30,6 +30,12 @@ public:
* */
* */
bool
getInitBackData
(
IN
const
char
*
inJson
,
OUT
std
::
string
&
outJson
);
bool
getInitBackData
(
IN
const
char
*
inJson
,
OUT
std
::
string
&
outJson
);
/* 功能:获取ODS初始化返回数据是否合法
* 参数:[1]返回json数据
* 返回:是否正确格式
* */
bool
isInitBackValid
(
IN
const
char
*
inJson
);
/* 功能:判断是否是心跳包
/* 功能:判断是否是心跳包
* 参数:[1]待判断数据
* 参数:[1]待判断数据
* 返回:1:心跳包 2:非心跳包 3:非法数据
* 返回:1:心跳包 2:非心跳包 3:非法数据
...
...
src/main.cpp
View file @
27d8b327
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
INITIALIZE_EASYLOGGINGPP
INITIALIZE_EASYLOGGINGPP
#define VERSION "1.0.5 Beta
2
" //版本号
#define VERSION "1.0.5 Beta
4
" //版本号
std
::
string
g_init_data
;
std
::
string
g_init_data
;
std
::
string
g_init_data_ods_back
;
std
::
string
g_init_data_ods_back
;
...
@@ -158,13 +158,16 @@ void* listen_pos_func(void* arg)
...
@@ -158,13 +158,16 @@ void* listen_pos_func(void* arg)
TCPClient
ods
;
TCPClient
ods
;
if
(
ods
.
doConnect
(
ods_recv_port
,
ods_ip
.
c_str
())
)
if
(
ods
.
doConnect
(
ods_recv_port
,
ods_ip
.
c_str
())
)
{
{
ods
.
setSocketTimeout
(
60
);
//设置超时
if
(
ods
.
send
(
requestOdsData
)
)
if
(
ods
.
send
(
requestOdsData
)
)
{
{
std
::
string
tmp
;
std
::
string
tmp
;
if
(
ods
.
receive
(
tmp
)
)
if
(
ods
.
receive
(
tmp
)
)
{
{
LOG
(
INFO
)
<<
"REQ ODS ===>> PLUGIN:"
<<
tmp
.
data
();
LOG
(
INFO
)
<<
"REQ ODS ===>> PLUGIN:"
<<
tmp
.
data
();
jsonTool
.
getPosResponseData
(
tmp
,
posRequestData
,
responseData
);
if
(
!
jsonTool
.
getPosResponseData
(
tmp
,
posRequestData
,
responseData
))
{
jsonTool
.
getPosResponseData
(
101
,
"receive data from [ODS] invalid!"
,
responseData
);
}
}
else
}
else
{
{
jsonTool
.
getPosResponseData
(
101
,
"receive data from [ODS] failed!"
,
responseData
);
jsonTool
.
getPosResponseData
(
101
,
"receive data from [ODS] failed!"
,
responseData
);
...
@@ -318,6 +321,10 @@ int main(int argc,char *argv[])
...
@@ -318,6 +321,10 @@ int main(int argc,char *argv[])
ods
.
receive
(
odsPushData
);
ods
.
receive
(
odsPushData
);
g_init_data_ods_back
=
odsPushData
;
g_init_data_ods_back
=
odsPushData
;
LOG
(
INFO
)
<<
"INIT ODS ===>> PLUGIN:"
<<
odsPushData
.
data
();
LOG
(
INFO
)
<<
"INIT ODS ===>> PLUGIN:"
<<
odsPushData
.
data
();
if
(
odsPushData
.
empty
()
||
!
jsonTool
.
isInitBackValid
(
odsPushData
.
data
()))
{
LOG
(
INFO
)
<<
"invalid data,close connect"
;
ods
.
close
();
//当连接到负载均衡,并没有和ods建立连接的时候。返回值为空,所以应该关闭重新连接
}
int
count
=
0
;
int
count
=
0
;
while
(
!
bInitDone
){
while
(
!
bInitDone
){
LOG
(
INFO
)
<<
"wait for init done"
;
LOG
(
INFO
)
<<
"wait for init done"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment