http client cancel in linux

Apr 11, 2014 at 2:20 PM
Hi,
Sorry if this question was asked before, but does the library support cancellation in Linux? I have code which works ok in Windows but the same code does not seem to do the cancellation in Linux.

Also do you have a full sample showing how to cancel a task in both Windows and Linux?

I am running 2.0.1 in Windows but 2.0.0 in Linux (maybe this is the issue?!).

Thanks,
G.
Coordinator
Apr 11, 2014 at 3:50 PM
Hi G,

No worries about asking questions :). Right now we only have http_client request cancellation implemented on the Windows platforms. We added the API so users can start coding with it while we bring it up on all the platforms. The feature request notes that it is not fully implemented on all the platforms yet. We are aware of this, and it will be fully added in the future to all platforms.

We don't have any http client cancellation samples or tutorials yet, but you can take a look at some of the test cases to get an idea. For example look at the test cases in connections_and_errors.cpp. All the test cases that begin with 'cancel_', for example cancel_while_uploading_data.

Thanks,
Steve
Apr 11, 2014 at 7:58 PM
Hi Steve,

Of cause there is a continuation :)

When I cancel an http task, I get an error code of 105 and the message is indeed some wording about user cancelled(web::http::http_exception thrown). Is the 105 an error code in Casablanca which is going to be consistent across implementations?

Thanks,

G.
Coordinator
Apr 14, 2014 at 4:38 PM
Hi G,

I wouldn't rely directly on the hardcoded integer value itself, but it will always be std::errc::operation_canceled. You can see in http_client_impl.h around line 167, that if cancellation occurs we always use operation_canceled.
// If cancellation has been triggered then ignore any errors.
if(m_request._cancellation_token().is_canceled())
{
    exceptionPtr = std::make_exception_ptr(http_exception((int)std::errc::operation_canceled, std::generic_category()));
}
Please note there always is an inherit race with the request/response being completed before cancellation occurs. If the request completes naturally before being cancelled then no such http_exception will be thrown.

Steve
Apr 14, 2014 at 5:40 PM
Hi Steve,

Ok good,

Thanks for your help,

G.