cpr icon indicating copy to clipboard operation
cpr copied to clipboard

Timeout for WriteCallback

Open christk1 opened this issue 3 years ago • 4 comments

  cpr::Response r = cpr::Get(cpr::Url{"https://streaming/api"},
                    cpr::Timeout{10000},
                    sslOpts,
                    cpr::WriteCallback([&](std::string response_line)
  {
     std::cout << "tick" << endl;
   }

This get will only wait 10 seconds and then it will stop executing. I want to put a timeout in case I don't receive a response in 10 secs using a WriteCallback. Is there any way to do this?

christk1 avatar Mar 09 '21 10:03 christk1

Hmm. I'm not aware of any solution for this. Any chance you know a way to do this is libcurl?

COM8 avatar Mar 15 '21 12:03 COM8

I think CURLOPT_CONNECTTIMEOUT can be used in this case but i am not sure how to do it using cpr::WriteCallback. i can check test if that is the correct way to go and open a PR for this.

ishansheth avatar Jul 10 '21 18:07 ishansheth

@ishansheth this would be great!

COM8 avatar Jul 16 '21 06:07 COM8

@COM8 I noticed that there is already the implementation of cpr::ConnectTimeout for this issue, so this issue could be closed as well.

leviliangtw avatar Jul 26 '22 15:07 leviliangtw