Re: Http.GetFile waiting forever

Giganews Newsgroups
Subject: Re: Http.GetFile waiting forever
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Thu, 27 Dec 2007

"Thomas Bergerot" <nospam@nospam.fr> wrote in message
news:132207CF7D42E340nospam@nospam.fr...

> I still have a problem using TIdHttp.GetFile.

There is no GetFile() method, so I'm assuming you mean Get() instead.

> Sometimes (especially when the connection is badly lost), the
> function keeps waiting forever.

If the connection is lost abnormally, that is very likely to happen.  The OS
doesn't know the connection is gone right away, so it can't report error
back to Indy until the socket times out internally (which can take hours on
Microsoft platforms).  Thus, Indy happily waits until the socket times out,
because the OS hasn't told it otherwise.

One thing you can do is set the ReadTimeout property to a small value.  It
is set to infinite by default.

> So i know this is a Winsock caveat, which has nothing to do with
> Indy, but the problem is i have a thread deadlocked with the GetFile,
> and it's a real problem for me.

Then move the download to its own thread so you don't deadlock the rest of
your code.  Otherwise, you only have two other options: 1) use the
ReadTimeout property, or 2) disconnect the socket from another thread after
a timeout that you control elapses.

> So what is the solution to avoid this kind of problem ? There MUST be
> a solution !!!! Don't tell me every programmer using Winsock is stuck
> in front of this without a solution.

Timeouts are the only way they have to deal with it.

Gambit

Replies

In response to

Http.GetFile waiting forever posted by Thomas Bergerot on Thu, 27 Dec 2007