Link to home
Start Free TrialLog in
Avatar of SheratonGroup
SheratonGroup

asked on

IDHttp Post Timeout

I am working on a legacy app that uses D6 with Indy 8.

I am wondering if there is a way to time out a post that's taking too long.  I realize the latest version Indy supports this with the ReadTimeOut property.  But for legacy reasons I am stuck with Indy 8.

Thanks,

sse
Avatar of 2266180
2266180
Flag of United States of America image

you can "hack" it like  this:
- create one thread
- add each connection you want to timeout to the threads list (list:TList ) in a record type = record connection:TIdTcpConnection; timeout:TDateTime; end
- make sure access to the list is synchronized (use a cs:TCriticalSection from SyncObjs)
- before post-ing, add the connection to the above list and set the timeout to now
- after post-ing, remove it from the list
- the thread will check every second (or as often as you want) the entire list and when one of the timeout values exceed with 5 seconds (or whatever time you want) it will forcibly disconnect the connection.

one thing to keep in mind here: if the connection is slow or the post response is big, from this point of view the conneciton will timeout. so make sure you use the onwork event to update the timeout from the record so the conneciton will not be closed by the trhead when it is actually working.

it's a little complicated and I don't have time tonight to make you a demo, but if you cannot do it by yourself, just let me know and I'll try to do it tomorrow. or during the weekend ;)
Avatar of SheratonGroup
SheratonGroup

ASKER

Thanks for that, I would really prefer not to add any threads to the application.  

Though I did try something similar with the IDAntiFreeze component and a TTimer.  I didn't like this solution either.  

I also tried putting a handler in the onWork event hoping that I could keep track of elapsed time there, and disconnect based on how much time elapsed, unfortunately the event doesn't fire often enough to use.

Is there no other "out of the box" way to do this with Indy 8?

Btw, not that it matters too much, but this is for an ISAPI application so there is no GUI.
 

ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial