Skip to content

Commit 902ed85

Browse files
committed
delete:auto error with download
1 parent 3b7d796 commit 902ed85

File tree

5 files changed

+36
-111
lines changed

5 files changed

+36
-111
lines changed

XEngine_Source/StorageModule_Session/Session_Define.h

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,14 @@
1515
//////////////////////////////////////////////////////////////////////////
1616
typedef struct
1717
{
18-
ULONGLONG ullTimeSend; //最后发送时间
19-
ULONGLONG ullTimeWait; //等待恢复时间,单位毫秒
20-
time_t nTimeError; //最后错误时间
21-
int nErrorCount; //错误次数
22-
int nAutoNumber; //恢复次数
23-
}SESSION_STORAGEDYNAMICRATE;
24-
typedef struct
25-
{
26-
SESSION_STORAGEDYNAMICRATE st_DynamicRate;
2718
TCHAR tszFileDir[MAX_PATH]; //文件地址
2819
TCHAR tszClientAddr[128]; //操作的用户地址
2920
__int64x ullCount; //总大小
3021
__int64x ullRWCount; //读取(写入)总大小
3122
__int64x ullRWLen; //已经读取(写入)的大小
3223
__int64x ullPosStart; //开始位置
3324
__int64x ullPosEnd; //结束位置
25+
int nErrorTime; //错误次数
3426
FILE* pSt_File;
3527
}SESSION_STORAGEINFO;
3628
//////////////////////////////////////////////////////////////////////////
@@ -92,18 +84,13 @@ extern "C" BOOL Session_User_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass);
9284
In/Out:In
9385
类型:整数型
9486
可空:Y
95-
意思:输入重试次数
96-
参数.二:nAutoSpeed
97-
In/Out:In
98-
类型:整数型
99-
可空:Y
100-
意思:输入恢复次数,超过次数不在恢复
87+
意思:输入下载错误重试次数
10188
返回值
10289
类型:逻辑型
10390
意思:是否成功
10491
备注:
10592
*********************************************************************/
106-
extern "C" BOOL Session_DLStroage_Init(int nTryTime = 3, int nAutoSpeed = 3);
93+
extern "C" BOOL Session_DLStroage_Init(int nTryTime = 3);
10794
/********************************************************************
10895
函数名称:Session_DLStroage_Destory
10996
函数功能:销毁下载管理器
@@ -197,17 +184,17 @@ extern "C" BOOL Session_DLStroage_GetInfo(LPCTSTR lpszClientAddr, SESSION_STORAG
197184
/********************************************************************
198185
函数名称:Session_DLStroage_GetCount
199186
函数功能:获取队列拥有的个数
200-
参数.一:pStl_ListClient
187+
参数.一:pInt_ListCount
201188
In/Out:Out
202-
类型:STL容器指针
189+
类型:整数型
203190
可空:N
204191
意思:输出要发送的队列个数
205192
返回值
206193
类型:逻辑型
207194
意思:是否成功
208195
备注:
209196
*********************************************************************/
210-
extern "C" BOOL Session_DLStroage_GetCount(list<string>*pStl_ListClient);
197+
extern "C" BOOL Session_DLStroage_GetCount(int* pInt_ListCount);
211198
/********************************************************************
212199
函数名称:Session_DLStorage_SetSeek
213200
函数功能:移动文件指针
@@ -225,18 +212,13 @@ extern "C" BOOL Session_DLStroage_GetCount(list<string>*pStl_ListClient);
225212
In/Out:In
226213
类型:逻辑型
227214
可空:Y
228-
意思:是否因为错误引起的
229-
参数.四:pSt_StorageRate
230-
In/Out:In
231-
类型:数据结构指针
232-
可空:Y
233-
意思:输出速率错误信息
215+
意思:是否有由错误引起的
234216
返回值
235217
类型:逻辑型
236218
意思:是否成功
237219
备注:
238220
*********************************************************************/
239-
extern "C" BOOL Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek, BOOL bError = TRUE, SESSION_STORAGEDYNAMICRATE * pSt_StorageRate = NULL);
221+
extern "C" BOOL Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek, BOOL bError = TRUE);
240222
/********************************************************************
241223
函数名称:Session_DLStorage_GetAll
242224
函数功能:获取下载池的任务列表

XEngine_Source/StorageModule_Session/Session_Error.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
#define ERROR_STORAGE_MODULE_SESSION_OPENFILE 0x0010003
1919
#define ERROR_STORAGE_MODULE_SESSION_NOTFOUND 0x0010004
2020
#define ERROR_STORAGE_MODULE_SESSION_PASSWORD 0x0010005
21-
#define ERROR_STORAGE_MODULE_SESSION_EMPTY 0x0010006
21+
#define ERROR_STORAGE_MODULE_SESSION_EMPTY 0x0010006
22+
#define ERROR_STORAGE_MODULE_SESSION_ERRORTIME 0x0010007

XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.cpp

Lines changed: 17 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,17 @@ CSession_DLStroage::~CSession_DLStroage()
2727
In/Out:In
2828
类型:整数型
2929
可空:Y
30-
意思:输入重试次数
31-
参数.二:nAutoSpeed
32-
In/Out:In
33-
类型:整数型
34-
可空:Y
35-
意思:输入恢复次数,超过次数不在恢复
30+
意思:输入下载错误重试次数
3631
返回值
3732
类型:逻辑型
3833
意思:是否成功
3934
备注:
4035
*********************************************************************/
41-
BOOL CSession_DLStroage::Session_DLStroage_Init(int nTryTime /* = 3 */, int nAutoSpeed /* = 3 */)
36+
BOOL CSession_DLStroage::Session_DLStroage_Init(int nTryTime /* = 3 */)
4237
{
4338
Session_IsErrorOccur = FALSE;
4439

4540
m_nTryTime = nTryTime;
46-
m_nTryAuto = nAutoSpeed;
4741
return TRUE;
4842
}
4943
/********************************************************************
@@ -292,57 +286,18 @@ BOOL CSession_DLStroage::Session_DLStroage_GetInfo(LPCTSTR lpszClientAddr, SESSI
292286
意思:是否成功
293287
备注:
294288
*********************************************************************/
295-
BOOL CSession_DLStroage::Session_DLStroage_GetCount(list<string>* pStl_ListClient)
289+
BOOL CSession_DLStroage::Session_DLStroage_GetCount(int* pInt_ListCount)
296290
{
297291
Session_IsErrorOccur = FALSE;
298292

299-
if (NULL == pStl_ListClient)
293+
if (NULL == pInt_ListCount)
300294
{
301295
Session_IsErrorOccur = TRUE;
302296
Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_PARAMENT;
303297
return FALSE;
304298
}
305-
306299
st_Locker.lock_shared();
307-
unordered_map<tstring, SESSION_STORAGEINFO>::iterator stl_MapIterator = stl_MapStroage.begin();
308-
for (; stl_MapIterator != stl_MapStroage.end(); stl_MapIterator++)
309-
{
310-
//是否需要等待恢复
311-
if (stl_MapIterator->second.st_DynamicRate.ullTimeWait > 0)
312-
{
313-
XENGINE_VALTIME st_TimeVal;
314-
time_t nTimeNow = time(NULL);
315-
316-
memset(&st_TimeVal, '\0', sizeof(XENGINE_VALTIME));
317-
BaseLib_OperatorTime_GetTimeOfday(&st_TimeVal);
318-
if (((st_TimeVal.tv_value - stl_MapIterator->second.st_DynamicRate.ullTimeSend) > stl_MapIterator->second.st_DynamicRate.ullTimeWait) && ((nTimeNow - stl_MapIterator->second.st_DynamicRate.nTimeError) > 1))
319-
{
320-
//等待时间超过,可以加入
321-
pStl_ListClient->push_back(stl_MapIterator->second.tszClientAddr);
322-
stl_MapIterator->second.st_DynamicRate.ullTimeSend = st_TimeVal.tv_value;
323-
}
324-
//速率恢复测算
325-
if ((stl_MapIterator->second.st_DynamicRate.nAutoNumber <= m_nTryAuto) && ((nTimeNow - stl_MapIterator->second.st_DynamicRate.nTimeError) > (stl_MapIterator->second.st_DynamicRate.nErrorCount * stl_MapIterator->second.st_DynamicRate.nAutoNumber)))
326-
{
327-
//printf("nAutoNumber:%d <= m_nTryAuto:%d,nTimeNow:%lu - nTimeError:%lu nErrorCount:%d\n", stl_MapIterator->second.st_DynamicRate.nAutoNumber, m_nTryAuto, nTimeNow, stl_MapIterator->second.st_DynamicRate.nTimeError, stl_MapIterator->second.st_DynamicRate.nErrorCount * stl_MapIterator->second.st_DynamicRate.nAutoNumber);
328-
stl_MapIterator->second.st_DynamicRate.nAutoNumber++;
329-
stl_MapIterator->second.st_DynamicRate.nErrorCount--;
330-
stl_MapIterator->second.st_DynamicRate.ullTimeWait -= (XENGINE_STOREAGE_SESSION_DOWNLOAD_SENDTIME * stl_MapIterator->second.st_DynamicRate.nTimeError);
331-
if (0 == stl_MapIterator->second.st_DynamicRate.nErrorCount)
332-
{
333-
stl_MapIterator->second.st_DynamicRate.nTimeError = 0;
334-
}
335-
else
336-
{
337-
stl_MapIterator->second.st_DynamicRate.nTimeError = nTimeNow;
338-
}
339-
}
340-
}
341-
else
342-
{
343-
pStl_ListClient->push_back(stl_MapIterator->second.tszClientAddr);
344-
}
345-
}
300+
*pInt_ListCount = stl_MapStroage.size();
346301
st_Locker.unlock_shared();
347302
return TRUE;
348303
}
@@ -363,18 +318,13 @@ BOOL CSession_DLStroage::Session_DLStroage_GetCount(list<string>* pStl_ListClien
363318
In/Out:In
364319
类型:逻辑型
365320
可空:Y
366-
意思:是否因为错误引起的
367-
参数.四:pSt_StorageRate
368-
In/Out:In
369-
类型:数据结构指针
370-
可空:Y
371-
意思:输出速率错误信息
321+
意思:是否有由错误引起的
372322
返回值
373323
类型:逻辑型
374324
意思:是否成功
375325
备注:
376326
*********************************************************************/
377-
BOOL CSession_DLStroage::Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek, BOOL bError /* = TRUE */, SESSION_STORAGEDYNAMICRATE* pSt_StorageRate /* = NULL */)
327+
BOOL CSession_DLStroage::Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek, BOOL bError /* = TRUE */)
378328
{
379329
Session_IsErrorOccur = FALSE;
380330

@@ -387,27 +337,21 @@ BOOL CSession_DLStroage::Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int n
387337
st_Locker.unlock_shared();
388338
return FALSE;
389339
}
390-
if (bError)
391-
{
392-
if ((time(NULL) - stl_MapIterator->second.st_DynamicRate.nTimeError) > 1)
393-
{
394-
stl_MapIterator->second.st_DynamicRate.nErrorCount++;
395-
stl_MapIterator->second.st_DynamicRate.nTimeError = time(NULL);
396-
stl_MapIterator->second.st_DynamicRate.ullTimeWait += (XENGINE_STOREAGE_SESSION_DOWNLOAD_SENDTIME * stl_MapIterator->second.st_DynamicRate.nTimeError);
397-
}
398-
if (NULL != pSt_StorageRate)
399-
{
400-
*pSt_StorageRate = stl_MapIterator->second.st_DynamicRate;
401-
}
402-
}
403-
fseek(stl_MapIterator->second.pSt_File, nSeek, SEEK_CUR);
404-
//如果超过次数.返回错误
405-
if (stl_MapIterator->second.st_DynamicRate.nErrorCount > m_nTryTime)
340+
if (stl_MapIterator->second.nErrorTime > m_nTryTime)
406341
{
342+
Session_IsErrorOccur = TRUE;
343+
Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_ERRORTIME;
407344
st_Locker.unlock_shared();
408345
return FALSE;
409346
}
347+
//移动文件指针
348+
fseek(stl_MapIterator->second.pSt_File, nSeek, SEEK_CUR);
410349
stl_MapIterator->second.ullRWLen += nSeek;
350+
351+
if (bError)
352+
{
353+
stl_MapIterator->second.nErrorTime++;
354+
}
411355
st_Locker.unlock_shared();
412356
return TRUE;
413357
}

XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,24 @@
1010
// Purpose: 存储下载会话
1111
// History:
1212
*********************************************************************/
13-
#define XENGINE_STOREAGE_SESSION_DOWNLOAD_SENDTIME 50
1413

1514
class CSession_DLStroage
1615
{
1716
public:
1817
CSession_DLStroage();
1918
~CSession_DLStroage();
2019
public:
21-
BOOL Session_DLStroage_Init(int nTryTime = 3, int nAutoSpeed = 3);
20+
BOOL Session_DLStroage_Init(int nTryTime);
2221
BOOL Session_DLStroage_Destory();
2322
BOOL Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x* pInt_Count, __int64x* pInt_LeftCount, int nPosStart = 0, int nPostEnd = 0);
2423
BOOL Session_DLStroage_GetBuffer(LPCTSTR lpszClientAddr, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
2524
BOOL Session_DLStroage_GetInfo(LPCTSTR lpszClientAddr, SESSION_STORAGEINFO* pSt_StorageInfo);
26-
BOOL Session_DLStroage_GetCount(list<string>* pStl_ListClient);
27-
BOOL Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek, BOOL bError = TRUE, SESSION_STORAGEDYNAMICRATE* pSt_StorageRate = NULL);
25+
BOOL Session_DLStroage_GetCount(int* pInt_ListCount);
26+
BOOL Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek, BOOL bError = TRUE);
2827
BOOL Session_DLStorage_GetAll(SESSION_STORAGEINFO*** pppSt_StorageInfo, int* pInt_ListCount);
2928
BOOL Session_DLStroage_Delete(LPCTSTR lpszClientAddr);
3029
private:
3130
int m_nTryTime;
32-
int m_nTryAuto;
3331
shared_mutex st_Locker;
3432
private:
3533
unordered_map<tstring, SESSION_STORAGEINFO> stl_MapStroage;

XEngine_Source/StorageModule_Session/pch.cpp

Lines changed: 6 additions & 6 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 nTryTime, int nAutoSpeed)
51+
extern "C" BOOL Session_DLStroage_Init(int nTryTime)
5252
{
53-
return m_DLStorage.Session_DLStroage_Init(nTryTime, nAutoSpeed);
53+
return m_DLStorage.Session_DLStroage_Init(nTryTime);
5454
}
5555
extern "C" BOOL Session_DLStroage_Destory()
5656
{
@@ -68,13 +68,13 @@ extern "C" BOOL Session_DLStroage_GetInfo(LPCTSTR lpszClientAddr, SESSION_STORAG
6868
{
6969
return m_DLStorage.Session_DLStroage_GetInfo(lpszClientAddr, pSt_StorageInfo);
7070
}
71-
extern "C" BOOL Session_DLStroage_GetCount(list<string>*pStl_ListClient)
71+
extern "C" BOOL Session_DLStroage_GetCount(int* pInt_ListCount)
7272
{
73-
return m_DLStorage.Session_DLStroage_GetCount(pStl_ListClient);
73+
return m_DLStorage.Session_DLStroage_GetCount(pInt_ListCount);
7474
}
75-
extern "C" BOOL Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek, BOOL bError, SESSION_STORAGEDYNAMICRATE * pSt_StorageRate)
75+
extern "C" BOOL Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek, BOOL bError)
7676
{
77-
return m_DLStorage.Session_DLStorage_SetSeek(lpszClientAddr, nSeek, bError, pSt_StorageRate);
77+
return m_DLStorage.Session_DLStorage_SetSeek(lpszClientAddr, nSeek, bError);
7878
}
7979
extern "C" BOOL Session_DLStorage_GetAll(SESSION_STORAGEINFO * **pppSt_StorageInfo, int* pInt_ListCount)
8080
{

0 commit comments

Comments
 (0)