JosephP91 / curlcpp

An object oriented C++ wrapper for CURL (libcurl)
https://josephp91.github.io/curlcpp
MIT License
628 stars 173 forks source link

Missing option CURLOPT_PIPEWAIT #111

Closed ghost closed 7 years ago

ghost commented 7 years ago

Could you please add this option to library?

When i define it myself in my code as CURLCPP_DEFINE_OPTION(CURLOPT_PIPEWAIT, long); i get error

error: expected constructor, destructor, or type conversion before ‘(’ token
 CURLCPP_DEFINE_OPTION(CURLOPT_PIPEWAIT, long);

Thanks in advance.

JosephP91 commented 7 years ago

@brano543 Done! Can you check it out please?

ghost commented 7 years ago

Thank you, it works!

Unfortunately i am still having difficulties with adding options to multi interface. Here is my sample code.

 // use single connection to download multiple files at once
    string file_path = download_path + "/test_download";
    ofstream myfile;
    myfile.open(file_path.c_str());

    curl_multi multi;
    multi.add<CURLMOPT_PIPELINING>(1L);

    for (uint32_t i = 0; i < chunked_requests.size(); ++i)
    {
      ChunkedRequest request = chunked_requests[i];
      FileInfo file = request.info;
      string url = commoncrawl_amazon_url + file.name;
      string range = to_string(file.offset) + "-" + to_string(file.offset + file.length);

      // Create a curl_ios object to handle the stream
      curl_ios<ostream> writer(myfile);
      curl_easy easy(writer);
      easy.add<CURLOPT_URL>(url.c_str());
      easy.add<CURLOPT_HTTP_VERSION>(CURL_HTTP_VERSION_2_0); //use HTTP/2
      easy.add<CURLOPT_PIPEWAIT>(1L);                        // wait for pipe connection to confirm
      easy.add<CURLOPT_RANGE>(range.c_str());
      multi.add(easy);
    }

    bool still_running = multi.perform(); // we start some action by calling perform right away
    while (still_running)
    {
      int numfds = 0;
      multi.wait(NULL, 0, 30, &numfds); //wait maximum of 30 seconds

      still_running = multi.perform();
    }

    uint64_t successful = 0;
    vector<unique_ptr<curl_multi::curl_message>> messages = multi.get_info();
    for (auto &message : messages)
    {
      if (message->get_code() == 200 || message->get_code() == 206)
      {
        successful++;
      }
    }

    cout << "Successfull downloads " << successful << endl;

This code produces error when i try to add option to multi interface as follows:

curl_multi.h:354:27: error: cannot convert ‘curl::curl_multi::multi_ptr {aka std::unique_ptr<void, curl::curl_multi::milti_deleter>}’ to ‘CURLM* {aka void*}’ for argument ‘1’ to ‘CURLMcode curl_multi_setopt(CURLM*, CURLMoption, ...)’
         const auto code = curl_multi_setopt(this->curl, Opt, val);
ghost commented 7 years ago

I have fixed the issue. Please merge my pull request #112.

JosephP91 commented 7 years ago

Good. I'm going to close the issue. Thank you!