Skip to content

Commit d485a84

Browse files
committed
Modify:Support setting the number of retry errors
1 parent 9e428be commit d485a84

File tree

11 files changed

+84
-56
lines changed

11 files changed

+84
-56
lines changed

XEngine_Source/StorageModule_Config/Config_Define.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ typedef struct tag_XEngine_ServerConfig
8484
}st_XProxy;
8585
struct
8686
{
87-
BOOL bAutoSpeed;
8887
int nDLTry;
88+
int nDLError;
8989
__int64x nMaxUPLoader;
9090
__int64x nMaxDNLoader;
9191
}st_XLimit;

XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ BOOL CConfig_Json::Config_Json_File(LPCTSTR lpszConfigFile,XENGINE_SERVERCONFIG
162162
return FALSE;
163163
}
164164
Json::Value st_JsonXLimit = st_JsonRoot["XLimit"];
165-
pSt_ServerConfig->st_XLimit.bAutoSpeed = st_JsonXLimit["bAutoSpeed"].asUInt();
166165
pSt_ServerConfig->st_XLimit.nDLTry = st_JsonXLimit["nDLTry"].asUInt();
166+
pSt_ServerConfig->st_XLimit.nDLError = st_JsonXLimit["nDLError"].asUInt();
167167
pSt_ServerConfig->st_XLimit.nMaxDNLoader = st_JsonXLimit["nMaxDNLoad"].asInt64();
168168
pSt_ServerConfig->st_XLimit.nMaxUPLoader = st_JsonXLimit["nMaxUPLoad"].asInt64();
169169

XEngine_Source/StorageModule_Session/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ CC = g++ -Wall -std=c++17 -fPIC
22
RELEASE = 0
33
UNICODE = 0
44
INCLUDE = -I ./
5-
LOADBIN =
6-
LIB =
5+
LOADBIN = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib
6+
LIB = -lXEngine_BaseLib
77
LIBEX = -static-libgcc -lrt -ldl -lpthread
88
LOADSO = -Wl,-rpath=
99
LIBINCLUDE = Session_DLStroage.o Session_UPStroage.o Session_User.o pch.o

XEngine_Source/StorageModule_Session/Session_Define.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
//////////////////////////////////////////////////////////////////////////
1616
typedef struct
1717
{
18+
ULONGLONG ullTimeSend; //最后发送时间
19+
ULONGLONG ullTimeWait; //等待恢复时间,单位毫秒
1820
time_t nTimeError; //最后错误时间
19-
time_t nTimeSend; //最后发送时间
2021
int nErrorCount; //错误次数
21-
int nTimeWait; //等待恢复时间,单位秒
22+
int nAutoNumber; //恢复次数
2223
}SESSION_STORAGEDYNAMICRATE;
2324
typedef struct
2425
{
@@ -97,17 +98,17 @@ extern "C" BOOL Session_User_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass);
9798
类型:整数型
9899
可空:Y
99100
意思:输入重试次数
100-
参数.三:bAutoSpeed
101+
参数.三:nAutoSpeed
101102
In/Out:In
102-
类型:逻辑型
103+
类型:整数型
103104
可空:Y
104-
意思:是否允许恢复速度
105+
意思:输入恢复次数,超过次数不在恢复
105106
返回值
106107
类型:逻辑型
107108
意思:是否成功
108109
备注:
109110
*********************************************************************/
110-
extern "C" BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3, BOOL bAutoSpeed = TRUE);
111+
extern "C" BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3, int nAutoSpeed = 3);
111112
/********************************************************************
112113
函数名称:Session_DLStroage_Destory
113114
函数功能:销毁下载管理器

XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*********************************************************************/
1414
CSession_DLStroage::CSession_DLStroage()
1515
{
16-
m_nTryTime = 3;
1716
}
1817
CSession_DLStroage::~CSession_DLStroage()
1918
{
@@ -32,14 +31,19 @@ CSession_DLStroage::~CSession_DLStroage()
3231
参数.二:nTryTime
3332
In/Out:In
3433
类型:整数型
35-
可空:N
34+
可空:Y
3635
意思:输入重试次数
36+
参数.三:nAutoSpeed
37+
In/Out:In
38+
类型:整数型
39+
可空:Y
40+
意思:输入恢复次数,超过次数不在恢复
3741
返回值
3842
类型:逻辑型
3943
意思:是否成功
4044
备注:
4145
*********************************************************************/
42-
BOOL CSession_DLStroage::Session_DLStroage_Init(int nPoolCount /* = 1 */, int nTryTime /* = 3 */, BOOL bAutoSpeed /* = TRUE */)
46+
BOOL CSession_DLStroage::Session_DLStroage_Init(int nPoolCount /* = 1 */, int nTryTime /* = 3 */, int nAutoSpeed /* = 3 */)
4347
{
4448
Session_IsErrorOccur = FALSE;
4549

@@ -55,7 +59,7 @@ BOOL CSession_DLStroage::Session_DLStroage_Init(int nPoolCount /* = 1 */, int nT
5559
st_Locker.unlock();
5660
}
5761
m_nTryTime = nTryTime;
58-
m_bAutoSpeed = bAutoSpeed;
62+
m_nTryAuto = nAutoSpeed;
5963
return TRUE;
6064
}
6165
/********************************************************************
@@ -405,28 +409,32 @@ BOOL CSession_DLStroage::Session_DLStroage_GetCount(int nPool, list<string>* pSt
405409
for (; stl_ListIterator != stl_MapIterator->second.pStl_ListStorage->end(); stl_ListIterator++)
406410
{
407411
//是否需要等待恢复
408-
if (stl_ListIterator->st_DynamicRate.nTimeWait > 0)
412+
if (stl_ListIterator->st_DynamicRate.ullTimeWait > 0)
409413
{
410414
time_t nTimeNow = time(NULL);
411-
if ((stl_ListIterator->st_DynamicRate.nTimeSend > 0) && ((nTimeNow - stl_ListIterator->st_DynamicRate.nTimeSend) > stl_ListIterator->st_DynamicRate.nTimeWait))
415+
ULONGLONG ullTimeNow = BaseLib_OperatorTime_GetTickCount();
416+
if (((ullTimeNow - stl_ListIterator->st_DynamicRate.ullTimeSend) > stl_ListIterator->st_DynamicRate.ullTimeWait) && ((nTimeNow - stl_ListIterator->st_DynamicRate.nTimeError) > 1))
412417
{
413418
//等待时间超过,可以加入
414419
pStl_ListClient->push_back(stl_ListIterator->tszClientAddr);
415-
printf("1-m_bAutoSpeed:%d,nTimeNow:%ld nTimeSend:%ld nTimeWait:%d\n", m_bAutoSpeed, nTimeNow, stl_ListIterator->st_DynamicRate.nTimeSend, stl_ListIterator->st_DynamicRate.nTimeWait);
420+
stl_ListIterator->st_DynamicRate.ullTimeSend = BaseLib_OperatorTime_GetTickCount();
416421
}
417422
//速率恢复测算
418-
if (m_bAutoSpeed && ((nTimeNow - stl_ListIterator->st_DynamicRate.nTimeError) > (stl_ListIterator->st_DynamicRate.nErrorCount * 2)))
423+
if ((stl_ListIterator->st_DynamicRate.nAutoNumber <= m_nTryAuto) && ((nTimeNow - stl_ListIterator->st_DynamicRate.nTimeError) > (stl_ListIterator->st_DynamicRate.nErrorCount * stl_ListIterator->st_DynamicRate.nAutoNumber)))
419424
{
420-
printf("2-m_bAutoSpeed:%d,nTimeNow:%ld - nTimeError:%ld nErrorCount:%d\n", m_bAutoSpeed, nTimeNow, stl_ListIterator->st_DynamicRate.nTimeError, stl_ListIterator->st_DynamicRate.nErrorCount * 2);
425+
printf("2-m_bAutoSpeed:%d,ullTimeNow:%llu - nTimeError:%llu nErrorCount:%lu\n", m_nTryAuto, nTimeNow, stl_ListIterator->st_DynamicRate.nTimeError, stl_ListIterator->st_DynamicRate.nErrorCount * 2);
426+
stl_ListIterator->st_DynamicRate.nAutoNumber++;
421427
stl_ListIterator->st_DynamicRate.nErrorCount--;
422-
stl_ListIterator->st_DynamicRate.nTimeError = time(NULL);
428+
stl_ListIterator->st_DynamicRate.ullTimeWait -= XENGINE_STOREAGE_SESSION_DOWNLOAD_SENDTIME;
423429
if (0 == stl_ListIterator->st_DynamicRate.nErrorCount)
424430
{
425-
stl_ListIterator->st_DynamicRate.nTimeWait = 0;
426431
stl_ListIterator->st_DynamicRate.nTimeError = 0;
427432
}
433+
else
434+
{
435+
stl_ListIterator->st_DynamicRate.nTimeError = nTimeNow;
436+
}
428437
}
429-
stl_ListIterator->st_DynamicRate.nTimeSend = nTimeNow;
430438
}
431439
else
432440
{
@@ -483,11 +491,12 @@ BOOL CSession_DLStroage::Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int n
483491
bFound = TRUE;
484492
if (bError)
485493
{
486-
stl_ListIterator->st_DynamicRate.nErrorCount++;
487-
stl_ListIterator->st_DynamicRate.nTimeError = time(NULL);
488-
//那么根据错误次数计算等待时间
489-
stl_ListIterator->st_DynamicRate.nTimeWait = stl_ListIterator->st_DynamicRate.nErrorCount;
490-
494+
if ((time(NULL) - stl_ListIterator->st_DynamicRate.nTimeError) > 1)
495+
{
496+
stl_ListIterator->st_DynamicRate.nErrorCount++;
497+
stl_ListIterator->st_DynamicRate.nTimeError = time(NULL);
498+
stl_ListIterator->st_DynamicRate.ullTimeWait += XENGINE_STOREAGE_SESSION_DOWNLOAD_SENDTIME;
499+
}
491500
if (NULL != pSt_StorageRate)
492501
{
493502
*pSt_StorageRate = stl_ListIterator->st_DynamicRate;

XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// Purpose: 存储下载会话
1111
// History:
1212
*********************************************************************/
13+
#define XENGINE_STOREAGE_SESSION_DOWNLOAD_SENDTIME 1
14+
1315
typedef struct
1416
{
1517
shared_ptr<shared_mutex> st_Locker;
@@ -22,7 +24,7 @@ class CSession_DLStroage
2224
CSession_DLStroage();
2325
~CSession_DLStroage();
2426
public:
25-
BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3, BOOL bAutoSpeed = TRUE);
27+
BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3, int nAutoSpeed = 3);
2628
BOOL Session_DLStroage_Destory();
2729
BOOL Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x* pInt_Count, __int64x* pInt_LeftCount, int nPosStart = 0, int nPostEnd = 0);
2830
BOOL Session_DLStroage_GetList(int nPool, LPCTSTR lpszClientAddr, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
@@ -32,8 +34,8 @@ class CSession_DLStroage
3234
BOOL Session_DLStroage_Delete(LPCTSTR lpszClientAddr);
3335
private:
3436
int m_nTryTime;
35-
BOOL m_bAutoSpeed;
37+
int m_nTryAuto;
3638
shared_mutex st_Locker;
3739
private:
3840
unordered_map<int, SESSION_STORAGELIST> stl_MapStroage;
39-
};
41+
};

XEngine_Source/StorageModule_Session/pch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ extern "C" BOOL Session_User_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass)
4848
/************************************************************************/
4949
/* 存储会话导出的函数 */
5050
/************************************************************************/
51-
extern "C" BOOL Session_DLStroage_Init(int nPoolCount, int nTryTime, BOOL bAutoSpeed)
51+
extern "C" BOOL Session_DLStroage_Init(int nPoolCount, int nTryTime, int nAutoSpeed)
5252
{
53-
return m_DLStorage.Session_DLStroage_Init(nPoolCount, nTryTime, bAutoSpeed);
53+
return m_DLStorage.Session_DLStroage_Init(nPoolCount, nTryTime, nAutoSpeed);
5454
}
5555
extern "C" BOOL Session_DLStroage_Destory()
5656
{

XEngine_Source/StorageModule_Session/pch.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ using namespace std;
3030
#include <XEngine_Include/XEngine_CommHdr.h>
3131
#include <XEngine_Include/XEngine_Types.h>
3232
#include <XEngine_Include/XEngine_ProtocolHdr.h>
33+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
34+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
3335
#include "Session_Define.h"
3436
#include "Session_Error.h"
3537
/********************************************************************
@@ -50,4 +52,12 @@ extern DWORD Session_dwErrorCode;
5052
typedef std::wstring tstring;
5153
#else
5254
typedef std::string tstring;
55+
#endif
56+
57+
#ifdef _WINDOWS
58+
#ifdef _WIN64
59+
#pragma comment(lib,"x64/XEngine_BaseLib/XEngine_BaseLib.lib")
60+
#else
61+
#pragma comment(lib,"x86/XEngine_BaseLib/XEngine_BaseLib.lib")
62+
#endif
5363
#endif

XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ BOOL XEngine_Task_SendDownload(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in
204204

205205
if (Session_DLStorage_SetSeek(lpszClientAddr, -nMsgLen, TRUE, &st_StorageRate))
206206
{
207-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("下载客户端:%s,正在发送文件数据,发送失败,移动指针:%d,错误次数:%d,等待时间:%d 秒"), lpszClientAddr, -nMsgLen, st_StorageRate.nErrorCount, st_StorageRate.nTimeWait);
207+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("下载客户端:%s,正在发送文件数据,发送失败,移动指针:%d,错误次数:%d,等待时间:%llu 毫秒,恢复次数:%d"), lpszClientAddr, -nMsgLen, st_StorageRate.nErrorCount, st_StorageRate.ullTimeWait, st_StorageRate.nAutoNumber);
208208
}
209209
else
210210
{
211211
XEngine_Net_CloseClient(lpszClientAddr, STORAGE_LEAVETYPE_CLOSE, STORAGE_NETTYPE_HTTPDOWNLOAD);
212-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,正在发送文件数据,大小:%d,发送超过重试次数,无法继续,移除发送队列,错误次数:%d,等待时间:%d 秒"), lpszClientAddr, nMsgLen, st_StorageRate.nErrorCount, st_StorageRate.nTimeWait);
212+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,正在发送文件数据,大小:%d,发送超过重试次数,无法继续,移除发送队列,错误次数:%d,等待时间:%llu 毫秒,恢复次数:%d"), lpszClientAddr, nMsgLen, st_StorageRate.nErrorCount, st_StorageRate.ullTimeWait, st_StorageRate.nAutoNumber);
213213
}
214214
}
215215
return TRUE;

XEngine_Source/XEngine_StorageApp/StorageApp_Network.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,33 +172,39 @@ BOOL XEngine_Net_SendMsg(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsg
172172
{
173173
SocketOpt_HeartBeat_ActiveAddrEx(xhHBDownload, lpszClientAddr);
174174
}
175-
}
176-
else if (STORAGE_NETTYPE_HTTPUPLOADER == nType)
177-
{
178-
bRet = NetCore_TCPXCore_SendEx(xhNetUPLoader, lpszClientAddr, lpszMsgBuffer, nMsgLen);
179-
if (bRet && st_ServiceCfg.st_XTime.bHBTime)
175+
if (!bRet)
180176
{
181-
SocketOpt_HeartBeat_ActiveAddrEx(xhHBUPLoader, lpszClientAddr);
177+
return FALSE;
182178
}
183179
}
184-
else if (STORAGE_NETTYPE_HTTPCENTER == nType)
185-
{
186-
bRet = NetCore_TCPXCore_SendEx(xhNetCenter, lpszClientAddr, lpszMsgBuffer, nMsgLen);
187-
}
188-
else if (STORAGE_NETTYPE_TCPP2XP == nType)
180+
else
189181
{
190-
bRet = NetCore_TCPXCore_SendEx(xhNetP2xp, lpszClientAddr, lpszMsgBuffer, nMsgLen);
191-
if (bRet && st_ServiceCfg.st_XTime.bHBTime)
182+
if (STORAGE_NETTYPE_HTTPUPLOADER == nType)
192183
{
193-
SocketOpt_HeartBeat_ActiveAddrEx(xhHBP2xp, lpszClientAddr);
184+
bRet = NetCore_TCPXCore_SendEx(xhNetUPLoader, lpszClientAddr, lpszMsgBuffer, nMsgLen);
185+
if (bRet && st_ServiceCfg.st_XTime.bHBTime)
186+
{
187+
SocketOpt_HeartBeat_ActiveAddrEx(xhHBUPLoader, lpszClientAddr);
188+
}
189+
}
190+
else if (STORAGE_NETTYPE_HTTPCENTER == nType)
191+
{
192+
bRet = NetCore_TCPXCore_SendEx(xhNetCenter, lpszClientAddr, lpszMsgBuffer, nMsgLen);
193+
}
194+
else if (STORAGE_NETTYPE_TCPP2XP == nType)
195+
{
196+
bRet = NetCore_TCPXCore_SendEx(xhNetP2xp, lpszClientAddr, lpszMsgBuffer, nMsgLen);
197+
if (bRet && st_ServiceCfg.st_XTime.bHBTime)
198+
{
199+
SocketOpt_HeartBeat_ActiveAddrEx(xhHBP2xp, lpszClientAddr);
200+
}
201+
}
202+
if (!bRet)
203+
{
204+
DWORD dwRet = NetCore_GetLastError();
205+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("客户端:%s,网络类型:%d,发送数据失败,发送大小:%d,错误:%lX,%d"), lpszClientAddr, nType, nMsgLen, dwRet, errno);
206+
return FALSE;
194207
}
195-
}
196-
197-
if (!bRet)
198-
{
199-
DWORD dwRet = NetCore_GetLastError();
200-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("客户端:%s,网络类型:%d,发送数据失败,发送大小:%d,错误:%lX,%d"), lpszClientAddr, nType, nMsgLen, dwRet, errno);
201-
return FALSE;
202208
}
203209
return TRUE;
204210
}

0 commit comments

Comments
 (0)