Clone
ixen <ixen@copyhandler.com>
committed
on 14 Sep 16
Added basic support for asynchronous logging in CH and libchcore (based on boost log) (CH-206)
LoggerImprovements + 5 more
src/ch/AsyncHttpFile.cpp (+3 -1)
1 1 // ============================================================================
2 2 //  Copyright (C) 2001-2015 by Jozef Starosczyk
3 3 //  ixen@copyhandler.com
4 4 //
5 5 //  This program is free software; you can redistribute it and/or modify
6 6 //  it under the terms of the GNU Library General Public License
7 7 //  (version 2) as published by the Free Software Foundation;
8 8 //
9 9 //  This program is distributed in the hope that it will be useful,
10 10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 12 //  GNU General Public License for more details.
13 13 //
14 14 //  You should have received a copy of the GNU Library General Public
15 15 //  License along with this program; if not, write to the
16 16 //  Free Software Foundation, Inc.,
17 17 //  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 18 // ============================================================================
19 19 #include "stdafx.h"
20 20 #include "AsyncHttpFile.h"
  21 #include "../common/TLogger.h"
  22 #include "ch.h"
21 23
22 24 // timeout used with waiting for events (avoiding hangs)
23 25 #define FORCE_TIMEOUT 60000
24 26
25 27 using details::CONTEXT_REQUEST;
26 28
27 29 // ============================================================================
28 30 /// CAsyncHttpFile::CAsyncHttpFile
29 31 /// @date 2009/04/18
30 32 ///
31 33 /// @brief     Constructs the CAsyncHttpFile object.
32 34 // ============================================================================
33 35 CAsyncHttpFile::CAsyncHttpFile() :
34 36         m_hInternet(nullptr),
35 37         m_hOpenUrl(nullptr),
36 38         m_hFinishedEvent(nullptr),
37 39         m_dwError(ERROR_SUCCESS)
38 40 {
39 41         memset(&m_internetBuffers, 0, sizeof(INTERNET_BUFFERSA));
40 42
 
338 340 /// @date 2009/04/18
339 341 ///
340 342 /// @brief     Callback for use with internet API.
341 343 /// @param[in] hInternet                                Internet handle.
342 344 /// @param[in] dwContext                                Context value.
343 345 /// @param[in] dwInternetStatus                 Internet status.
344 346 /// @param[in] lpvStatusInformation             Additional status information.
345 347 /// @param[in] dwStatusInformationLength Length of lpvStatusInformation.
346 348 // ============================================================================
347 349 void CALLBACK CAsyncHttpFile::InternetStatusCallback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
348 350 {
349 351         CONTEXT_REQUEST* pRequest = (CONTEXT_REQUEST*)dwContext;
350 352         BOOST_ASSERT(pRequest && pRequest->pHttpFile);
351 353         if(!pRequest || !pRequest->pHttpFile)
352 354                 return;
353 355
354 356         CString strMsg;
355 357         strMsg.Format(_T("[CAsyncHttpFile::InternetStatusCallback] hInternet: %p, dwContext: %Iu (operation: %lu), dwInternetStatus: %lu, lpvStatusInformation: %p, dwStatusInformationLength: %lu\n"),
356 358                 hInternet, (size_t)dwContext, pRequest->eOperationType, dwInternetStatus, lpvStatusInformation, dwStatusInformationLength);
357 359         ATLTRACE(L"%s\n", strMsg);
358           LOG_DEBUG(strMsg);
  360         LOG_DEBUG(GetLogger()) << strMsg;
359 361
360 362         switch(dwInternetStatus)
361 363         {
362 364         case INTERNET_STATUS_HANDLE_CREATED:
363 365         {
364 366                 INTERNET_ASYNC_RESULT* pRes = (INTERNET_ASYNC_RESULT*)lpvStatusInformation;
365 367                 if(pRes)
366 368                 {
367 369                         ATLTRACE(L"INTERNET_STATUS_HANDLE_CREATED error code: %lu\n", pRes->dwError);
368 370                         pRequest->pHttpFile->SetUrlHandle((HINTERNET)(pRes->dwResult));
369 371                 }
370 372                 break;
371 373         }
372 374         case INTERNET_STATUS_RESPONSE_RECEIVED:
373 375         {
374 376                 ATLTRACE(_T("INTERNET_STATUS_RESPONSE_RECEIVED; received %lu bytes."), *(DWORD*)lpvStatusInformation);
375 377                 break;
376 378         }
377 379         case INTERNET_STATUS_REQUEST_COMPLETE:
378 380         {