🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2836

Problem with HTTP download locking up.

#2836
From: Tom
Date: Tue, 24 Jan 2006 00:18
239 lines
7961 bytes
I'm having a problem with a customers computer locking up as soon as a 
request
to download a file via http is made. To my knowledge this is the only 
customer
with this problem. He's using XP SP2, I'm still waiting for a response to 
make
sure a Proxy server isn't needed, but even then I would think it would 
simply
throw an exception.

I've tried both TNMHttp and TIdHTTP and it seems to happen at the same
point with both controls..

Because TNMHttp controsl are supposed to be buggy what is below is using
the TId component. I'm using Indy 9.0.50.

The first call I make is to a web page and return the result as a string.
Then I download a small file (22 bytes) this seems to work fine. The next
file that gets downloaded is 24MB and as soon as the Get is called the 
program
freezes solid. I do have the AntiFreeze component on the form, and on my 
machine
that doesn't lock up it functions just fine with being able to move the 
window, click
buttons etc without it appearing to be frozen. On his, it's locked up solid, 
can't
move the windows, click the cancel button, nothing.

I have the OnWork event setup to calculate the current progress of the 
transfer
using the Http1->Response->ContentStream->Position and the ContentLength
variables. With a Application->ProcessMessages() thrown in to update the 
display.

Initially I had it setup in a thread for the downloading with synchronize
calls for updating the display, but rather than lockup, the thread was just 
dying without
any errors being thrown.

I'm including the code below for downloading:

<excerpt from function of the code that is not locking up>

   if(!Download("http://www.companyname.com/SmallFile.nfo", InstallDir + 
"\\SmallFile.nfo"))
   {
     Msg = "Unable to download Information File.";
     Write_Debug(Msg);
     UpdateStatus();  // Adds a line to a TMemo and 
Application->ProcessMessages();
     DownloadFailed = true;
     AbortUpdate = true;
     return;
   }

<end excerpt>


<excerpt from function of the code that IS locking up>

Msg.sprintf("Downloading Update number %d.", iCtr);
Write_Debug(Msg);
UpdateStatus(Msg);

 if(!FileExists(FileName5) && !Download("http://www.companyname.com/" + 
FileName, InstallDir + "\\" + FileName))
{
   if(!AbortUpdate)
   {
      Msg.sprintf("Unable to download update number %d.", iCtr);
      Write_Debug(Msg);
      UpdateStatus();
   }
  DownloadFailed = true;
  AbortUpdate = true;
  return;
}

<end excerpt>

<Code from the Download Function>

bool Download(AnsiString const FileName, AnsiString const FullPath)
{
   Retry = 10;
   IsDownloading = true;
   DLResult = false;

   while(IsDownloading && !DLResult && Retry != 0)
   {
     frmUpdate->StartTime = Now();
     try
     {
       TMemoryStream *ms = new TMemoryStream;
       frmUpdate->Http1->Get(FileName, ms);
       if(!AbortUpdate)
       {
         if(FileExists(FullPath))
           DeleteFile(FullPath);
         ms->SaveToFile(FullPath);
         DLResult = true;
       }
       delete ms;
       IsDownloading = false;
     }
     catch(const EIdSocketError &e)
     {
       AnsiString Message = "EIdSocketError: "  + AnsiString(e.LastError) + 
" - " + e.Message;
       Write_Debug(Message);
       --Retry;
     }
     catch(const EIdHTTPProtocolException &e)
     {
       AnsiString Message = "EIdHTTPProtocolException: " + 
AnsiString(e.ReplyErrorCode) + " - " + e.ErrorMessage;
       Write_Debug(Message);
       --Retry;
     }
     catch(const EIdException &e)
     {
       AnsiString Message = "EIdException: " + e.Message;
       Write_Debug(Message);
       --Retry;
     }
     catch(const Exception &e)
     {
       AnsiString Message = "Exception: " + e.ClassName() + " - " + 
e.Message;
       Write_Debug(Message);
       --Retry;
     }
   }

   return DLResult;
}

<Code from OnWork Event>

void __fastcall TfrmUpdate::Http1Work(TObject *Sender,
      TWorkMode AWorkMode, const int AWorkCount)
{
 if(IsDownloading)
 {
  if(AbortUpdate)
  {
    Http1->Disconnect();
    DLResult = false;
    Retry = 0;
    Msg = "Download was aborted by the user.";
    UpdateStatus();
    Write_Debug(Msg);
    return;
  }
  if(Http1->Response->ContentLength >= 1048576)
  {
    lblFileSize->Caption = lblFileSize->Caption.FormatFloat("0.00", 
float(Http1->Response->ContentLength) / 1048576);
    Label5->Caption = "MB";
  }
  else if(Http1->Response->ContentLength >= 1024)
  {
    lblFileSize->Caption = lblFileSize->Caption.FormatFloat("0.00", 
float(Http1->Response->ContentLength) / 1024);
    Label5->Caption = "KB";
  }
  else
  {
    lblFileSize->Caption = Http1->Response->ContentLength;
    Label5->Caption = "Bytes";
  }

  if(Http1->Response->ContentStream->Position >= 1048576)
  {
    lblBytesReceived->Caption = 
lblBytesReceived->Caption.FormatFloat("0.00", 
float(Http1->Response->ContentStream->Position) / 1048576);
    Label6->Caption = "MB";
  }
  else if(Http1->Response->ContentStream->Position >= 1024)
  {
    lblBytesReceived->Caption = 
lblBytesReceived->Caption.FormatFloat("0.00", 
float(Http1->Response->ContentStream->Position) / 1024);
    Label6->Caption = "KB";
  }
  else
  {
    lblBytesReceived->Caption = Http1->Response->ContentStream->Position;
    Label6->Caption = "Bytes";
  }
  TDateTime CurrentTime = Now();
  double NumSecs = SecondSpan(CurrentTime, frmUpdate->StartTime);
  double BytesLeft = Http1->Response->ContentLength - 
Http1->Response->ContentStream->Position;
  float TimeLeft;
  if(Http1->Response->ContentStream->Position != 0)
    TimeLeft = BytesLeft / (Http1->Response->ContentStream->Position / 
NumSecs);
  else
    TimeLeft = BytesLeft / (1 / NumSecs);

  if(TimeLeft >= 3600)
  {
    int Hours = (int)(TimeLeft / 3600);
    int Minutes = (int)((TimeLeft - (Hours * 3600)) / 60);
    int Seconds = (int)((TimeLeft - (Hours * 3600) - (Minutes * 60)));
    lblTimeRemaining->Caption.sprintf("%d hrs %d mins %d secs", Hours, 
Minutes, Seconds);
  }
  else if(TimeLeft >= 60)
  {
    int Minutes = (int)(TimeLeft/ 60);
    int Seconds = (int)((TimeLeft - (Minutes * 60)));
    lblTimeRemaining->Caption.sprintf("%d mins %d secs", Minutes, Seconds);
  }
  else
     frmUpdate->lblTimeRemaining->Caption.sprintf("%d secs", (int)TimeLeft);

  Application->ProcessMessages();
 }
}

Here is the contents of the Log file that Write Debug writes to.

2006-01-23 7:54:27 AM : Downloading Update Infomation File
2006-01-23 7:54:27 AM : Information file downloaded sucessfully.
2006-01-23 7:54:27 AM : Old Information file opened. Old AM Version: 77. Old 
Updater Version: 6. Last Update Number: 5.
2006-01-23 7:54:27 AM : New Information file opened. New AM Version: 80. New 
Updater Version: 7. New Update Number: 8.
2006-01-23 7:54:27 AM : New version of Updater.exe found, downloading it!
2006-01-23 7:54:30 AM : Downloading Update number 6.

If anymore information needs to be provided please let me know.

Thanks,

Tom
Technical Details
Message-ID: <43d571a6$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,1a95ad1eb7ec8c80,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Tom" <thomasf1021@hotmail.com>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Problem with HTTP download locking up.
Date: Mon, 23 Jan 2006 18:18:31 -0600
Lines: 243
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 68.1.78.156
Message-ID: <43d571a6$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1138061734 68.1.78.156 (23 Jan 2006 16:15:34 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail