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
82183d7f
Commit
82183d7f
authored
Mar 29, 2022
by
wuyang.zou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix dns failed > 3 ,App Will Quit
parent
34183082
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
12 deletions
+17
-12
src/main.cpp
+17
-12
No files found.
src/main.cpp
View file @
82183d7f
...
@@ -106,7 +106,7 @@ void* listen_pos_func(void* arg)
...
@@ -106,7 +106,7 @@ void* listen_pos_func(void* arg)
int
reqType
=
jsonTool
.
getPushType
(
posRequestData
.
data
());
int
reqType
=
jsonTool
.
getPushType
(
posRequestData
.
data
());
LOG
(
INFO
)
<<
"Pos ReqType:"
<<
reqType
;
LOG
(
INFO
)
<<
"Pos ReqType:"
<<
reqType
;
if
(
reqType
==
REQUEST_TYPE_INIT
)
{
if
(
reqType
==
REQUEST_TYPE_INIT
)
{
// POS请求类型:: 登录初始化;
// POS请求类型:: 登录初始化;
// 如果当前内存标识: 插件已接受到, Pos发送过来的登录请求, 初始化标识完成;将断开 插件与 ODS 的长连接, 等待后面插件再与ODS重新连接
// 如果当前内存标识: 插件已接受到, Pos发送过来的登录请求, 初始化标识完成;将断开 插件与 ODS 的长连接, 等待后面插件再与ODS重新连接
if
(
bInitDone
)
{
if
(
bInitDone
)
{
...
@@ -359,7 +359,7 @@ int main(int argc,char *argv[])
...
@@ -359,7 +359,7 @@ int main(int argc,char *argv[])
}
}
else
{
else
{
g_init_data
=
"{
\"
fm_cmd
\"
:1000,
\"
storeId
\"
:
\"
"
+
pos_config_storeid
+
"
\"
,
\"
pos_id
\"
:
\"
"
+
std
::
to_string
(
pos_config_posid
)
g_init_data
=
"{
\"
fm_cmd
\"
:1000,
\"
storeId
\"
:
\"
"
+
pos_config_storeid
+
"
\"
,
\"
pos_id
\"
:
\"
"
+
std
::
to_string
(
pos_config_posid
)
+
"
\"
,
\"
operator_id
\"
:
\"
zouwuyang
\"
,
\"
business_date
\"
:
\"
202
11015
\"
,
\"
is_master
\"
:"
+
pos_config_ismaster
+
" ,
\"
plugin_comment
\"
:
\"
"
+
g_plugin_comment
+
+
"
\"
,
\"
operator_id
\"
:
\"
zouwuyang
\"
,
\"
business_date
\"
:
\"
202
20401
\"
,
\"
is_master
\"
:"
+
pos_config_ismaster
+
" ,
\"
plugin_comment
\"
:
\"
"
+
g_plugin_comment
+
+
"
\"
,
\"
version
\"
:
\"
"
+
VERSION
+
"
\"
,
\"
listen_port
\"
:24445 }"
;
+
"
\"
,
\"
version
\"
:
\"
"
+
VERSION
+
"
\"
,
\"
listen_port
\"
:24445 }"
;
}
}
...
@@ -432,6 +432,9 @@ int main(int argc,char *argv[])
...
@@ -432,6 +432,9 @@ int main(int argc,char *argv[])
// 当 插件 与 ODS 的长连接无效时;
// 当 插件 与 ODS 的长连接无效时;
// ①插件将重连 ODS: ip+port; ②与ODS建立连接后 发送登录初始化请求报文 完成登录; ③登录成功后 接受ODS推送到插件上的请求数据
// ①插件将重连 ODS: ip+port; ②与ODS建立连接后 发送登录初始化请求报文 完成登录; ③登录成功后 接受ODS推送到插件上的请求数据
if
(
!
longConnectionOds
.
isValid
()
)
{
if
(
!
longConnectionOds
.
isValid
()
)
{
// 长连接断开重连时, 重新解析 域名映射地址;
ods_ip
=
ZIni
::
readString
(
"ODS"
,
"ip"
,
""
,
strIniPath
.
c_str
());
getIpByDns
(
ods_ip
);
// ①插件将重连 ODS : ip + port 成功;
// ①插件将重连 ODS : ip + port 成功;
if
(
longConnectionOds
.
doConnect
(
ods_push_port
,
ods_ip
.
c_str
()
)
)
{
if
(
longConnectionOds
.
doConnect
(
ods_push_port
,
ods_ip
.
c_str
()
)
)
{
...
@@ -441,7 +444,7 @@ int main(int argc,char *argv[])
...
@@ -441,7 +444,7 @@ int main(int argc,char *argv[])
int
waitPosInitReqTimeOutCount
=
0
;
int
waitPosInitReqTimeOutCount
=
0
;
while
(
true
)
{
// socket: Send / Recive To ODS --> Begin
while
(
true
)
{
// socket: Send / Recive To ODS --> Begin
if
(
!
g_init_data
.
empty
())
{
if
(
!
g_init_data
.
empty
())
{
// ②与ODS建立连接后 发送登录初始化请求报文成功 完成登录; Bug: Send Faild, Will While(1) ;
// ②与ODS建立连接后 发送登录初始化请求报文成功 完成登录; Bug: Send Faild, Will While(1) ;
if
(
longConnectionOds
.
send
(
g_init_data
)
)
{
if
(
longConnectionOds
.
send
(
g_init_data
)
)
{
longConnectionOds
.
receive
(
odsPushData
);
longConnectionOds
.
receive
(
odsPushData
);
...
@@ -487,7 +490,6 @@ int main(int argc,char *argv[])
...
@@ -487,7 +490,6 @@ int main(int argc,char *argv[])
waitPosInitReqTimeOutCount
++
;
waitPosInitReqTimeOutCount
++
;
}
}
os_sleep
(
10
);
os_sleep
(
10
);
if
(
waitPosInitReqTimeOutCount
<
6
)
{
if
(
waitPosInitReqTimeOutCount
<
6
)
{
continue
;
//Continue / break; 6次超时(60s) 内都继续本循环; 超过6次超时(60s) 将退出本循环,进入上一层循环进行重新连接Ods的 ip+ port;
continue
;
//Continue / break; 6次超时(60s) 内都继续本循环; 超过6次超时(60s) 将退出本循环,进入上一层循环进行重新连接Ods的 ip+ port;
}
else
{
}
else
{
...
@@ -508,20 +510,21 @@ int main(int argc,char *argv[])
...
@@ -508,20 +510,21 @@ int main(int argc,char *argv[])
if
(
!
bPriorityDone
){
if
(
!
bPriorityDone
){
LOG
(
INFO
)
<<
"ODS set priority send:"
<<
g_set_pos_priority
.
data
();
LOG
(
INFO
)
<<
"ODS set priority send:"
<<
g_set_pos_priority
.
data
();
if
(
longConnectionOds
.
send
(
g_set_pos_priority
)
)
{
if
(
longConnectionOds
.
send
(
g_set_pos_priority
)
)
{
longConnectionOds
.
receive
(
odsPushData
);
longConnectionOds
.
receive
(
odsPushData
);
g_set_pos_priority_ods_back
=
odsPushData
;
g_set_pos_priority_ods_back
=
odsPushData
;
LOG
(
INFO
)
<<
"ODS set priority back:"
<<
odsPushData
.
data
();
LOG
(
INFO
)
<<
"ODS set priority back:"
<<
odsPushData
.
data
();
}
}
}
}
// Recv ODS Request Command From Liston Long Connection;
// ③登录成功后 接受ODS推送到插件上的请求数据
// ③登录成功后 接受ODS推送到插件上的请求数据
if
(
longConnectionOds
.
receive
(
odsPushData
)
)
{
if
(
longConnectionOds
.
receive
(
odsPushData
)
)
{
LOG
(
INFO
)
<<
"---------------- ODS ===>> PLUGIN ---------------"
;
LOG
(
INFO
)
<<
"---------------- ODS ===>> PLUGIN ---------------"
;
LOG
(
INFO
)
<<
odsPushData
;
LOG
(
INFO
)
<<
odsPushData
;
int
dataType
=
jsonTool
.
isHeartbeatData
(
odsPushData
.
data
());
int
dataType
=
jsonTool
.
isHeartbeatData
(
odsPushData
.
data
());
if
(
2
==
dataType
){
if
(
2
==
dataType
)
{
//ODS Push Order Data ReqCommand;
if
(
jsonTool
.
convertDataOds2Pos
(
odsPushData
,
pushPosData
)
)
{
if
(
jsonTool
.
convertDataOds2Pos
(
odsPushData
,
pushPosData
)
)
{
LOG
(
INFO
)
<<
"----------- PLUGIN ===>> POS ------------"
;
LOG
(
INFO
)
<<
"----------- PLUGIN ===>> POS ------------"
;
...
@@ -547,23 +550,24 @@ int main(int argc,char *argv[])
...
@@ -547,23 +550,24 @@ int main(int argc,char *argv[])
}
else
{
}
else
{
jsonTool
.
getOdsResponseData
(
101
,
"convert data to [POS] format failed!"
,
odsPushData
,
responseData
);
jsonTool
.
getOdsResponseData
(
101
,
"convert data to [POS] format failed!"
,
odsPushData
,
responseData
);
}
}
// Direct Return Pos Response To Ods Request;
LOG
(
INFO
)
<<
"PLUGIN ===>> ODS:"
<<
responseData
.
data
();
LOG
(
INFO
)
<<
"PLUGIN ===>> ODS:"
<<
responseData
.
data
();
bool
rlt
=
longConnectionOds
.
send
(
responseData
);
bool
rlt
=
longConnectionOds
.
send
(
responseData
);
LOG
(
INFO
)
<<
"send to ods result:"
<<
rlt
;
LOG
(
INFO
)
<<
"send to ods result:"
<<
rlt
;
}
else
if
(
1
==
dataType
)
{
}
else
if
(
1
==
dataType
)
{
//ODS Send Heartbeat ReqCommand;
if
(
!
bInitDone
)
{
if
(
!
bInitDone
)
{
longConnectionOds
.
setValid
(
false
);
longConnectionOds
.
setValid
(
false
);
LOG
(
INFO
)
<<
"maybe pos restart,reconnect!!!"
;
LOG
(
INFO
)
<<
"maybe pos restart,reconnect!!!"
;
}
}
}
else
if
(
3
==
dataType
){
}
else
if
(
3
==
dataType
)
{
//ODS Undefine ReqCommand;
LOG
(
INFO
)
<<
"illegal data!!"
;
LOG
(
INFO
)
<<
"illegal data!!"
;
}
}
}
else
{
}
else
{
// Long Connect Recv Failed;
longConnectionOds
.
close
();
longConnectionOds
.
close
();
os_sleep
(
2
);
//防止在ods挂掉后狂刷日志
os_sleep
(
2
);
//防止在ods挂掉后狂刷日志
LOG
(
INFO
)
<<
"recv ODS pushData failed or timeout"
;
LOG
(
INFO
)
<<
"recv ODS pushData failed or timeout"
;
...
@@ -622,6 +626,7 @@ bool order_send_to_pos(IN std::string &order_json,IN std::string &ods_json,OUT s
...
@@ -622,6 +626,7 @@ bool order_send_to_pos(IN std::string &order_json,IN std::string &ods_json,OUT s
jsonTool
.
getOdsResponseData
(
tmp
,
order_json
,
ods_json
,
back_json
);
jsonTool
.
getOdsResponseData
(
tmp
,
order_json
,
ods_json
,
back_json
);
return
rlt
;
return
rlt
;
}
}
...
@@ -631,8 +636,8 @@ void getIpByDns(IN std::string &ods_ip) {
...
@@ -631,8 +636,8 @@ void getIpByDns(IN std::string &ods_ip) {
LOG
(
INFO
)
<<
"DNS Resolve IP Begin , Origin ods_ip: "
<<
ods_ip
.
c_str
();
LOG
(
INFO
)
<<
"DNS Resolve IP Begin , Origin ods_ip: "
<<
ods_ip
.
c_str
();
struct
hostent
*
pHost
=
NULL
;
struct
hostent
*
pHost
=
NULL
;
bool
bGetDnsRet
=
false
;
bool
bGetDnsRet
=
false
;
// 需考虑POS机断网后,域名解析会频繁失败,频繁失败,插件有退出程序的可能,故在此进行类似死循环处理,插件永不主动退出;
for
(
int
n
=
0
;
n
<
3
;
n
++
)
{
for
(
int
n
=
0
;
n
<
n
+
3
;
n
++
)
{
pHost
=
gethostbyname
(
ods_ip
.
c_str
());
pHost
=
gethostbyname
(
ods_ip
.
c_str
());
if
(
!
pHost
)
{
if
(
!
pHost
)
{
LOG
(
INFO
)
<<
"DNS Resolve Failed: ods domain name: "
<<
n
<<
" "
<<
ods_ip
.
c_str
();
LOG
(
INFO
)
<<
"DNS Resolve Failed: ods domain name: "
<<
n
<<
" "
<<
ods_ip
.
c_str
();
...
...
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