0

I have the following code to execute a PUT to a given address by means of the restc-cpp library:

auto rest_client = RestClient::Create();

auto done = rest_client->ProcessWithPromise([&mess,AI_IP,AI_port,Auth_token](Context& ctx){

auto reply = RequestBuilder(ctx).Put("http://ip_address:port/").Data(message).Execute();

});

try
{
    done.get();
}
catch(const exception& ex)
{
    ...
}
catch(const boost::exception& ex)
{
    ...
}
RESTC_CPP_IN_COROUTINE_CATCH_ALL
{
    ...
}

I would like to set a timeout for the execution of this PUT, but I do not find anything for this in the documentation of restc-cpp. Do you know how to do this? Thanks

New contributor
Lorenzo Eboli is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • 1
    Sidenote: I'd expect boost::exception to inherit from std::exception, and if it does, you will never catch a boost::exception if you place that after std::exception like you now do. That is, if exception is really std::exception. It's impossible to tell from your code snippet. Commented 2 hours ago

1 Answer 1

0

You can use Request::Properties to set timeouts on individual requests:

auto rest_client = RestClient::Create();

auto done = rest_client->ProcessWithPromise([&mess, AI_IP, AI_port, Auth_token](Context& ctx){
    
    restc_cpp::Request::Properties properties;
    properties.sendTimeoutMs = 30000;  // 30 seconds in milliseconds
    properties.recvTimeout = 30000;    // 30 seconds in milliseconds
    
    auto reply = RequestBuilder(ctx)
        .Put("http://ip_address:port/")
        .Data(message)
        .Properties(properties)
        .Execute();
});

try {
    done.get();
}
catch(const exception& ex) {
    // timeout exceptions will get caught here
}

See the Properties Struct in the headers here for all the configs: https://github.com/jgaa/restc-cpp/blob/master/include/restc-cpp/restc-cpp.h#L168

int sendTimeoutMs = (1000 * 12);  // For each IO operation
int replyTimeoutMs = (1000 * 21); // For the reply header
int recvTimeout = (1000 * 21);    // For each IO operation
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.