Skip to content

Commit 9e428be

Browse files
committed
fixed:Auto speed not work
1 parent dab25d3 commit 9e428be

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

XEngine_Source/StorageModule_Session/Session_Define.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
typedef struct
1717
{
1818
time_t nTimeError; //最后错误时间
19+
time_t nTimeSend; //最后发送时间
1920
int nErrorCount; //错误次数
2021
int nTimeWait; //等待恢复时间,单位秒
2122
}SESSION_STORAGEDYNAMICRATE;
@@ -94,14 +95,19 @@ extern "C" BOOL Session_User_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass);
9495
参数.二:nTryTime
9596
In/Out:In
9697
类型:整数型
97-
可空:N
98+
可空:Y
9899
意思:输入重试次数
100+
参数.三:bAutoSpeed
101+
In/Out:In
102+
类型:逻辑型
103+
可空:Y
104+
意思:是否允许恢复速度
99105
返回值
100106
类型:逻辑型
101107
意思:是否成功
102108
备注:
103109
*********************************************************************/
104-
extern "C" BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3);
110+
extern "C" BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3, BOOL bAutoSpeed = TRUE);
105111
/********************************************************************
106112
函数名称:Session_DLStroage_Destory
107113
函数功能:销毁下载管理器

XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CSession_DLStroage::~CSession_DLStroage()
3939
意思:是否成功
4040
备注:
4141
*********************************************************************/
42-
BOOL CSession_DLStroage::Session_DLStroage_Init(int nPoolCount /* = 1 */, int nTryTime /* = 3 */)
42+
BOOL CSession_DLStroage::Session_DLStroage_Init(int nPoolCount /* = 1 */, int nTryTime /* = 3 */, BOOL bAutoSpeed /* = TRUE */)
4343
{
4444
Session_IsErrorOccur = FALSE;
4545

@@ -54,6 +54,8 @@ BOOL CSession_DLStroage::Session_DLStroage_Init(int nPoolCount /* = 1 */, int nT
5454
stl_MapStroage.insert(make_pair(i, st_StorageList));
5555
st_Locker.unlock();
5656
}
57+
m_nTryTime = nTryTime;
58+
m_bAutoSpeed = bAutoSpeed;
5759
return TRUE;
5860
}
5961
/********************************************************************
@@ -406,21 +408,25 @@ BOOL CSession_DLStroage::Session_DLStroage_GetCount(int nPool, list<string>* pSt
406408
if (stl_ListIterator->st_DynamicRate.nTimeWait > 0)
407409
{
408410
time_t nTimeNow = time(NULL);
409-
if ((nTimeNow - stl_ListIterator->st_DynamicRate.nTimeError) > stl_ListIterator->st_DynamicRate.nTimeWait)
411+
if ((stl_ListIterator->st_DynamicRate.nTimeSend > 0) && ((nTimeNow - stl_ListIterator->st_DynamicRate.nTimeSend) > stl_ListIterator->st_DynamicRate.nTimeWait))
410412
{
411413
//等待时间超过,可以加入
412414
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);
413416
}
414417
//速率恢复测算
415-
if ((nTimeNow - stl_ListIterator->st_DynamicRate.nTimeError) > (stl_ListIterator->st_DynamicRate.nErrorCount * 2))
418+
if (m_bAutoSpeed && ((nTimeNow - stl_ListIterator->st_DynamicRate.nTimeError) > (stl_ListIterator->st_DynamicRate.nErrorCount * 2)))
416419
{
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);
417421
stl_ListIterator->st_DynamicRate.nErrorCount--;
422+
stl_ListIterator->st_DynamicRate.nTimeError = time(NULL);
418423
if (0 == stl_ListIterator->st_DynamicRate.nErrorCount)
419424
{
420425
stl_ListIterator->st_DynamicRate.nTimeWait = 0;
421426
stl_ListIterator->st_DynamicRate.nTimeError = 0;
422427
}
423428
}
429+
stl_ListIterator->st_DynamicRate.nTimeSend = nTimeNow;
424430
}
425431
else
426432
{
@@ -477,15 +483,10 @@ BOOL CSession_DLStroage::Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int n
477483
bFound = TRUE;
478484
if (bError)
479485
{
480-
time_t nTimeNow = time(NULL);
481-
//如果发送错误事件小于等于1秒
482-
if ((nTimeNow - stl_ListIterator->st_DynamicRate.nTimeError) <= 1)
483-
{
484-
//那么根据错误次数计算等待时间
485-
stl_ListIterator->st_DynamicRate.nTimeWait = stl_ListIterator->st_DynamicRate.nErrorCount + 1;
486-
}
487486
stl_ListIterator->st_DynamicRate.nErrorCount++;
488487
stl_ListIterator->st_DynamicRate.nTimeError = time(NULL);
488+
//那么根据错误次数计算等待时间
489+
stl_ListIterator->st_DynamicRate.nTimeWait = stl_ListIterator->st_DynamicRate.nErrorCount;
489490

490491
if (NULL != pSt_StorageRate)
491492
{

XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CSession_DLStroage
2222
CSession_DLStroage();
2323
~CSession_DLStroage();
2424
public:
25-
BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3);
25+
BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3, BOOL bAutoSpeed = TRUE);
2626
BOOL Session_DLStroage_Destory();
2727
BOOL Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x* pInt_Count, __int64x* pInt_LeftCount, int nPosStart = 0, int nPostEnd = 0);
2828
BOOL Session_DLStroage_GetList(int nPool, LPCTSTR lpszClientAddr, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
@@ -32,6 +32,7 @@ class CSession_DLStroage
3232
BOOL Session_DLStroage_Delete(LPCTSTR lpszClientAddr);
3333
private:
3434
int m_nTryTime;
35+
BOOL m_bAutoSpeed;
3536
shared_mutex st_Locker;
3637
private:
3738
unordered_map<int, SESSION_STORAGELIST> stl_MapStroage;

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)
51+
extern "C" BOOL Session_DLStroage_Init(int nPoolCount, int nTryTime, BOOL bAutoSpeed)
5252
{
53-
return m_DLStorage.Session_DLStroage_Init(nPoolCount, nTryTime);
53+
return m_DLStorage.Session_DLStroage_Init(nPoolCount, nTryTime, bAutoSpeed);
5454
}
5555
extern "C" BOOL Session_DLStroage_Destory()
5656
{

XEngine_Source/XEngine_StorageApp/StorageApp_Network.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ BOOL XEngine_Net_SendMsg(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsg
163163

164164
if (STORAGE_NETTYPE_HTTPDOWNLOAD == nType)
165165
{
166+
#if ((XENGINE_VERSION_KERNEL >= 7) && (XENGINE_VERSION_MAIN > 18))
167+
bRet = NetCore_TCPXCore_SendEx(xhNetDownload, lpszClientAddr, lpszMsgBuffer, nMsgLen, 0, 10);
168+
#else
166169
bRet = NetCore_TCPXCore_SendEx(xhNetDownload, lpszClientAddr, lpszMsgBuffer, nMsgLen);
170+
#endif
167171
if (bRet && st_ServiceCfg.st_XTime.bHBTime)
168172
{
169173
SocketOpt_HeartBeat_ActiveAddrEx(xhHBDownload, lpszClientAddr);

XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ int main(int argc, char** argv)
256256
goto XENGINE_EXITAPP;
257257
}
258258
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动用户管理服务成功"));
259-
if (!Session_DLStroage_Init(st_ServiceCfg.st_XMax.nStorageDLThread))
259+
if (!Session_DLStroage_Init(st_ServiceCfg.st_XMax.nStorageDLThread, st_ServiceCfg.st_XLimit.nDLTry, st_ServiceCfg.st_XLimit.bAutoSpeed))
260260
{
261261
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务器中,启动下载会话服务失败,错误:%lX"), Session_GetLastError());
262262
goto XENGINE_EXITAPP;

0 commit comments

Comments
 (0)