Board index » delphi » TIdFTP and timeout: worker thread code sample needed

TIdFTP and timeout: worker thread code sample needed

Hello,

I've done a small robot that does download files at fixed
time intervals, using TIdFTP. It works fine until it hangs
during a transfer. This happens after a few days (some
200 sessions after startup), and no substancial memory
leak is detected in the Win 2000 task manager.

I figured some timeout control was needed, but
found no easy way to do it with the TIdFTP
(this is my 1st Indy program...)

My program runs TIdFTP in the VCL thread,
using AntiFreeze, like the Delphi 6.02 FTPDemo
sample.

I have researched previous newsgroup postings,
but found no "recommended" solution to this
problem.

I know I could move the component to its
own worker thread, but haven't tried  this.
(would not solve the timeout problem anyway).

Some postings suggest that a timer could be used to check
the worker thread.  The thread would be terminated if
the FTP session timed out.  However, other postings
indicate that this leaves the application in unstable state
(so I did not test this either :). I'm also not sure if some
combination of TIdFTP Abort/Disconnect is needed
to end the session gracefully.

Questions:
1- What is the Indy experts solution to the FTP session
timeout problem ?

2- Can someone point a FTP worker thread code sample
that implements timeouts reliably ?

This kind of application is quite common, as the number
of times this problem appears in the news postings show.
An official code sample would help a lot.

Thanks in advance...

Omar

 

Re:TIdFTP and timeout: worker thread code sample needed


Quote
Omar Reis <o...@tecepe.com.br> wrote in message

news:3EA6880E.369A1C4F@tecepe.com.br...

Quote
> Hello,

> I've done a small robot that does download files at fixed
> time intervals, using TIdFTP. It works fine until it hangs
> during a transfer. This happens after a few days (some
> 200 sessions after startup), and no substancial memory
> leak is detected in the Win 2000 task manager.

> I figured some timeout control was needed, but
> found no easy way to do it with the TIdFTP
> (this is my 1st Indy program...)

There is a readTimeout property inherited from... something.
TidTCPClient?

Quote

> My program runs TIdFTP in the VCL thread,
> using AntiFreeze, like the Delphi 6.02 FTPDemo
> sample.

Many of the demo designs are actually poor.  Dump the antiFreeze &
use a seperate FTP thread.   If there is anything that might need to
wait or could possibly get stuck, it should not be in a main-thread
event handler.

Quote

> I have researched previous newsgroup postings,
> but found no "recommended" solution to this
> problem.

I haven't seen any{*word*154}s.  I've used TidFTP & left it running for
weeks.  The problem may have some OS dependency, (I was on W2k), or
only occur with large files or something...

Quote
> I know I could move the component to its
> own worker thread, but haven't tried  this.
> (would not solve the timeout problem anyway).

Well, it could.  If your FTP thread does not respond within a
reasonable time then you can assume it's got stuck & take steps to
kill it & start another.  If anything sticks in the main thread then
your app. is dead.  TidFTP etc. works fine in threads.

Quote
> Some postings suggest that a timer could be used to check
> the worker thread.  The thread would be terminated if
> the FTP session timed out.

At least you have the option of trying to unblock the thread.  Often,
disconnecting or closing the socket it is stuck on will cause the
stuck call to except in the thread, allowing you to clean
up/retry/exit.  TidFTP has an abort method which, I believe, does
something like this.

Quote
> Questions:
> 1- What is the Indy experts solution to the FTP session
> timeout problem ?

Well, my solution is to use the readTimeout property & run the FTP in
a thread.  If you still get problems, time out the thread with a
'classic' timer & try the TidFTP abort method from your timer event
handler.  I have never used any socket component in the main
hread  - it's just asking for trouble & strife.

Quote
> 2- Can someone point a FTP worker thread code sample
> that implements timeouts reliably ?

Just try the readTimeout - it works fine in a thread - raises an
exception.

Quote
> This kind of application is quite common, as the number
> of times this problem appears in the news postings show.
> An official code sample would help a lot.

It would help if the Demos were threaded.  The chat client, for
example, uses a main-thread loop with a short timeout.  Not good.

I am not in a position to issue 'official' code samples, but TidFTP
can be made to work reliably under the circumstances where I used it.
I'll see if I can find some code or a simple demo that times out.

Rgds,
Martin

Other Threads