C++ CkHttp AbortCheck Callback
Chilkat classes that involve network communications can use callbacks. This blog post describes the CkHttp AbortCheck callback. An application can request periodic AbortCheck callbacks according to the HeartbeatMs property setting. (If HeartbeatMs = 0, then no AbortCheck callbacks will occur.) For example:
// Create a class that inherits CkHttpProgress and override desired methods..
class MyHttpProgress : public CkHttpProgress
{
public:
MyHttpProgress(void) { }
virtual ~MyHttpProgress(void) { }
// Periodically called according to the HeartbeatMs property setting.
// Any callback method with a "bool *abort" argument provides the opportunity to abort the current method call.
void AbortCheck(bool *abort)
{
// If your application wishes to abort, set *abort = true before returning.
*abort = false;
}
void PercentDone(int pctDone, bool *abort)
{
*abort = false;
}
};
// Setting up and using the progress (callback) class..
void test(void)
{
CkHttp http;
MyHttpProgress myProgress;
http.put_EventCallbackObject(&myProgress);
// Make an AbortCheck callback every 100 milliseconds.
// Our application can choose to abort the download in the AbortCheck callback.
http.put_HeartbeatMs(100);
bool success = http.Download("https://example.com/something_large.zip","c:/someDir/something_large.zip");
if (!success)
{
// ....
}
// ....
// ....
};
admin
0
Tags :