Skip to content

Commit a61fbb6

Browse files
committed
support resumable for upload file with session module
1 parent 15f6b7a commit a61fbb6

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

XEngine_Source/StorageModule_Session/Session_Define.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,17 @@ extern "C" BOOL Session_DLStroage_Delete(LPCTSTR lpszClientAddr);
255255
/********************************************************************
256256
函数名称:Session_UPStroage_Init
257257
函数功能:初始化上传会话管理器
258+
参数.一:bUPResume
259+
In/Out:In
260+
类型:逻辑型
261+
可空:Y
262+
意思:是否启用断点上传
258263
返回值
259264
类型:逻辑型
260265
意思:是否成功
261266
备注:
262267
*********************************************************************/
263-
extern "C" BOOL Session_UPStroage_Init();
268+
extern "C" BOOL Session_UPStroage_Init(BOOL bUPResume = FALSE);
264269
/********************************************************************
265270
函数名称:Session_UPStroage_Destory
266271
函数功能:销毁下载管理器

XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@ CSession_UPStroage::~CSession_UPStroage()
2323
/********************************************************************
2424
函数名称:Session_UPStroage_Init
2525
函数功能:初始化上传会话管理器
26+
参数.一:bUPResume
27+
In/Out:In
28+
类型:逻辑型
29+
可空:Y
30+
意思:是否启用断点上传
2631
返回值
2732
类型:逻辑型
2833
意思:是否成功
2934
备注:
3035
*********************************************************************/
31-
BOOL CSession_UPStroage::Session_UPStroage_Init()
36+
BOOL CSession_UPStroage::Session_UPStroage_Init(BOOL bUPResume)
3237
{
3338
Session_IsErrorOccur = FALSE;
3439

40+
m_bResume = bUPResume;
3541
return TRUE;
3642
}
3743
/********************************************************************
@@ -122,7 +128,7 @@ BOOL CSession_UPStroage::Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTST
122128
_tcscpy(st_Client.st_StorageInfo.tszFileDir, lpszFileDir);
123129
_tcscpy(st_Client.st_StorageInfo.tszClientAddr, lpszClientAddr);
124130
//填充下载信息
125-
st_Client.st_StorageInfo.pSt_File = _tfopen(lpszFileDir, _T("wb"));
131+
st_Client.st_StorageInfo.pSt_File = _tfopen(lpszFileDir, _T("ab+"));
126132
if (NULL == st_Client.st_StorageInfo.pSt_File)
127133
{
128134
Session_IsErrorOccur = TRUE;
@@ -146,21 +152,26 @@ BOOL CSession_UPStroage::Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTST
146152
类型:常量字符指针
147153
可空:N
148154
意思:输入要操作的客户端
149-
参数.二:pbComplete
155+
参数.二:pbUPComplete
156+
In/Out:Out
157+
类型:逻辑型指针
158+
可空:N
159+
意思:上传是否完成
160+
参数.三:pbFileComplete
150161
In/Out:Out
151162
类型:逻辑型指针
152163
可空:N
153-
意思:输出是否完成
164+
意思:文件是否完成,某些断点续传的文件可能需要此参数
154165
返回值
155166
类型:逻辑型
156167
意思:是否成功
157168
备注:
158169
*********************************************************************/
159-
BOOL CSession_UPStroage::Session_UPStroage_GetComplete(LPCTSTR lpszClientAddr, BOOL* pbComplete)
170+
BOOL CSession_UPStroage::Session_UPStroage_GetComplete(LPCTSTR lpszClientAddr, BOOL* pbUPComplete, BOOL* pbFileComplete)
160171
{
161172
Session_IsErrorOccur = FALSE;
162173

163-
if ((NULL == lpszClientAddr) || (NULL == pbComplete))
174+
if ((NULL == lpszClientAddr) || (NULL == pbUPComplete))
164175
{
165176
Session_IsErrorOccur = TRUE;
166177
Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_PARAMENT;
@@ -178,12 +189,13 @@ BOOL CSession_UPStroage::Session_UPStroage_GetComplete(LPCTSTR lpszClientAddr, B
178189
}
179190
if (stl_MapIterator->second.st_StorageInfo.ullRWLen >= stl_MapIterator->second.st_StorageInfo.ullRWCount)
180191
{
181-
*pbComplete = TRUE;
192+
*pbUPComplete = TRUE;
182193
}
183194
else
184195
{
185-
*pbComplete = FALSE;
196+
*pbUPComplete = FALSE;
186197
}
198+
187199
st_Locker.unlock_shared();
188200
return TRUE;
189201
}
@@ -394,6 +406,15 @@ BOOL CSession_UPStroage::Session_UPStroage_Delete(LPCTSTR lpszClientAddr)
394406
if (stl_MapIterator != stl_MapStroage.end())
395407
{
396408
fclose(stl_MapIterator->second.st_StorageInfo.pSt_File);
409+
410+
struct __stat64 st_FStat;
411+
memset(&st_FStat, '\0', sizeof(struct __stat64));
412+
_stat64(stl_MapIterator->second.st_StorageInfo.tszFileDir, &st_FStat);
413+
//大小是否足够
414+
if ((stl_MapIterator->second.st_StorageInfo.ullCount != st_FStat.st_size) && !m_bResume)
415+
{
416+
_tremove(stl_MapIterator->second.st_StorageInfo.tszFileDir);
417+
}
397418
stl_MapStroage.erase(stl_MapIterator);
398419
}
399420
st_Locker.unlock();

XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ class CSession_UPStroage
2222
CSession_UPStroage();
2323
~CSession_UPStroage();
2424
public:
25-
BOOL Session_UPStroage_Init();
25+
BOOL Session_UPStroage_Init(BOOL bUPResume = FALSE);
2626
BOOL Session_UPStroage_Destory();
2727
BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x nFileSize, __int64x nLeftCount, int nPosStart = 0, int nPostEnd = 0);
28-
BOOL Session_UPStroage_GetComplete(LPCTSTR lpszClientAddr, BOOL* pbComplete);
28+
BOOL Session_UPStroage_GetComplete(LPCTSTR lpszClientAddr, BOOL* pbUPComplete, BOOL* pbFileComplete = NULL);
2929
BOOL Session_UPStroage_GetInfo(LPCTSTR lpszClientAddr, SESSION_STORAGEINFO* pSt_StorageInfo);
3030
BOOL Session_UPStroage_Write(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen);
3131
BOOL Session_UPStroage_Exist(LPCTSTR lpszClientAddr);
3232
BOOL Session_UPStorage_GetAll(SESSION_STORAGEINFO*** pppSt_StorageInfo, int* pInt_ListCount);
3333
BOOL Session_UPStroage_Delete(LPCTSTR lpszClientAddr);
34+
private:
35+
BOOL m_bResume;
3436
private:
3537
shared_mutex st_Locker;
3638
private:

XEngine_Source/StorageModule_Session/pch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ extern "C" BOOL Session_DLStroage_Delete(LPCTSTR lpszClientAddr)
8484
{
8585
return m_DLStorage.Session_DLStroage_Delete(lpszClientAddr);
8686
}
87-
extern "C" BOOL Session_UPStroage_Init()
87+
extern "C" BOOL Session_UPStroage_Init(BOOL bUPResume)
8888
{
89-
return m_UPStorage.Session_UPStroage_Init();
89+
return m_UPStorage.Session_UPStroage_Init(bUPResume);
9090
}
9191
extern "C" BOOL Session_UPStroage_Destory()
9292
{

0 commit comments

Comments
 (0)