|
@@ -62,14 +62,12 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
|
|
|
m_strRvcWebVersion = szVersion;
|
|
|
|
|
|
// 立刻同步配置
|
|
|
- //BeginDownloadCenterSetting();
|
|
|
pFunc->PostEntityTaskFIFO(new DownloadCenterSettingsTask(this));
|
|
|
|
|
|
// 启动轮询定时器 5min
|
|
|
GetFunction()->SetTimer(DOWNLOAD_CENTERSETTINGS_TIMER_ID, this, DOWNLOAD_CENTERSETTINGS_TIMER_INTERVAL);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void CCenterSettingEntity::OnTimeout(DWORD dwTimerID)
|
|
|
{
|
|
|
BeginDownloadCenterSetting();
|
|
@@ -82,23 +80,30 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
|
|
|
pTransactionContext->SendAnswer(Error_Succeed);
|
|
|
}
|
|
|
|
|
|
- ErrorCodeEnum CCenterSettingEntity::BeginDownloadCenterSetting()
|
|
|
+ ErrorCodeEnum CCenterSettingEntity::BeginDownloadCenterSetting(LPCTSTR serverIP, int port)
|
|
|
{
|
|
|
- if (!SecureClientConnect(false))
|
|
|
- {
|
|
|
- m_nConnectFailCount++;
|
|
|
- if (m_nConnectFailCount < 20)
|
|
|
- return Error_NetBroken;
|
|
|
+ LOG_FUNCTION();
|
|
|
|
|
|
- // 10分钟连接不上,切换到备用地址
|
|
|
- Dbg("connect fail more than 10 min, now use backup config");
|
|
|
- if (!SecureClientConnect(true))
|
|
|
+ if (serverIP != NULL && strlen(serverIP) > 0 && port > 0) {
|
|
|
+ if (!SecureClientConnect(ConnectServerType::PARAM, serverIP, port)) {
|
|
|
return Error_NetBroken;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!SecureClientConnect(ConnectServerType::DEFAULT)) {
|
|
|
+ m_nConnectFailCount++;
|
|
|
+ if (m_nConnectFailCount < 20)
|
|
|
+ return Error_NetBroken;
|
|
|
+
|
|
|
+ // 10分钟连接不上,切换到备用地址
|
|
|
+ Dbg("connect fail more than 10 min, now use backup config");
|
|
|
+ if (!SecureClientConnect(ConnectServerType::BACKUP))
|
|
|
+ return Error_NetBroken;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
m_nConnectFailCount = 0;
|
|
|
//Dbg("begin poll center setting");
|
|
|
- assert(m_pConnection != NULL && m_pConnection->IsConnectionOK());
|
|
|
+ LOG_ASSERT(IsServerConnectedNow());
|
|
|
auto rc = m_pConnection->BeginPollConfig();
|
|
|
return rc;
|
|
|
}
|
|
@@ -133,7 +138,15 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
|
|
|
}
|
|
|
|
|
|
m_spDownloadCall = sp;
|
|
|
- BeginDownloadCenterSetting();
|
|
|
+ ErrorCodeEnum error = (sp != NULL ? BeginDownloadCenterSetting(sp->Req.strAddr, sp->Req.nPort) : BeginDownloadCenterSetting());
|
|
|
+ if (error == Error_NetBroken) {
|
|
|
+ m_spDownloadCall = nullptr;
|
|
|
+ if (sp != NULL) {
|
|
|
+ sp->Answer(Error_Unexpect);
|
|
|
+ }
|
|
|
+ return error;
|
|
|
+ }
|
|
|
+
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
@@ -183,17 +196,21 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- bool CCenterSettingEntity::SecureClientConnect(bool bUseBackup)
|
|
|
+ bool CCenterSettingEntity::SecureClientConnect(ConnectServerType type, LPCTSTR serverIP, int port)
|
|
|
{
|
|
|
- if (m_pConnection!=NULL && m_pConnection->IsConnectionOK())
|
|
|
+ LOG_FUNCTION();
|
|
|
+ Dbg("%d, %s, %d", type, serverIP, port);
|
|
|
+
|
|
|
+ if (type == ConnectServerType::DEFAULT && IsServerConnectedNow())
|
|
|
return true;
|
|
|
|
|
|
SecureClientRelease();
|
|
|
- m_bUseBackupNow = bUseBackup;
|
|
|
+
|
|
|
+ m_bUseBackupNow = (type == ConnectServerType::BACKUP);
|
|
|
|
|
|
m_pConnection = new CCenterSettingConn(this);
|
|
|
|
|
|
- if (bUseBackup)
|
|
|
+ if (m_bUseBackupNow)
|
|
|
{
|
|
|
CSmartPointer<IConfigInfo> pConfig;
|
|
|
auto rc = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
|
|
@@ -216,9 +233,13 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
|
|
|
}
|
|
|
|
|
|
return m_pConnection->Connect(strIP, nPort, 3);
|
|
|
+
|
|
|
+ } else if(type == ConnectServerType::PARAM)
|
|
|
+ {
|
|
|
+ Dbg("custom download from server %s:%d", serverIP, port);
|
|
|
+ return m_pConnection->Connect(serverIP, port, 3);
|
|
|
}
|
|
|
- else
|
|
|
- return m_pConnection->ConnectFromCentralSetting();
|
|
|
+ return m_pConnection->ConnectFromCentralSetting();
|
|
|
}
|
|
|
|
|
|
void CCenterSettingEntity::SecureClientRelease()
|