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.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 ;)
SheratonGroupAuthor Commented:
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.

since it's an isapi applicaiton, it does not have a form. antifreeze only works if you place it on the same component with the rest of indy (you can make it work at runtime as well, but you need pay extra attention). so I hope you were either doing it right at runtime, or you were using a datamodule and dropping the components on it.

>> Is there no other "out of the box" way to do this with Indy 8?
if you code your own http post, then yes, otehrwise, no.

>> I would really prefer not to add any threads to the application.
you can add one global thread. that way you don't compromise the server resources (I suspect this is the main reason behind not wanting threads)

basically, it's like this:
- indy is blocking
- indy 8 has no timeout for http operations (as far as I seen looking through the code)
- because of the above, you need to somehow disconnect the socket if it stalled too much
- tehre are 2 ways: antifreeze or another thread

that's it. and I can tell you that both methods work. there might be issues with antifreeze running in a dll mode in case of indy 8 (I think I successfully used indy9 or 10 in a dll with antifreeze), but in worse case scenario, you still have the thread method which will work.

I'll answer any other questions tomorrow. It's close to midnight here :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.