Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Doubt with timeout in HttpRequest
Doubt with timeout in HttpRequest [message #36119] Mon, 30 April 2012 10:05 Go to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

HttpRequest is subclass of TcpSocket. Both have a timeout member.

In HttpRequest it is set to 120000 and in TcpSocket it is set to Null.

The problem is that doing a HttpRequest::RequestTimeout(int ms) does not change TcpSocket::timeout, so for example HttpRequest::SendingData() will not work properly, as it calls TcpSocket::Put().

So it seems to set a timeout it is necessary to do this:
	HttpRequest http;
	http.RequestTimeout(mytime);
	http.Timeout(mytime);

Is it ok?


Best regards
Iñaki
Re: Doubt with timeout in HttpRequest [message #36130 is a reply to message #36119] Wed, 02 May 2012 08:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Mon, 30 April 2012 04:05

Hello Mirek

HttpRequest is subclass of TcpSocket. Both have a timeout member.

In HttpRequest it is set to 120000 and in TcpSocket it is set to Null.

The problem is that doing a HttpRequest::RequestTimeout(int ms) does not change TcpSocket::timeout, so for example HttpRequest::SendingData() will not work properly, as it calls TcpSocket::Put().

So it seems to set a timeout it is necessary to do this:
	HttpRequest http;
	http.RequestTimeout(mytime);
	http.Timeout(mytime);

Is it ok?



Actually, it is more complicated. First of all, it is true it now does not work as it should in case that TcpSocket has Null timeout.

Anyway, there is a difference between TcpSocket::Timeout and RequestTimeout. Timeout is for single socket operation, RequestTimeout is meant to be total timeout for the whole request.

So it will need a little bit more to resolve...

Mirek
Re: Doubt with timeout in HttpRequest [message #36144 is a reply to message #36130] Fri, 04 May 2012 07:59 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

Now timeout is 120 seconds and there are 3 retries.

With this default values if there is a problem in connexion the application will seem to be hanged.

Perhaps it would be better to have a smaller timeout.


Best regards
Iñaki
Re: Doubt with timeout in HttpRequest [message #36146 is a reply to message #36144] Fri, 04 May 2012 08:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Fri, 04 May 2012 01:59

Hello Mirek

Now timeout is 120 seconds and there are 3 retries.

With this default values if there is a problem in connexion the application will seem to be hanged.

Perhaps it would be better to have a smaller timeout.


Well, those values are for console/server apps. And in fact, I am strongly in favor of completely removing RequestTimeout - some requests can take much longer than 2 minutes (like uploading MBs files) and then RequestTimeout would become unpleasant surprise.

If you have app that can seem hanged, you should rather use 'WhenWait'/'WhenDo' callbacks to show. Look at reference/GuiWebCrawler...
Re: Doubt with timeout in HttpRequest [message #36236 is a reply to message #36146] Tue, 15 May 2012 20:45 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hopefully fixed.
Re: Doubt with timeout in HttpRequest [message #36381 is a reply to message #36236] Wed, 23 May 2012 15:03 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

Using WhenWait works:

if ((endTimeout < GetTickCount()) && http.GetContentLength() == 0)
	http.Abort();

However it is not very pretty as Timeout() could be supposed to be the place to set the timeout Smile.


Best regards
Iñaki
Re: Doubt with timeout in HttpRequest [message #36387 is a reply to message #36381] Wed, 23 May 2012 17:00 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Wed, 23 May 2012 09:03

Hello Mirek

Using WhenWait works:

if ((endTimeout < GetTickCount()) && http.GetContentLength() == 0)
	http.Abort();

However it is not very pretty as Timeout() could be supposed to be the place to set the timeout Smile.


Ah, but meanwhile I have implemented TcpSocket::GlobalTimeout and HttpRequest::RequestTimeout (which just calls GlobalTimeout).

It is also important to understand that Timeout sets timeout for single IO operation...

Mirek
Re: Doubt with timeout in HttpRequest [message #36389 is a reply to message #36387] Wed, 23 May 2012 18:27 Go to previous message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
... if there is a retry TcpSocket::GlobalTimeout is cleared to Null?

Best regards
Iñaki
Previous Topic: Problem with includes in Socket.cpp and Web.h
Next Topic: Set thread priority for linux
Goto Forum:
  


Current Time: Wed Apr 24 21:39:30 CEST 2024

Total time taken to generate the page: 0.02364 seconds