@@ -238,35 +238,30 @@ BOOL CSession_DLStroage::Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTST
238238 类型:整数型
239239 可空:N
240240 意思:输入要操作的队列
241- 参数.二:nIndex
241+ 参数.二:lpszClientAddr
242242 In/Out:In
243- 类型:整数型
243+ 类型:常量字符指针
244244 可空:N
245- 意思:输入要操作的队列索引
246- 参数.三:ptszClientAddr
245+ 意思:输入客户端地址
246+ 参数.三:ptszMsgBuffer
247247 In/Out:In
248- 类型:整数型
248+ 类型:字符指针
249249 可空:N
250- 意思:输出客户端地址
251- 参数.四:ptszMsgBuffer
250+ 参数.四:pInt_MsgLen
252251 In/Out:In
253- 类型:整数型
254- 可空:N
255- 参数.五:pInt_MsgLen
256- In/Out:In
257- 类型:整数型
252+ 类型:整数型指针
258253 可空:N
259254 意思:输出获取的缓冲区大小
260255返回值
261256 类型:逻辑型
262257 意思:是否成功
263258备注:
264259*********************************************************************/
265- BOOL CSession_DLStroage::Session_DLStroage_GetList (int nPool, int nIndex, TCHAR* ptszClientAddr , TCHAR* ptszMsgBuffer, int * pInt_MsgLen)
260+ BOOL CSession_DLStroage::Session_DLStroage_GetList (int nPool, LPCTSTR lpszClientAddr , TCHAR* ptszMsgBuffer, int * pInt_MsgLen)
266261{
267262 Session_IsErrorOccur = FALSE ;
268263
269- if ((NULL == ptszClientAddr ) || (NULL == ptszMsgBuffer))
264+ if ((NULL == lpszClientAddr ) || (NULL == ptszMsgBuffer) || ( NULL == pInt_MsgLen ))
270265 {
271266 Session_IsErrorOccur = TRUE ;
272267 Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_PARAMENT;
@@ -286,10 +281,8 @@ BOOL CSession_DLStroage::Session_DLStroage_GetList(int nPool, int nIndex, TCHAR*
286281 list<SESSION_STORAGEINFO>::iterator stl_ListIterator = stl_MapIterator->second .pStl_ListStorage ->begin ();
287282 for (int i = 0 ; stl_ListIterator != stl_MapIterator->second .pStl_ListStorage ->end (); stl_ListIterator++, i++)
288283 {
289- if (nIndex == i )
284+ if (0 == _tcsncmp (lpszClientAddr, stl_ListIterator-> tszClientAddr , _tcslen (lpszClientAddr)) )
290285 {
291- _tcscpy (ptszClientAddr, stl_ListIterator->tszClientAddr );
292-
293286 if (stl_ListIterator->ullRWLen >= stl_ListIterator->ullRWCount )
294287 {
295288 *pInt_MsgLen = 0 ;
@@ -318,11 +311,11 @@ BOOL CSession_DLStroage::Session_DLStroage_GetList(int nPool, int nIndex, TCHAR*
318311 类型:整数型
319312 可空:N
320313 意思:输入要操作的下载池
321- 参数.二:nIndex
314+ 参数.二:lpszClientAddr
322315 In/Out:In
323- 类型:整数型
316+ 类型:常量字符指针
324317 可空:N
325- 意思:输入要操作的索引
318+ 意思:输入要操作的客户端
326319 参数.三:pSt_StorageInfo
327320 In/Out:Out
328321 类型:数据结构指针
@@ -333,7 +326,7 @@ BOOL CSession_DLStroage::Session_DLStroage_GetList(int nPool, int nIndex, TCHAR*
333326 意思:是否成功
334327备注:
335328*********************************************************************/
336- BOOL CSession_DLStroage::Session_DLStroage_GetInfo (int nPool, int nIndex , SESSION_STORAGEINFO* pSt_StorageInfo)
329+ BOOL CSession_DLStroage::Session_DLStroage_GetInfo (int nPool, LPCTSTR lpszClientAddr , SESSION_STORAGEINFO* pSt_StorageInfo)
337330{
338331 Session_IsErrorOccur = FALSE ;
339332
@@ -357,7 +350,7 @@ BOOL CSession_DLStroage::Session_DLStroage_GetInfo(int nPool, int nIndex, SESSIO
357350 list<SESSION_STORAGEINFO>::iterator stl_ListIterator = stl_MapIterator->second .pStl_ListStorage ->begin ();
358351 for (int i = 0 ; stl_ListIterator != stl_MapIterator->second .pStl_ListStorage ->end (); stl_ListIterator++, i++)
359352 {
360- if (nIndex == i )
353+ if (0 == _tcsncmp (lpszClientAddr, stl_ListIterator-> tszClientAddr , _tcslen (lpszClientAddr)) )
361354 {
362355 *pSt_StorageInfo = *stl_ListIterator;
363356 break ;
@@ -375,21 +368,21 @@ BOOL CSession_DLStroage::Session_DLStroage_GetInfo(int nPool, int nIndex, SESSIO
375368 类型:整数型
376369 可空:N
377370 意思:输入要操作的队列
378- 参数.二:pInt_ListCount
371+ 参数.二:pStl_ListClient
379372 In/Out:Out
380- 类型:整数型指针
373+ 类型:STL容器指针
381374 可空:N
382- 意思:输出队列个数
375+ 意思:输出要发送的队列个数
383376返回值
384377 类型:逻辑型
385378 意思:是否成功
386379备注:
387380*********************************************************************/
388- BOOL CSession_DLStroage::Session_DLStroage_GetCount (int nPool, int * pInt_ListCount )
381+ BOOL CSession_DLStroage::Session_DLStroage_GetCount (int nPool, list<string>* pStl_ListClient )
389382{
390383 Session_IsErrorOccur = FALSE ;
391384
392- if (NULL == pInt_ListCount )
385+ if (NULL == pStl_ListClient )
393386 {
394387 Session_IsErrorOccur = TRUE ;
395388 Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_PARAMENT;
@@ -406,7 +399,34 @@ BOOL CSession_DLStroage::Session_DLStroage_GetCount(int nPool, int* pInt_ListCou
406399 return FALSE ;
407400 }
408401 stl_MapIterator->second .st_Locker ->lock_shared ();
409- *pInt_ListCount = stl_MapIterator->second .pStl_ListStorage ->size ();
402+ list<SESSION_STORAGEINFO>::iterator stl_ListIterator = stl_MapIterator->second .pStl_ListStorage ->begin ();
403+ for (; stl_ListIterator != stl_MapIterator->second .pStl_ListStorage ->end (); stl_ListIterator++)
404+ {
405+ // 是否需要等待恢复
406+ if (stl_ListIterator->st_DynamicRate .nTimeWait > 0 )
407+ {
408+ time_t nTimeNow = time (NULL );
409+ if ((nTimeNow - stl_ListIterator->st_DynamicRate .nTimeError ) > stl_ListIterator->st_DynamicRate .nTimeWait )
410+ {
411+ // 等待时间超过,可以加入
412+ pStl_ListClient->push_back (stl_ListIterator->tszClientAddr );
413+ }
414+ // 速率恢复测算
415+ if ((nTimeNow - stl_ListIterator->st_DynamicRate .nTimeError ) > (stl_ListIterator->st_DynamicRate .nErrorCount * 2 ))
416+ {
417+ stl_ListIterator->st_DynamicRate .nErrorCount --;
418+ if (0 == stl_ListIterator->st_DynamicRate .nErrorCount )
419+ {
420+ stl_ListIterator->st_DynamicRate .nTimeWait = 0 ;
421+ stl_ListIterator->st_DynamicRate .nTimeError = 0 ;
422+ }
423+ }
424+ }
425+ else
426+ {
427+ pStl_ListClient->push_back (stl_ListIterator->tszClientAddr );
428+ }
429+ }
410430 stl_MapIterator->second .st_Locker ->unlock_shared ();
411431 st_Locker.unlock_shared ();
412432 return TRUE ;
@@ -424,12 +444,22 @@ BOOL CSession_DLStroage::Session_DLStroage_GetCount(int nPool, int* pInt_ListCou
424444 类型:整数型
425445 可空:N
426446 意思:输入文件位置
447+ 参数.三:bError
448+ In/Out:In
449+ 类型:逻辑型
450+ 可空:Y
451+ 意思:是否因为错误引起的
452+ 参数.四:pSt_StorageRate
453+ In/Out:In
454+ 类型:数据结构指针
455+ 可空:Y
456+ 意思:输出速率错误信息
427457返回值
428458 类型:逻辑型
429459 意思:是否成功
430460备注:
431461*********************************************************************/
432- BOOL CSession_DLStroage::Session_DLStorage_SetSeek (LPCTSTR lpszClientAddr, int nSeek)
462+ BOOL CSession_DLStroage::Session_DLStorage_SetSeek (LPCTSTR lpszClientAddr, int nSeek, BOOL bError /* = TRUE */ , SESSION_STORAGEDYNAMICRATE* pSt_StorageRate /* = NULL */ )
433463{
434464 Session_IsErrorOccur = FALSE ;
435465
@@ -445,10 +475,26 @@ BOOL CSession_DLStroage::Session_DLStorage_SetSeek(LPCTSTR lpszClientAddr, int n
445475 if (0 == _tcsncmp (lpszClientAddr, stl_ListIterator->tszClientAddr , _tcslen (lpszClientAddr)))
446476 {
447477 bFound = TRUE ;
448- stl_ListIterator->nErrorCount ++;
478+ if (bError)
479+ {
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+ }
487+ stl_ListIterator->st_DynamicRate .nErrorCount ++;
488+ stl_ListIterator->st_DynamicRate .nTimeError = time (NULL );
489+
490+ if (NULL != pSt_StorageRate)
491+ {
492+ *pSt_StorageRate = stl_ListIterator->st_DynamicRate ;
493+ }
494+ }
449495 fseek (stl_ListIterator->pSt_File , nSeek, SEEK_CUR);
450496 // 如果超过次数.返回错误
451- if (stl_ListIterator->nErrorCount > m_nTryTime)
497+ if (stl_ListIterator->st_DynamicRate . nErrorCount > m_nTryTime)
452498 {
453499 stl_MapIterator->second .st_Locker ->unlock_shared ();
454500 st_Locker.unlock_shared ();
0 commit comments