UPDATED: Problem was not in libcurl. The right way to cancel request if to return from callback non-zero value. I used curl_progress_callback function, and everything works fine.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What you need to understand is that CURL is a C library. In general, you cannot pass pointers to C++ objects or functions because C does not know anything about C++’s classes and calling convention.
For example, this line is incorrect:
CURL setopt
CURLOPT_ERRORBUFFERexpects that the third parameter is a pointer to a C-style string (C-stylechararray) having space forCURL_ERROR_SIZEchars. You are instead passing a pointer to astd::stringobject. As CURL, being written in C, does not know what astd::stringis, it simply overwrites the byte representation havingsizeof (std::string)bytes with the error data because it thinks that the pointer is to a C-stylechararray.Use this instead:
errorBufferis only filled with a valid string ifcurl_easy_perform()returns an error code.Also,
Uploader::WriteResponceis a C++ function. With this line:CURL expects the third parameter to be a pointer-to-C function. Here, you are passing a pointer-to-C++ function. You need to wrap the call to
WriteResponcein anextern "C"function that calls the C++ function:The “write function” needs to return
size_t, notint;Uploader::WriteResponceneeds to returnsize_t.