Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing option CURLOPT_PIPEWAIT #111

Closed
ghost opened this issue Aug 30, 2017 · 4 comments
Closed

Missing option CURLOPT_PIPEWAIT #111

ghost opened this issue Aug 30, 2017 · 4 comments

Comments

@ghost
Copy link

ghost commented Aug 30, 2017

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
Copy link
Owner

@brano543 Done! Can you check it out please?

@ghost
Copy link
Author

ghost commented Aug 30, 2017

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
Copy link
Author

ghost commented Aug 30, 2017

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

@JosephP91
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant