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

How to check timeout expiration in a rest connection ?? #75

Closed
nabilasalmi opened this issue Jan 26, 2017 · 1 comment
Closed

How to check timeout expiration in a rest connection ?? #75

nabilasalmi opened this issue Jan 26, 2017 · 1 comment

Comments

@nabilasalmi
Copy link

nabilasalmi commented Jan 26, 2017

Hello,

I use a multithreaded application where a c++ thread sends some information in a google protocol buffer to a Java thread using RestClient. I want to initialize a timeout of the Rest connection so that to check expiration timeout in case the Java thread do'nt respond. How to do that ? This is the c++ main code.

                RestClient::init();
		RestClient::Connection* conn = new RestClient::Connection(applicationUrl);
		conn->SetTimeout(5);
		RestClient::HeaderFields headers;
		headers["Accept"] = "application/x-protobuf";
		conn->SetHeaders(headers);
		
                std::string url(applicationUrl);
	        string restRoot((VoiceLayer::getConfigParamValue("REST_ROOT")).c_str());
	        url.append(restRoot);
		string serialized;
	        stvproto::StartEvent event;
                event.set_info(info);
                event.SerializeToString(&serialized);
	
                RestClient::Response r=conn->post(url, serialized); 
                if (r.code==408)
                   cout <<"Request timeout!!" << endl;

This code results in a response code=-1 ! What's wrong in my code ?? please help me !
Thank you a lot !

Best regards,
Nabila

@mrtazz
Copy link
Owner

mrtazz commented Mar 15, 2017

The library is using 28 for the timeout code as this is what libcurl passes up and it's technically not a 408 timeout detected by the server but a client timeout. You can see an example here https://github.com/mrtazz/restclient-cpp/blob/master/test/test_connection.cc#L40

@mrtazz mrtazz closed this as completed Mar 15, 2017
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

2 participants