login about faq

I'm using Ck libs 9.41 with VC++ 2012. I'm downloading a file using the background thread method per your example http://www.example-code.com/mfc/http_backgroundThread.asp.

The only difference is that I'm using CkHttpW instead of CkHttp.

Part way through the download (it's many MB in size), I call http.BgTaskAbort() to abort the download. This simulates the user aborting a lengthy download for some reason.

However, after calling http.BgTaskAbort(), the download doesn't really abort. It's obviously that it doesn't because Windows Explorer shows the file size still growing until the full file is downloaded. Also, as soon as the full file is downloaded, I can see the background thread exit in the VC++ debugger.

Is there something different that I need to do to abort the download? Does BgTaskAbort now work with CkHttpW?

asked Feb 28 '14 at 18:37

pdm1999's gravatar image

pdm1999
1244


I was not able to reproduce the problem. I'll post a new build here shortly for you to try. This was my test code:

bool HttpTesting::qa_httpBgAbort(void)
    {
    CkHttp http;

bool success;

http.put_UseBgThread(true);

success = http.Download("http://www.chilkatsoft.com/download/ChilkatJava.zip","qa_output/ChilkatJava.zip");
if (!success) 
{
    printf("%s\n",http.lastErrorText());
printf("qa_httpBgAbort failed!\n");
    return false;
}

// After running the 1st time without aborting, I determined that (for me) the download took
// about 17 iterations.  To abort, I inserted a call to abort on the 10th iteration.
int numIterations = 0;
while ((http.get_BgTaskRunning() == true)) 
{
    //  Sleep .1 seconds -- to keep the CPU from being 100% busy...
    http.SleepMs(100);
numIterations++;
if (numIterations == 10)
    {
    http.BgTaskAbort();
    }
}

printf("numIterations = %d\n",numIterations);

//  Once the background task has completed, check it for success/failure:

if (!http.get_BgTaskSuccess()) 
{
printf("%s\n",http.bgLastErrorText());
printf("qa_httpBgAbort failed!\n");
return false;
}
else
{
printf("qa_httpBgAbort success\n");
return true;
}

}

This is the BgLastErrorText for the aborted download:

numIterations = 11
ChilkatLog:
  Download:
    DllDate: Feb 28 2014
    ChilkatVersion: 9.5.0.15
    UnlockPrefix: UNTTSTHttp
    Username: CHILKAT13:Matt
    Architecture: Little Endian; 32-bit
    Language: Visual C++ 11.0 (32-bit)
    VerboseLogging: 0
    url: http://www.chilkatsoft.com/download/ChilkatJava.zip
    toLocalPath: qa_output/ChilkatJava.zip
    currentWorkingDir: c:ck2000appDataUnitTest
    a_httpDownload:
      httpDownloadFile:
        localFilePath: qa_output/ChilkatJava.zip
        localFileAlreadyExists: 1
        quickHttpRequest:
          httpVerb: GET
          url: http://www.chilkatsoft.com/download/ChilkatJava.zip
          buildQuickRequest:
            genStartLine:
              startLine: GET /download/ChilkatJava.zip HTTP/1.1
            --genStartLine
            addCookies:
              Not auto-adding cookies.
            --addCookies
          --buildQuickRequest
          openHttpConnection:
            Opening connection to HTTP server.
            hostname: www.chilkatsoft.com
            port: 80
            ssl: 0
            connectElapsedMs: 62
            HTTP connection succeeded.
          --openHttpConnection
          sendRequestHeader:
            sendHeaderElapsedMs: 0
          --sendRequestHeader
          statusCode: 200
          statusText: OK
          readResponseBody:
            contentLength: 2656231
            Socket ReceiveBytes aborted by application.
          --readResponseBody
          Failed to read response body.
        --quickHttpRequest
        outputLocalFileSize: 1008974
        numOutputBytesWritten: 1008974
        httpDownloadFile failed.
      --httpDownloadFile
      a_httpDownload failed.
    --a_httpDownload
    totalElapsedMs: 1016
    Failed.
  --Download
--ChilkatLog

link

answered Mar 02 '14 at 22:15

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

link

answered Mar 02 '14 at 22:33

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×2

Asked: Feb 28 '14 at 18:37

Seen: 616 times

Last updated: Mar 02 '14 at 22:33

powered by OSQA