• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2956
  • Last Modified:

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
0
SheratonGroup
Asked:
SheratonGroup
  • 2
1 Solution
 
2266180Commented:
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 ;)
0
 
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.
 

0
 
2266180Commented:
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 :)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now