@@ -44,9 +44,9 @@ XHTHREAD CALLBACK XEngine_Download_HTTPThread(LPVOID lParam)
4444
4545void CALLBACK XEngine_Download_CBSend (LPCSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam)
4646{
47- int nTimeWait = 0 ;
4847 int nThreadPos = 0 ; // 回调模式不需要发送线程池
4948 int nMsgLen = 4096 ;
49+ __int64u nTimeWait = 0 ;
5050 TCHAR tszMsgBuffer[4096 ];
5151 list<string> stl_ListClient;
5252
@@ -95,65 +95,8 @@ void CALLBACK XEngine_Download_CBSend(LPCSTR lpszClientAddr, SOCKET hSocket, LPV
9595 Session_DLStroage_GetCount (nThreadPos, &stl_ListClient);
9696 Algorithm_Calculation_SleepFlow (&nTimeWait, st_ServiceCfg.st_XLimit .nMaxDNLoader , stl_ListClient.size (), 4096 );
9797 stl_ListClient.clear ();
98- std::this_thread::sleep_for (std::chrono::microseconds (nTimeWait));
99- }
100-
101- XHTHREAD CALLBACK XEngine_Download_SendThread (LPVOID lParam)
102- {
103- int nThreadPos = *(int *)lParam;
104- TCHAR tszMsgBuffer[4096 ];
105-
106- while (bIsRun)
107- {
108- list<string> stl_ListClient;
109- memset (tszMsgBuffer, ' \0 ' , sizeof (tszMsgBuffer));
110-
111- Session_DLStroage_GetCount (nThreadPos, &stl_ListClient);
112- list<string>::const_iterator stl_ListIterator = stl_ListClient.begin ();
113- for (; stl_ListIterator != stl_ListClient.end (); stl_ListIterator++)
114- {
115- int nMsgLen = 4096 ;
116- if (!Session_DLStroage_GetBuffer (nThreadPos, stl_ListIterator->c_str (), tszMsgBuffer, &nMsgLen))
117- {
118- XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T (" 下载客户端:%s,获取用户对应文件内容失败,错误:%lX" ), stl_ListIterator->c_str (), Session_GetLastError ());
119- continue ;
120- }
121- if (nMsgLen <= 0 )
122- {
123- if (st_ServiceCfg.st_XProxy .st_XProxyPass .bDLPass )
124- {
125- int nPLen = MAX_PATH;
126- int nHttpCode = 0 ;
127- UCHAR tszHashKey[MAX_PATH];
128- TCHAR tszHashStr[MAX_PATH];
129- TCHAR tszProxyStr[MAX_PATH];
130- SESSION_STORAGEINFO st_StorageInfo;
131-
132- memset (tszHashKey, ' \0 ' , MAX_PATH);
133- memset (tszHashStr, ' \0 ' , MAX_PATH);
134- memset (tszProxyStr, ' \0 ' , MAX_PATH);
135- memset (&st_StorageInfo, ' \0 ' , sizeof (SESSION_STORAGEINFO));
136-
137- OPenSsl_Api_Digest (st_StorageInfo.tszFileDir , tszHashKey, NULL , TRUE , st_ServiceCfg.st_XStorage .nHashMode );
138- BaseLib_OperatorString_StrToHex ((char *)tszHashKey, 20 , tszHashStr);
139- Session_DLStroage_GetInfo (nThreadPos, stl_ListIterator->c_str (), &st_StorageInfo);
140-
141- XStorageProtocol_Proxy_PacketUPDown (st_StorageInfo.tszFileDir , st_StorageInfo.tszClientAddr , st_StorageInfo.ullRWCount , tszProxyStr, &nPLen, tszHashStr);
142- APIHelp_HttpRequest_Post (st_ServiceCfg.st_XProxy .st_XProxyPass .tszDLPass , tszProxyStr, &nHttpCode);
143- XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_NOTICE, _T (" 下载客户端:%s,请求完成通知返回值:%d,文件:%s,地址:%s" ), stl_ListIterator->c_str (), nHttpCode, st_StorageInfo.tszFileDir , st_ServiceCfg.st_XProxy .st_XProxyPass .tszDLPass );
144- }
145- Session_DLStroage_Delete (stl_ListIterator->c_str ());
146- XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_NOTICE, _T (" 下载客户端:%s,文件已经发送完毕,用户已经被移除发送列表" ), stl_ListIterator->c_str ());
147- continue ;
148- }
149- XEngine_Task_SendDownload (stl_ListIterator->c_str (), tszMsgBuffer, nMsgLen);
150- }
151- int nTimeWait = 1 ;
152- Algorithm_Calculation_SleepFlow (&nTimeWait, st_ServiceCfg.st_XLimit .nMaxDNLoader , stl_ListClient.size (), 4096 );
153- stl_ListClient.clear ();
154- std::this_thread::sleep_for (std::chrono::microseconds (nTimeWait));
155- }
156- return 0 ;
98+ // 计算机每次休眠时间是不一定的,*2作为修正,如果想要更准确的需要使用到 Algorithm_Calculation_Create来处理
99+ std::this_thread::sleep_for (std::chrono::microseconds (nTimeWait * 2 ));
157100}
158101
159102BOOL XEngine_Task_HttpDownload (LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, TCHAR** pptszListHdr, int nHdrCount)
0 commit comments