Skip to content

Commit c554c22

Browse files
committed
Support setting the number of sending retries
1 parent 09595a6 commit c554c22

File tree

7 files changed

+111
-13
lines changed

7 files changed

+111
-13
lines changed

XEngine_Source/StorageModule_Session/Session_Define.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef struct
2222
__int64x ullRWLen; //已经读取(写入)的大小
2323
__int64x ullPosStart; //开始位置
2424
__int64x ullPosEnd; //结束位置
25+
int nErrorCount; //错误次数
2526
FILE* pSt_File;
2627
}SESSION_STORAGEINFO;
2728
//////////////////////////////////////////////////////////////////////////
@@ -84,12 +85,17 @@ extern "C" BOOL Session_User_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass);
8485
类型:整数型
8586
可空:N
8687
意思:输入最大运行多少个下载同时进行
88+
参数.二:nTryTime
89+
In/Out:In
90+
类型:整数型
91+
可空:N
92+
意思:输入重试次数
8793
返回值
8894
类型:逻辑型
8995
意思:是否成功
9096
备注:
9197
*********************************************************************/
92-
extern "C" BOOL Session_DLStroage_Init(int nPoolCount = 1);
98+
extern "C" BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3);
9399
/********************************************************************
94100
函数名称:Session_DLStroage_Destory
95101
函数功能:销毁下载管理器
@@ -215,6 +221,25 @@ extern "C" BOOL Session_DLStroage_GetInfo(int nPool, int nIndex, SESSION_STORAGE
215221
*********************************************************************/
216222
extern "C" BOOL Session_DLStroage_GetCount(int nIndex, int* pInt_ListCount);
217223
/********************************************************************
224+
函数名称:Session_DLStorage_SetSeek
225+
函数功能:移动文件指针
226+
参数.一:lpszClientAddr
227+
In/Out:In
228+
类型:常量字符指针
229+
可空:N
230+
意思:输入要操作的客户端
231+
参数.二:nSeek
232+
In/Out:In
233+
类型:整数型
234+
可空:N
235+
意思:输入文件位置
236+
返回值
237+
类型:逻辑型
238+
意思:是否成功
239+
备注:
240+
*********************************************************************/
241+
extern "C" BOOL Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek);
242+
/********************************************************************
218243
函数名称:Session_DLStroage_Delete
219244
函数功能:删除一个队列
220245
参数.一:lpszClientAddr

XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*********************************************************************/
1414
CSession_DLStroage::CSession_DLStroage()
1515
{
16+
m_nTryTime = 3;
1617
}
1718
CSession_DLStroage::~CSession_DLStroage()
1819
{
@@ -28,12 +29,17 @@ CSession_DLStroage::~CSession_DLStroage()
2829
类型:整数型
2930
可空:N
3031
意思:输入最大运行多少个下载同时进行
32+
参数.二:nTryTime
33+
In/Out:In
34+
类型:整数型
35+
可空:N
36+
意思:输入重试次数
3137
返回值
3238
类型:逻辑型
3339
意思:是否成功
3440
备注:
3541
*********************************************************************/
36-
BOOL CSession_DLStroage::Session_DLStroage_Init(int nPoolCount /* = 1 */)
42+
BOOL CSession_DLStroage::Session_DLStroage_Init(int nPoolCount /* = 1 */, int nTryTime /* = 3 */)
3743
{
3844
Session_IsErrorOccur = FALSE;
3945

@@ -406,6 +412,62 @@ BOOL CSession_DLStroage::Session_DLStroage_GetCount(int nPool, int* pInt_ListCou
406412
return TRUE;
407413
}
408414
/********************************************************************
415+
函数名称:Session_DLStorage_SetSeek
416+
函数功能:移动文件指针
417+
参数.一:lpszClientAddr
418+
In/Out:In
419+
类型:常量字符指针
420+
可空:N
421+
意思:输入要操作的客户端
422+
参数.二:nSeek
423+
In/Out:In
424+
类型:整数型
425+
可空:N
426+
意思:输入文件位置
427+
返回值
428+
类型:逻辑型
429+
意思:是否成功
430+
备注:
431+
*********************************************************************/
432+
BOOL CSession_DLStroage::Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek)
433+
{
434+
Session_IsErrorOccur = FALSE;
435+
436+
BOOL bFound = FALSE;
437+
st_Locker.lock_shared();
438+
unordered_map<int, SESSION_STORAGELIST>::iterator stl_MapIterator = stl_MapStroage.begin();
439+
for (; stl_MapIterator != stl_MapStroage.end(); stl_MapIterator++)
440+
{
441+
stl_MapIterator->second.st_Locker->lock_shared();
442+
list<SESSION_STORAGEINFO>::iterator stl_ListIterator = stl_MapIterator->second.pStl_ListStorage->begin();
443+
for (; stl_ListIterator != stl_MapIterator->second.pStl_ListStorage->end(); stl_ListIterator++)
444+
{
445+
if (0 == _tcsncmp(lpszClientAddr, stl_ListIterator->tszClientAddr, _tcslen(lpszClientAddr)))
446+
{
447+
bFound = TRUE;
448+
stl_ListIterator->nErrorCount++;
449+
fseek(stl_ListIterator->pSt_File, nSeek, SEEK_CUR);
450+
//如果超过次数.返回错误
451+
if (stl_ListIterator->nErrorCount > m_nTryTime)
452+
{
453+
stl_MapIterator->second.st_Locker->unlock_shared();
454+
st_Locker.unlock_shared();
455+
return FALSE;
456+
}
457+
break;
458+
}
459+
}
460+
stl_MapIterator->second.st_Locker->unlock_shared();
461+
462+
if (bFound)
463+
{
464+
break;
465+
}
466+
}
467+
st_Locker.unlock_shared();
468+
return TRUE;
469+
}
470+
/********************************************************************
409471
函数名称:Session_DLStroage_Delete
410472
函数功能:删除一个队列
411473
参数.一:lpszClientAddr

XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ class CSession_DLStroage
2222
CSession_DLStroage();
2323
~CSession_DLStroage();
2424
public:
25-
BOOL Session_DLStroage_Init(int nPoolCount = 1);
25+
BOOL Session_DLStroage_Init(int nPoolCount = 1, int nTryTime = 3);
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, int nIndex, TCHAR* ptszClientAddr, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
2929
BOOL Session_DLStroage_GetInfo(int nPool, int nIndex, SESSION_STORAGEINFO* pSt_StorageInfo);
3030
BOOL Session_DLStroage_GetCount(int nPool, int* pInt_ListCount);
31+
BOOL Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek);
3132
BOOL Session_DLStroage_Delete(LPCTSTR lpszClientAddr);
3233
private:
34+
int m_nTryTime;
3335
shared_mutex st_Locker;
3436
private:
3537
unordered_map<int, SESSION_STORAGELIST> stl_MapStroage;

XEngine_Source/StorageModule_Session/StorageModule_Session.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ EXPORTS
1313
Session_DLStroage_GetList
1414
Session_DLStroage_GetInfo
1515
Session_DLStroage_GetCount
16+
Session_DLStorage_SetSeek
1617
Session_DLStroage_Delete
1718

1819
Session_UPStroage_Init

XEngine_Source/StorageModule_Session/pch.cpp

Lines changed: 6 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)
51+
extern "C" BOOL Session_DLStroage_Init(int nPoolCount, int nTryTime)
5252
{
53-
return m_DLStorage.Session_DLStroage_Init(nPoolCount);
53+
return m_DLStorage.Session_DLStroage_Init(nPoolCount, nTryTime);
5454
}
5555
extern "C" BOOL Session_DLStroage_Destory()
5656
{
@@ -72,6 +72,10 @@ extern "C" BOOL Session_DLStroage_GetCount(int nIndex, int* pInt_ListCount)
7272
{
7373
return m_DLStorage.Session_DLStroage_GetCount(nIndex, pInt_ListCount);
7474
}
75+
extern "C" BOOL Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int nSeek)
76+
{
77+
return m_DLStorage.Session_DLStorage_SetSeek(lpszClientAddr, nSeek);
78+
}
7579
extern "C" BOOL Session_DLStroage_Delete(LPCTSTR lpszClientAddr)
7680
{
7781
return m_DLStorage.Session_DLStroage_Delete(lpszClientAddr);

XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ XHTHREAD CALLBACK XEngine_Download_SendThread(LPVOID lParam)
9292
}
9393
XEngine_Task_SendDownload(tszClientAddr, tszMsgBuffer, nMsgLen);
9494
}
95-
int nTimeWait = 10;
95+
int nTimeWait = 1;
9696
Algorithm_Calculation_SleepFlow(&nTimeWait, st_ServiceCfg.st_XLimit.nMaxDNLoader, nListCount, 4096);
97-
std::this_thread::sleep_for(std::chrono::milliseconds(nTimeWait));
97+
std::this_thread::sleep_for(std::chrono::microseconds(nTimeWait));
9898
}
9999
return 0;
100100
}
@@ -195,8 +195,15 @@ BOOL XEngine_Task_SendDownload(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in
195195
}
196196
else
197197
{
198-
XEngine_Net_CloseClient(lpszClientAddr, STORAGE_LEAVETYPE_CLOSE, STORAGE_NETTYPE_HTTPDOWNLOAD);
199-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,正在发送文件数据,大小:%d,发送失败,无法继续,移除发送队列"), lpszClientAddr, nMsgLen);
198+
if (Session_DLStorage_SetSeek(lpszClientAddr, -nMsgLen))
199+
{
200+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("下载客户端:%s,正在发送文件数据,发送失败,移动指针:%d"), lpszClientAddr, -nMsgLen);
201+
}
202+
else
203+
{
204+
XEngine_Net_CloseClient(lpszClientAddr, STORAGE_LEAVETYPE_CLOSE, STORAGE_NETTYPE_HTTPDOWNLOAD);
205+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,正在发送文件数据,大小:%d,发送超过重试次数,无法继续,移除发送队列"), lpszClientAddr, nMsgLen);
206+
}
200207
}
201208
return TRUE;
202209
}

XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorageSQL_File/XStorageSQL_File.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ BOOL CXStorageSQL_File::XStorageSQL_File_Destory()
9393
return TRUE;
9494
}
9595
bIsRun = FALSE;
96-
if (pSTDThread->joinable())
97-
{
98-
pSTDThread->join();
99-
}
96+
pSTDThread->join();
10097

10198
DataBase_MySQL_Close(xhDBSQL);
10299

0 commit comments

Comments
 (0)