Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Mar : Re: idhttp calculation problem , need help!

www.cryer.info
Managed Newsgroup Archive

Re: idhttp calculation problem , need help!

Subject:Re: idhttp calculation problem , need help!
Posted by:"inqontrol" (te..@odium.to)
Date:Tue, 11 Mar 2008 08:42:33

Hello,
thanks for your interesting hints! I will test them this evening :)
Meanwhile I discovered that the problem does not occur while downloading so
I was wondering how it could calculate the correct values when downloading
but not when uploading. I noticed my antivirus checks HTTP-datastreams and
disabled this feature. It sounds crazy but this seems to be at least one
problem - without this check the tool works. Anyway, I will test your hint
and will use some ideas of it, for sure!

I will tell you what happens to this problem :]
Thanks again, bye.
--
Inqontrol,
Did you solve your problem?  If not here are some hints.
HTH, JohnH

This code uses a TTimer to trigger the checks, a button to start the
simulation and an TEdit to report the results.  It does not use
the GetTickCount.

Var idhttp: record fWorkPos, fMaxCount: Int64; end;
    fLastNow: double; fLastPos: Int64; fLastRate: double;
    SimRate: double;

procedure TForm1.Button5Click(Sender: TObject);
begin
  SimRate := 100e3{bytes/sec}*(24*60*60); {bytes/day}
  idhttp.fWorkPos := 0;
  idhttp.fMaxCount := 1000000; {1e6 bytes}
  fLastNow := Now;
  Timer1.Interval := 1000;
  Timer1.Enabled := true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var CurPos: Int64; CurNow: TDateTime;
    DeltaSecs, CurBytesPerSec, Progress, EstSecsToFinish: double;
begin
// Fake progress for testing.
   idhttp.fWorkPos := idhttp.fWorkPos
       + round(SimRate*(1+random-random)/(24*60*60));
// Do regular work.
  CurNow := Now; {current seconds time}
  DeltaSecs := (CurNow - fLastNow)*(24*60*60);
{ Note that a bump in time for a non-24-hour day can cause a problem.}
  CurPos := idhttp.fWorkPos; {downloaded bytes}
  If (CurPos >= idhttp.fMaxCount)
    then begin
      Timer1.Enabled := false;
      Edit5.Text := 'Finished';
      { ... other completion work ...}
      end
    else begin
      If (DeltaSecs > 0)
        then begin
          CurBytesPerSec :=
              (idhttp.fWorkPos - fLastPos)/DeltaSecs; {bytes/sec}
          Progress :=
              idhttp.fWorkPos/idhttp.fMaxCount; {fraction complete}
          EstSecsToFinish :=
              round(((idhttp.fMaxCount - fLastPos))/CurBytesPerSec);
          Edit5.Text :=
              Format('%.0F%% %F secs to go',
                     [100*Progress,EstSecsToFinish]);
          end
        else begin
          CurBytesPerSec := 0/0; {Not-A-Number}
          Edit5.Text := 'Error';
          end;
      fLastPos := CurPos;
      fLastNow := CurNow;
      fLastRate := CurBytesPerSec;
      end;
end;

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive