Commit 79741adb by wuyang.zou

Fix New Feature:优化socket通信时间间隔

Versionn: 2.2022.10.20
parent 0eb226bd
Pipeline #41710 failed with stage
in 0 seconds
......@@ -133,9 +133,9 @@ bool SocketCommunicate::connectTcpSvr()
requestErrorNum++;
QLOG_INFO()<< QString("connectTcpSvr:: getRealPubKeyPriKey Failed, encryptPublicKey: %1 , encryptPrivateKey: %2 ").arg( encryptPublicKey ).arg( encryptPrivateKey );
if (requestErrorNum < 5 ) {
Sleep(2*60*1000);
Sleep(SOCKET_SHORT_TIMEOUT_INTERVAL);
} else {
Sleep(5*60*1000);
Sleep(SOCKET_LONG_TIMEOUT_INTERVAL);
}
} else {
......@@ -148,9 +148,9 @@ bool SocketCommunicate::connectTcpSvr()
QLOG_ERROR() <<QString("connectTcpSvr:: Get Certificate Url: %1 , ErrorMsg: %2 , RspErrorMsg: %3 , requestErrorNum: %4 , outRspData: %5")
.arg( reqCertificateRealUrl ).arg( requestError ).arg( outCertificateJson[JSON_MSG].toString() ).arg( requestErrorNum).arg( QString(outCertificateData) );
if (requestErrorNum < 5 ) {
Sleep(2*60*1000);
Sleep(SOCKET_SHORT_TIMEOUT_INTERVAL);
} else {
Sleep(5*60*1000);
Sleep(SOCKET_LONG_TIMEOUT_INTERVAL);
}
}
......@@ -158,9 +158,9 @@ bool SocketCommunicate::connectTcpSvr()
requestErrorNum++;
QLOG_ERROR() <<QString("connectTcpSvr:: Get Certificate Url: %1 ,ErrorMsg: %2, outRspData: %3 ").arg( reqCertificateRealUrl ).arg( requestError ).arg( QString(outCertificateData) );
if (requestErrorNum < 5 ) {
Sleep(2*60*1000);
Sleep(SOCKET_SHORT_TIMEOUT_INTERVAL);
} else {
Sleep(5*60*1000);
Sleep(SOCKET_LONG_TIMEOUT_INTERVAL);
}
}
} while(1);
......@@ -181,7 +181,7 @@ bool SocketCommunicate::connectTcpSvr()
connect(this, &SocketCommunicate::quit, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(this, &SocketCommunicate::connected, &loop, &QEventLoop::quit);
timer.start(20*1000);
timer.start( SOCKET_CONNECT_TIMEOUT_INTERVAL );
loop.exec();
}
......@@ -246,7 +246,7 @@ bool SocketCommunicate::loginTcpSvr()
connect(this, &SocketCommunicate::quit, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(this, &SocketCommunicate::writeReady, &loop, &QEventLoop::quit);
timer.start(10*1000);
timer.start( SOCKET_WRITE_TIMEOUT_INTERVAL );
loop.exec();
}
......@@ -266,7 +266,7 @@ bool SocketCommunicate::loginTcpSvr()
connect(this, &SocketCommunicate::quit, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(this, &SocketCommunicate::readReady, &loop, &QEventLoop::quit);
timer.start(30*1000);
timer.start( SOCKET_START_TIMEOUT_INTERVAL );
loop.exec();
}
......@@ -335,7 +335,7 @@ void SocketCommunicate::acceptTcpSvrSendMsg()
connect(this, &SocketCommunicate::quit, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(this, &SocketCommunicate::readReady, &loop, &QEventLoop::quit);
timer.start(120*1000);
timer.start( (SOCKET_HEARTBEAT_INTERVAL + 20) *1000 );
loop.exec();
}
......@@ -346,11 +346,11 @@ void SocketCommunicate::acceptTcpSvrSendMsg()
}
QDateTime tmpCurDateTime = QDateTime::currentDateTime();
int seconds = tmpCurDateTime.secsTo(_socketHeartBeatDateTime);
if ( abs(seconds) > ( SOCKET_HEARTBEAT_INTERVAL + 20 ) ) {
if ( abs(seconds) > ( SOCKET_HEARTBEAT_INTERVAL + 10 ) ) {
QLOG_ERROR() << "acceptTcpSvrSendMsg:: Nothing Recv, Timeout , Wait Retry Connect Server...... ";
break;
} else {
QLOG_INFO() << "acceptTcpSvrSendMsg:: Nothing Recv, Continue Wait Recv Msg Because Diff Last HeartBeat Stamps< SOCKET_HEARTBEAT_INTERVAL+20, Value: " << abs(seconds);
QLOG_INFO() << "acceptTcpSvrSendMsg:: Nothing Recv, Continue Wait Recv Msg Because Diff Last HeartBeat Stamps< SOCKET_HEARTBEAT_INTERVAL+10, Value: " << abs(seconds);
continue;
}
}
......@@ -395,7 +395,7 @@ void SocketCommunicate::acceptTcpSvrSendMsg()
connect(this, &SocketCommunicate::quit, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(this, &SocketCommunicate::writeReady, &loop, &QEventLoop::quit);
timer.start(30*1000);
timer.start( SOCKET_WRITE_TIMEOUT_INTERVAL );
loop.exec();
}
......@@ -452,7 +452,7 @@ void SocketCommunicate::acceptTcpSvrSendMsg()
connect(this, &SocketCommunicate::quit, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(this, &SocketCommunicate::writeReady, &loop, &QEventLoop::quit);
timer.start(30*1000);
timer.start( SOCKET_WRITE_TIMEOUT_INTERVAL );
loop.exec();
}
QLOG_INFO() << "acceptTcpSvrSendMsg:: Socket Write OrderStatus Resp Data, Sequence: " << outDataHead.sequence <<" Len: " << len << ( _isTimeout ? " TimeOut" : " Success" ) ;
......@@ -497,7 +497,7 @@ void SocketCommunicate::acceptTcpSvrSendMsg()
connect(this, &SocketCommunicate::quit, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(this, &SocketCommunicate::writeReady, &loop, &QEventLoop::quit);
timer.start(30*1000);
timer.start( SOCKET_WRITE_TIMEOUT_INTERVAL );
loop.exec();
}
QLOG_INFO() << "acceptTcpSvrSendMsg:: Socket Write Login Resp'Resp Data (Impossible Occur), Sequence: " << outDataHead.sequence <<" Len: "<< len
......@@ -543,7 +543,7 @@ void SocketCommunicate::acceptTcpSvrSendMsg()
connect(this, &SocketCommunicate::quit, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(this, &SocketCommunicate::writeReady, &loop, &QEventLoop::quit);
timer.start(30*1000);
timer.start( SOCKET_WRITE_TIMEOUT_INTERVAL );
loop.exec();
}
QLOG_INFO() << "acceptTcpSvrSendMsg:: Socket Write Resp Undefine Msg Type Data, Sequence: " << outDataHead.sequence <<" Len: "<< len
......@@ -695,7 +695,7 @@ bool SocketCommunicate::sendSocketHeart()
connect(this, &SocketCommunicate::quit, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(this, &SocketCommunicate::writeReady, &loop, &QEventLoop::quit);
timer.start(10*1000);
timer.start( SOCKET_WRITE_TIMEOUT_INTERVAL );
loop.exec();
}
......@@ -796,9 +796,9 @@ void SocketCommunicate::threadStart()
QLOG_INFO() << QString("threadStart() This Thread Had Been Set Need Quit Flag, Now Return. ");
return;
}
QLOG_INFO() << QString("Waitting HttpLogin / openTcpChannel / GetSvrIpPort Failed, Wait 60 Seconds, _httpLoginResult:%1, _openTcpChannel:%2, _stopFlag:%3")
QLOG_INFO() << QString("Waitting HttpLogin / openTcpChannel / GetSvrIpPort Failed, Wait 30 Seconds, _httpLoginResult:%1, _openTcpChannel:%2, _stopFlag:%3")
.arg( _httpLoginResult?1:0 ).arg(_openTcpChannel?1:0).arg(_stopFlag?1:0);
Sleep(60*1000);
Sleep( SOCKET_START_TIMEOUT_INTERVAL );
FlowControl::GetInstance()._GetFcMajorInfo(_httpLoginResult, _openTcpChannel, _storeId, _localIp, _hostName,_workStationNum,_backupPos);
}
......@@ -807,11 +807,11 @@ void SocketCommunicate::threadStart()
// Reconnet Pos Agent Server Socket Rate;
if ( _reconnectTimes < 5 ) {
Sleep( 1*60*1000 );
Sleep( SOCKET_START_TIMEOUT_INTERVAL );
} else if ( _reconnectTimes < 20 ) {
Sleep( 5*60*1000 );
Sleep( SOCKET_LONG_TIMEOUT_INTERVAL );
} else {
Sleep( 10*60*1000 );
Sleep( SOCKET_SUPER_LONG_TIMEOUT_INTERVAL );
}
do {
......@@ -858,7 +858,7 @@ void SocketCommunicate::threadStart()
{
QEventLoop loop;
connect(this, &SocketCommunicate::quit, &loop,&QEventLoop::quit);
QTimer::singleShot(60000, &loop, SLOT(quit()));
QTimer::singleShot(30000, &loop, SLOT(quit()));
loop.exec();
}
......
......@@ -1511,13 +1511,12 @@ bool FlowControl::_PullOrderList( const int &pageSize, const int &pageNo, const
QJsonObject recvJson;
int ordertotalSum;
sendJson = DataManger::GetInstance().GetPullOrderListData(pageNo,pageSize);
sendJson.insert(JSON_POS_BACKUP_PC, m_backupPosFlag);
QLOG_INFO() << QString("[<<<<---FlowControl::_PullOrderList: Pull Order List--->>>>][requestData:]")<<sendJson;
QLOG_INFO() << QString("[<<<<---FlowControl::_PullOrderList: Pull Order List--->>>>]");
if(ConfigManger::GetInstance().GetOrderSslConfig()) {
m_pullOrderListSocket->SetSslConfig();
QLOG_INFO()<<"FlowControl::_PullOrderList load ssl";
} else {
QLOG_INFO()<<"FlowControl::_PullOrderList load not ssl";
}
if ( callBackUrl.length() ) {
......
......@@ -214,7 +214,19 @@
// 长连接Get请求超时 设置为 10s
#define SOCKET_GET_TIMEOUT 10000
// 长连接 向 POS Agent Server 发送心跳时间间隔(单位: 秒);
#define SOCKET_HEARTBEAT_INTERVAL 80
#define SOCKET_HEARTBEAT_INTERVAL 70
// 建立连接超时时间(单位: 毫秒);
#define SOCKET_CONNECT_TIMEOUT_INTERVAL 20*1000
// 写报文超时时间(单位: 毫秒);
#define SOCKET_WRITE_TIMEOUT_INTERVAL 15*1000
// 启动超时时间(单位: 毫秒);
#define SOCKET_START_TIMEOUT_INTERVAL 1*30*1000
// 短超时时间(单位: 毫秒);
#define SOCKET_SHORT_TIMEOUT_INTERVAL 2*30*1000
// 长超时时间(单位: 毫秒);
#define SOCKET_LONG_TIMEOUT_INTERVAL 5*30*1000
// 超长超时时间(单位: 毫秒);
#define SOCKET_SUPER_LONG_TIMEOUT_INTERVAL 10*30*1000
// ssl证书相关宏;
#define DES3_KEY_SIZE 24
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment