login about faq

I'm starting download like this: BOOL success = [http S3_DownloadFile: bucketName objectName: objectName localFilePath:filenameWithTempExtension];

It works fine but if I need to cancel download, how do I do it?

asked Mar 22 '13 at 17:15

ilkkapirttimaa's gravatar image

ilkkapirttimaa
1333


For now, you can call Http.CloseAllConnections prior to calling S3_DownloadFile. This will ensure that a new connection is established for the download. What is currently happening is that HTTP object is trying to use the pre-existing connection because the previous HTTP response did not indicate that the connection should be closed. A TCP socket that becomes disconnected by the remote peer closing its end is not noticed until an attempt to read is tried. This is what happens, and the method fails. I will work on adding an internal automatic re-try to re-establish the connection so that it doesn't need to be worried about. This change will be in v9.4.1. For now though, you can explicitly make sure connections are closed by calling Http.CloseAllConnections.

link

answered Apr 03 '13 at 08:44

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

To cancel an HTTP method call, setup a callback object by deriving from CkHttpProgress:

class MyHttpProgress : public CkHttpProgress { private: bool m_timeToAbort;

public:
MyHttpProgress(void) : m_timeToAbort(false) { }
virtual ~MyHttpProgress(void) { }

void PercentDone(int pctDone, bool *abort) 
    { 
    printf("PercentDone: %d percent\n",(int)pctDone);
    *abort = m_timeToAbort;
    }
void AbortCheck(bool *abort) 
    { 
    printf("----------- AbortCheck -----------\n");
    *abort = m_timeToAbort;
    }

void HttpBeginReceive(void) { printf("HttpBeginReceive!\n"); }
void HttpEndReceive(bool success) { printf("HttpEndReceive!\n"); }
void HttpBeginSend(void) { printf("HttpBeginSend!\n"); }
void HttpEndSend(bool success) { printf("HttpEndSend!\n"); }

void ReceiveRate(unsigned long byteCount, unsigned long bytesPerSec) 
    { 
    printf("ReceiveRate: byteCount = %d, bytesPerSec = %d\n",
    (int)byteCount,(int)bytesPerSec);
    }
void ProgressInfo(const char *name, const char *value)
    {
    printf("%s, %s\n",name,value);
    }

};

Then set the callback like this:

    CkHttp http;

MyHttpProgress myProgress;
http.put_EventCallbackObject(&myProgress);

Methods can be aborted from the PercentDone or AbortCheck callbacks. (PercentDone events are only called when it's possible to know the percentage completion. In some cases, such as for some method calls, or for chunked HTTP responses, it is impossible to know the percent complete.)

AbortCheck events fire at a frequency set by the HeartbeatMs property setting (which defaults to 0 for no AbortCheck events). PercentDone events, because they allow for aborting, count as an AbortCheck.

link

answered Apr 03 '13 at 10:49

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

PS> If the HTTP method was backgrounded by setting the UseBgThread property, then your foreground thread may abort the method running in the background thread at any time by calling CkHttp::BgTaskAbort.

link

answered Apr 03 '13 at 10:53

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Also, if using Objective-C, then the concept of using the event callback class is the same, and the methods are the same, except the class is CkoHttpProgress. See:
http://www.chilkatforum.com/questions/292/event-callbacks-in-ios-objective-c

link

answered Apr 03 '13 at 10:55

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Thank you, these answers really solved my issues.

link

answered Apr 03 '13 at 11:15

ilkkapirttimaa's gravatar image

ilkkapirttimaa
1333

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:

×186
×94
×33
×15

Asked: Mar 22 '13 at 17:15

Seen: 1,542 times

Last updated: Apr 03 '13 at 11:15

powered by OSQA