Archived Forum Post

Index of archived forum posts

Question:

CkHttpW BgTaskAbort doesn't abort file download

Mar 02 '14 at 22:33

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?


Answer

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


Answer

Here are new builds you can try:

32-bit: http://www.chilkatsoft.com/preRelease/chilkat-9.5.0-x86-vc12.zip
64-bit: http://www.chilkatsoft.com/preRelease/chilkat-9.5.0-x86_64-vc12.zip